You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a project contains multiple <OpenApiReference> entries, the ApiException class is only generated for the first entry. While this is a nice default, since v14 it has become impossible to generate exception classes for all entries (they live in separate namespaces).
The problematic line is in NSwag.ApiDescription.Client.targets:
<CommandCondition="!%(FirstForGenerator) OR (%(NSwagGenerateExceptionClasses) != '' AND !%(NSwagGenerateExceptionClasses))">%(Command) /GenerateExceptionClasses:false</Command>
which always adds /GenerateExceptionClasses:false for the non-first entry, ignoring the configured value of NSwagGenerateExceptionClasses in <OpenApiReference>.
When trying to work around it by adding the argument explicitly using:
<Options>/GenerateExceptionClasses:true</Options>
the build fails because the /GenerateExceptionClasses parameter is now specified multiple times (which makes NConsole fail).
GenerateExceptionClassesDemo.zip contains a minimal repro. It fails to build the generated QueryStringsClient file (second entry in csproj), because it doesn't declare the ApiException class while referencing it.
To fix this, the problematic line should be replaced with:
<CommandCondition="!%(FirstForGenerator) AND ('%(NSwagGenerateExceptionClasses)' == '')">%(Command) /generateExceptionClasses:false</Command>
<CommandCondition="'%(NSwagGenerateExceptionClasses)' != ''">%(Command) /generateExceptionClasses:%(NSwagGenerateExceptionClasses)</Command>
The fix only adds /generateExceptionClasses:false for non-first entries that aren't configured. In all other cases, it takes the configured value, similar to all the other NSwag* properties. When /generateExceptionClasses is omitted, it defaults to true.
The same fix should be applied for NSwagGenerateResponseClasses, which works similarly.
Additionally, generation of the JsonInheritanceConverter, JsonInheritanceConverterAttribute, and JsonInheritanceAttribute classes could benefit from the same fix, but there's no NSwag* property to control whether they are generated.
The text was updated successfully, but these errors were encountered:
When a project contains multiple
<OpenApiReference>
entries, theApiException
class is only generated for the first entry. While this is a nice default, since v14 it has become impossible to generate exception classes for all entries (they live in separate namespaces).The problematic line is in
NSwag.ApiDescription.Client.targets
:which always adds
/GenerateExceptionClasses:false
for the non-first entry, ignoring the configured value ofNSwagGenerateExceptionClasses
in<OpenApiReference>
.When trying to work around it by adding the argument explicitly using:
the build fails because the
/GenerateExceptionClasses
parameter is now specified multiple times (which makes NConsole fail).GenerateExceptionClassesDemo.zip contains a minimal repro. It fails to build the generated
QueryStringsClient
file (second entry in csproj), because it doesn't declare theApiException
class while referencing it.To fix this, the problematic line should be replaced with:
The fix only adds
/generateExceptionClasses:false
for non-first entries that aren't configured. In all other cases, it takes the configured value, similar to all the otherNSwag*
properties. When/generateExceptionClasses
is omitted, it defaults totrue
.The same fix should be applied for
NSwagGenerateResponseClasses
, which works similarly.Additionally, generation of the
JsonInheritanceConverter
,JsonInheritanceConverterAttribute
, andJsonInheritanceAttribute
classes could benefit from the same fix, but there's noNSwag*
property to control whether they are generated.The text was updated successfully, but these errors were encountered: