How to change EmitDefaultValue in automatically created Nuget

22 Views Asked by At

I'm using a C# application with microservices and using swagger/openAPI and swashbuckle to automatically generate nugets from my code. I have some int properties which are getting EmitDefaultValue=false in the generated nuget, which causes 0 value to not be serialized. I tried everything I could think of to change this but couldn't.

Example property:

[Range(-1, int.MaxValue)]
[DefaultValue(-1)]
[DataMember(EmitDefaultValue = true)]
public int Some Number { get; set; } = -1;

As you can see my default is -1, meaning 0 holds significance, so I don't want 0 ignored.

These are my swashbuckle packages:

<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
<PackageReference Include="Swashbuckle.AspNetCore.Newtonsoft" Version="6.1.4" /> 

Found this on github about others with the same issue: https://github.com/OpenAPITools/openapi-generator/issues/3274

issue seems to have been resolved but I couldn't understand how to implement it. Any help would be appreciated, I don't want to add a schema filter to all properties since this is specific only for very few properties and the others should continue ignoring 0.

0

There are 0 best solutions below