Document writer outputs invalid JSON when the current culture uses comma as decimal symbol
Microsoft.OpenAPI.dll v 1.2.3
To reproduce the issue you will need to change regional settings to a culture that uses comma (",") as decimal symbol, i.e. English (Belgium). When outputting JSON the decimal symbol should be dot (".").
I'm attaching a sample specification (input.txt) that has single definition with a few floating properties. If you run the following unit test it will produce the invalid JSON (output.txt):
[TestMethod]
public void Test()
{
var reader = new OpenApiStringReader();
var doc = reader.Read(System.IO.File.ReadAllText("input.txt"), out OpenApiDiagnostic d);
using (var stringWriter = new System.IO.StringWriter(CultureInfo.CurrentCulture))
{
OpenApiDocumentWriter.Write(textWriter: stringWriter,
document: doc,
version: OpenApiSpecVersion.OpenApi3_0,
format: OpenApiFormat.Json);
var json = stringWriter.ToString();
// This will throw an error
JObject jobject = JObject.Parse(json);
}
}
This isssue was addressed in 1.2 and confirmed by the original person who reported it https://github.com/microsoft/OpenAPI.NET/issues/478 Do you see a difference between your scenario and the original one that was reported. /cc @MaggieKimani1 @CarolKigoonya
Hi Darrel,
I reported #478. :) The original scenario was about sample values and it was indeed fixed. This one is about outputting decimal properties min / max values when the current culture's decimal delimiter is comma (,) which is reserved character in JSON.
@korygin If you create your own writer, then you are responsible for providing the appropriate culture setting. When we create the writer, we use the FormatingStreamWriter with the culture invariant setting https://github.com/microsoft/OpenAPI.NET/blob/5189855c9c9abb159d3e6140849cecfb7e5ea0e9/src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs#L87
When you create the StringWriter, you explicitly pass the CurrentCulture. Why would you expect it to write using the invariant culture?