NSwag
NSwag copied to clipboard
Unable to generate contract output via CLI using .nswag file
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
You need to specify an output path (on the bottom in the UI)
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:
//----------------------
//
using Models;
namespace { #pragma warning disable // Disable all warnings }
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
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.