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

Not able to handle the GenerateExceptionClasses parameter being specified twice in the command line #4698

Open pnguyen2021 opened 8 months ago

pnguyen2021 commented 8 months ago

When there are multiple client classes being generated, the "/GenerateExceptionClasses:false" parameter is somehow added to the command-line even when it is already explicitly specified. v14 is not able to parse the same parameter twice.

<ItemGroup>
    <OpenApiReference Include="OpenAPIs\xxx.yaml" Options="/GenerateClientInterfaces:true /AdditionalNamespaceUsages:xxx /DateType:System.DateTime /DateTimeType:System.DateTime /GenerateExceptionClasses:false /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false" CodeGenerator="NSwagCSharp" Namespace="xxx" ClassName="xxx">
      <OutputPath>xxx.cs</OutputPath>
      <SourceUri>http://xxx.yaml</SourceUri>
    </OpenApiReference>
    <OpenApiReference Include="OpenAPIs\yyy.yaml" CodeGenerator="NSwagCSharp" Namespace="yyy" ClassName="yyy">
        <SourceUri>http://yyy.yaml</SourceUri>
        <ClassName>yyy</ClassName>
        <OutputPath>yyy.cs</OutputPath>
        <Options>/GenerateClientInterfaces:true /AdditionalNamespaceUsages:yyy /DateTimeType:DateTime /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false /GenerateExceptionClasses:false </Options>
    </OpenApiReference>
</ItemGroup>

GenerateNSwagCSharp: dotnet --roll-forward-on-no-candidate-fx 2 "C:\zzz\nswag.msbuild\14.0.0\buildTransitive../tools/Net60//dotnet-nswag.dll" openapi2csclient /className:yyy /namespace:yyy /GenerateExceptionClasses:false /input:"D:\yyy.yaml" /output:"yyy.cs" /GenerateClientInterfaces:true /AdditionalNamespaceUsages:yyy /DateType:DateTime /DateTimeType:DateTime /GenerateExceptionClasses:false /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false NSwag command line tool for .NET Core Net60, toolchain v14.0.0.0 (NJsonSchema v11.0.0.0 (Newtonsoft.Json v13.0.0.0)) Visit http://nswag.org/ for more information. NSwag bin directory: C:\zzz\nswag.msbuild\14.0.0\tools\Net60 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

Previous version worked fine:

GenerateNSwagCSharp: dotnet --roll-forward-on-no-candidate-fx 2 "C:\zzz\nswag.msbuild\13.18.2\build../tools/Net60//dotnet-nswag.dll" openapi2csclient /className:yyy /namespace:yyy /GenerateExceptionClasses:false /input:"D:\yyy.yaml" /output:"obj\yyy.cs" /GenerateClientInterfaces:true /AdditionalNamespaceUsages:yyy /useDateTimeOffset:false /GenerateExceptionClasses:false /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false NSwag command line tool for .NET Core Net60, toolchain v13.18.2.0 (NJsonSchema v10.8.0.0 (Newtonsoft.Json v13.0.0.0)) Visit http://nswag.org/ for more information. NSwag bin directory: C:\zzz\nswag.msbuild\13.18.2\tools\Net60 Code has been successfully written to file.

pnguyen2021 commented 8 months ago

There is a work-around the issue: remove the "/GenerateExceptionClasses:false" parameter from the 2nd+ OpenApiReference node(s):

<ItemGroup>
    <OpenApiReference Include="OpenAPIs\xxx.yaml" Options="/GenerateClientInterfaces:true /AdditionalNamespaceUsages:xxx /DateType:System.DateTime /DateTimeType:System.DateTime /GenerateExceptionClasses:false /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false" CodeGenerator="NSwagCSharp" Namespace="xxx" ClassName="xxx">
      <OutputPath>xxx.cs</OutputPath>
      <SourceUri>http://xxx.yaml</SourceUri>
    </OpenApiReference>
    <OpenApiReference Include="OpenAPIs\yyy.yaml" CodeGenerator="NSwagCSharp" Namespace="yyy" ClassName="yyy">
        <SourceUri>http://yyy.yaml</SourceUri>
        <ClassName>yyy</ClassName>
        <OutputPath>yyy.cs</OutputPath>
        <Options>/GenerateClientInterfaces:true /AdditionalNamespaceUsages:yyy /DateTimeType:DateTime /GenerateDataAnnotations:false /RequiredPropertiesMustBeDefined:false </Options>
    </OpenApiReference>
</ItemGroup>
joelwilhelms-FMFI commented 5 months ago

Can confirm that I had the exact same issue and the workaround fixed it for me too