RicoSuter / NSwag

The Swagger/OpenAPI toolchain for .NET, ASP.NET Core and TypeScript.
http://NSwag.org
MIT License
6.67k stars 1.23k forks source link

Unable to generate contract output via CLI using .nswag file #1190

Open jjohs opened 6 years ago

jjohs commented 6 years ago

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

RicoSuter commented 6 years ago

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

jjohs commented 6 years ago

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

}

bcbeatty commented 6 years ago

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

didaskein commented 4 months ago

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.