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

csproj OpenApiReference won't generate records. #4750

Open peterdrier opened 6 months ago

peterdrier commented 6 months ago

When I manually configure this through NSwagStudio, it will generate proper records, but when trying to do it via the following in my csproj file, it's still giving me "public partial class User" for a data class for example instead of ".,.. record User". Am I missing something?

Note: I have 3 different API's I'm including by these references. I've tried both having different settings on them, and them all having the same settings, neither seemed to make a difference. I do know these parameters are somewhat working though as the GenerateExceptionClasses = false, without that this will not let me have 3x api's in parallel.

<OpenApiReference Include="Foo.yaml">
    <Namespace>Services.Foo</Namespace>
    <ClassName>FooClient</ClassName>
    <NSwagGenerateExceptionClasses>false</NSwagGenerateExceptionClasses>
    <NSwagOperationGenerationMode>SingleClientFromOperationId</NSwagOperationGenerationMode>
    <NSwagGenerateOptionalPropertiesAsNullable>true</NSwagGenerateOptionalPropertiesAsNullable>
    <NSwagGenerateNullableReferenceTypes>true</NSwagGenerateNullableReferenceTypes>
    <NSwagGenerateNativeRecords>true</NSwagGenerateNativeRecords>
    <NSwagClassStyle>Record</NSwagClassStyle>
    <NSwagJsonLibrary>SystemTextJson</NSwagJsonLibrary>
    <NSwagAdditionalNamespaceUsages>OpenApi</NSwagAdditionalNamespaceUsages>
</OpenApiReference>

<PackageReference Include="NSwag.ApiDescription.Client" Version="14.0.2">

I have attempted to trace my way through the NSwag source tree, but get a bit lost tbh. It's a little odd to me needing two flags (GenerateNativeRecords and ClassStyle) to both be set to true/Record, but it seems like it should work.

I'm happy to help contribute to improve this experience.. Just need a bit of direction to get started.