NSwag icon indicating copy to clipboard operation
NSwag copied to clipboard

Unable to generate contract output via CLI using .nswag file

Open jjohs opened this issue 7 years ago • 4 comments

Is it possible to generate contract output files targeting .NET using the CLI, and referencing a .nswag file?

Loading the .nswag file in NSwagStudio produces contract file output when Generate Files button is clicked.

Attempting to run the following via the CLI does not generate any file output:

dotnet "C:\Program Files (x86)\Rico Suter\NSwagStudio\NetCore20\dotnet-nswag.dll" run "C:\temp\nswag\test.nswag"

Thanks

jjohs avatar Feb 13 '18 16:02 jjohs

You need to specify an output path (on the bottom in the UI)

RicoSuter avatar Feb 13 '18 23:02 RicoSuter

The contract file (DTO classes only, no client interface) is generated as expected when file generation is executed through Studio. The contractsOutputFilePath, typesToSwagger classNames, and assemblyPaths properties are set in the .nswag file. When executing the following command using the CLI, no contract file is generated:

dotnet "C:\Program Files (x86)\Rico Suter\NSwagStudio\NetCore20\dotnet-nswag.dll" run "C:\temp\nswag\test.nswag"

When output path is specified, a file is generated (Studio and CLI), but the contents are empty: //---------------------- // // Generated using the NSwag toolchain v11.14.1.0 (NJsonSchema v9.10.24.0 (Newtonsoft.Json v9.0.0.0)) (http://NSwag.org) // //----------------------

using Models;

namespace { #pragma warning disable // Disable all warnings }

jjohs avatar Feb 14 '18 03:02 jjohs

Same thing happens when you click the "Generate Outputs" button with C# Client, but clicking "Generate Files" it does generate the C# classes as a file, but not in the preview window

bcbeatty avatar Apr 19 '18 13:04 bcbeatty

I have the same issue, i think i found the solution :

NSWAG file BEFORE :

 "documentGenerator": {
    "fromDocument": {
      "json": "{\r\n  \"openapi\": \"3.0.1\",\r\n  \"info\": {\r\n    \"title\":  ....... ",
      "url": "https://localhost:44324/swagger/v1/swagger.json",
      "output": null,
      "newLineBehavior": "Auto"
    }
  },

NSWAG file AFTER :

 "documentGenerator": {
    "fromDocument": {
      "url": "https://localhost:44324/swagger/v1/swagger.json",
      "output": null,
      "newLineBehavior": "Auto"
    }
  },

I need to remove the json field store inside the nswag file. This field is set when you use the graphical interface of NSwag.

didaskein avatar Apr 20 '24 07:04 didaskein