You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenApiSchemaJsonConverter writes invalid JSON under cultures with a decimal comma #3185
OpenApiSchemaJsonConverter.Write serializes the schema through a StreamWriter. That writer's FormatProvider is the current culture. The result is then passed to Utf8JsonWriter.WriteRawValue(..., skipInputValidation: true).
Numbers in the schema are therefore written with the current culture, and the invalid output is not caught:
under de-DE, a default of 1.5 is written as "default": 1,5;
under fi-FI, -5 is written with U+2212 MINUS SIGN.
Both make the serialized JSON invalid.
OpenApiDocument.GetHashCodeAsync uses the same kind of writer, so a document's hash depends on the machine's culture.
To reproduce
CultureInfo.CurrentCulture=newCultureInfo("de-DE");varschema=newOpenApiSchema{Type=JsonSchemaType.Number,Default=JsonValue.Create(1.5)};varjson=JsonSerializer.Serialize(schema,newJsonSerializerOptions{Converters={newOpenApiSchemaJsonConverter()}});JsonDocument.Parse(json);// JsonReaderException: '5' is an invalid start of a property name
Expected behavior
The output is the same as under the invariant culture: "default": 1.5. This is what the SerializeAsync extensions already produce, because they use FormattingStreamWriter with CultureInfo.InvariantCulture.
I have a fix with tests ready and will open a PR that links this issue.
This issue was written with AI assistance (Claude Code); I reproduced the bug and reviewed the text.
Activity