I'm using Swashbuckle.AspNetCore in my .NET 6 application to create a swagger API. In my .NET code I have a model with a property:
/// <summary>Gets or sets the power of the converter.</summary>
/// <example>4.40</example>
[Required]
public decimal Power { get; set; }
I'm using the example tag to generate an example object users can send. Which becomes this in my swagger file:
"power": {
"type": "number",
"description": "Gets or sets the power of the converter.",
"format": "double",
"example": 4,4
}
The 4,4 is invalid JSON syntax and should be displayed as 4.4. Is there any way I can change this?
Apparently this is an issue related to culture. Very weird because a ",' should never be in a json like that.
A way to solve this is to pass in DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 when using swashbuckle.aspnetcore.cli:
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="dotnet tool restore" />
<Exec EnvironmentVariables="DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1" Command="dotnet swagger tofile --output swagger.json $(OutputPath)\$(AssemblyName).dll v1" />
</Target>