Skip to content

Document writer outputs invalid JSON when the current culture uses comma as decimal symbol #657

Closed
@korygin

Description

@korygin

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);
    }
}

input.txt
output.txt

Metadata

Metadata

Assignees

Labels

Needs: Attention 👋priority:p1High priority but not blocking. Causes major but not critical loss of functionality SLA <=7days

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions