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

Customise DTO class names when using NSwag.MSBuild (or nswag.exe openapi2csclient) #3523

Open flcdrg opened 3 years ago

flcdrg commented 3 years ago

I'm using NSwag.MSBuild (via NSwag.ApiDescription.Client).

  <ItemGroup>
    <OpenApiReference Include="swagger.yaml" Namespace="Client" ClassName="MyClient">
      <CodeGenerator>NSwagCSharp</CodeGenerator>
      <Options>/JsonLibrary:SystemTextJson /GenerateContractsOutput:true /ContractsOutput:Contracts\Downstream.cs /ContractsNamespace:Contracts.Downstream /GenerateNullableReferenceTypes:true /GenerateOptionalPropertiesAsNullable:true /GenerateImmutableArrayProperties:true /GenerateImmutableDictionaryProperties:true /generateOptionalParameters:true /useBaseUrl:false /GenerateClientInterfaces:true /ArrayType:System.Collections.Generic.IList /ArrayInstanceType:System.Collections.Generic.List /ParameterArrayType:System.Collections.Generic.IList /ChecksumCacheEnabled:true</Options>
    </OpenApiReference>
  </ItemGroup>

I've tried using the various parameters listed for the openapi2csclient command that sound like they should allow customising the class names for the DTO classes (eg. /TypeNameGenerator, /PropertyNameGeneratorType and even /TemplateDirectory), but none of them seem to work in this scenario and seem to be ignored (I also tried running nswag.exe manually from the command line adding these extra parameters.

Looking at the source code, it doesn't seem like these are even used in this code path.

Is there a way of doing this?

GillesNorce commented 7 months ago

I've got a similar question about passing a CustomTypeNameGenerator through nswag.exe posted in the discussion forum.