RicoSuter / NSwag

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

Command line argument parsing seems to be broken with nswag npm package 14.0.0 + #4706

Closed benrhere closed 8 months ago

benrhere commented 8 months ago

Hi,

I think the jump from 13.20 to 14.0.1 of the npm module may have changed behavior for command line parsing. When I npm install witih nswag 13.20.0, and then I run:

dotnet "D:\Path\To\Project\node_modules\nswag\bin\binaries\Net70\dotnet-nswag.dll" run /variables:SwaggerFile=swagger-public.json,DtoProject=Core

I get:

NSwag command line tool for .NET Core Net70, toolchain v13.20.0.0 (NJsonSchema v10.9.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: D:\Path\To\Project\node_modules\nswag\bin\binaries\Net70

Executing file 'nswag.json' with variables 'SwaggerFile=swagger-public.json,DtoProject=Core'...

It has recognized the variables passed in. Next, I'll update my package.json to reference nswag 14.0.1, npm install, and rerun while replacing Net70 witih Net80 below. I now get:

dotnet "D:\Path\To\Project\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run /variables:SwaggerFile=swagger-public.json,DtoProject=Core
NSwag command line tool for .NET Core Net80, toolchain v14.0.1.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0))
Visit http://NSwag.org for more information.
NSwag bin directory: D:\Path\To\Project\node_modules\nswag\bin\binaries\Net80
NConsole.UnusedArgumentException: Unrecognised arguments are present: []
   at NConsole.CommandLineProcessor.ProcessSingleAsync(String[] args, Object input)
   at NConsole.CommandLineProcessor.ProcessAsync(String[] args, Object input)
   at NSwag.Commands.NSwagCommandProcessor.ProcessAsync(String[] args) in /_/src/NSwag.Commands/NSwagCommandProcessor.cs:line 62

The npm module version is the only thing I'm changing. I was also toying with nuget packages, but I was able to isolate the problem to only the above npm change. If it's relevant, the above repro is while my ASP.NET Core project is on 14.0.1 for NSwag.AspNetCore, NSwag.CodeGeneration.TypeScript, NSwag.Core, and NSwag.MSBuild.

If I remove all variables:

dotnet "D:\Path\To\Project\node_modules\nswag\bin\binaries\Net80\dotnet-nswag.dll" run

I can run successfully even on the newest npm package. It's also respecting the "defaultVariables" even in this case.

Thanks for your guidance!

(Edited to show repro with 14.0.1 and NET80 for clarity - original post showed repro with 14.0.0 and NET70 but same problem repro'd)

krzyhan commented 8 months ago

dotnet "D:\Path\To\Project\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run /runtime:Net80 /variables:SwaggerFile=swagger-public.json,DtoProject=Core should work or eq. dotnet "D:\Path\To\Project\node_modules\nswag\bin/binaries/Net80/dotnet-nswag.dll" run nswagConfigurationFile.json /variables:SwaggerFile=swagger-public.json,DtoProject=Core

benrhere commented 8 months ago

@krzyhan thank you! Adding the runtime flag solved my issue.