Repository navigation
fix: write schema JSON and document hashes with the invariant culture - #3186
Merged
Vincent Biret (baywet) merged 1 commit intoNov 23, 2026
Conversation
OpenApiSchemaJsonConverter.Write wrote the schema through a StreamWriter, whose format provider is the current culture, and passed the result to Utf8JsonWriter.WriteRawValue without validation. Under de-DE a default of 1.5 came out as "1,5" and under fi-FI -5 as "−5" (U+2212), both invalid JSON. OpenApiDocument.GetHashCodeAsync had the same writer, so a document's hash depended on the machine's culture. Both now use FormattingStreamWriter with CultureInfo.InvariantCulture, like the SerializeAsync extensions already do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues blocking the culture-independent schema serialization and document-hashing changes.
No open issues 🎉
What changed in this PR
Fixes #3185 by making schema JSON serialization and document hashing culture-independent, aligning both paths with the library’s existing invariant-culture serialization.
Changes:
- Uses
FormattingStreamWriterwith invariant culture for schema serialization and both document-hashing branches. - Removes the converter’s redundant UTF-8 encoding field while retaining BOM-free output.
- Adds regression tests for numeric JSON under
de-DEandfi-FI, and hash consistency across cultures.
| File | Description |
|---|---|
test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs |
Tests hash equality under invariant and German cultures. |
test/Microsoft.OpenApi.Tests/Converters/OpenApiSchemaJsonConverterTests.cs |
Tests valid numeric JSON under German and Finnish cultures. |
src/Microsoft.OpenApi/Models/OpenApiDocument.cs |
Uses invariant-culture formatting in both hashing branches. |
src/Microsoft.OpenApi/Converters/OpenApiSchemaJsonConverter.cs |
Uses invariant-culture formatting and removes the redundant encoding field. |
Review effort: Balanced
Contributor
Author
|
@microsoft-github-policy-service agree |
Vincent Biret (baywet)
approved these changes
Nov 23, 2026
Vincent Biret (baywet)
added a commit
that referenced
this pull request
Nov 23, 2026
…#3186) (#3188) OpenApiSchemaJsonConverter.Write wrote the schema through a StreamWriter, whose format provider is the current culture, and passed the result to Utf8JsonWriter.WriteRawValue without validation. Under de-DE a default of 1.5 came out as "1,5" and under fi-FI -5 as "−5" (U+2212), both invalid JSON. OpenApiDocument.GetHashCodeAsync had the same writer, so a document's hash depended on the machine's culture. Both now use FormattingStreamWriter with CultureInfo.InvariantCulture, like the SerializeAsync extensions already do. Co-authored-by: menes97 <38889017+menes97@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request
Description
OpenApiSchemaJsonConverter.Writewrote the schema through aStreamWriter. That writer formats numbers with the current culture, and the result was then passed toWriteRawValuewithout validation:de-DE,1.5became1,5;fi-FI,-5was written with U+2212.Both produce invalid JSON.
OpenApiDocument.GetHashCodeAsynchad the same writer, so its hash depended on the machine's culture.Type of Change
Related Issue(s)
Fixes #3185
Changes Made
OpenApiSchemaJsonConverter.Writewrites throughFormattingStreamWriter(stream, CultureInfo.InvariantCulture), as theSerializeAsyncextensions already do. That writer also emits UTF-8 without a BOM.MemoryStream.ToArraystill works after the writer closes the stream, so the custom encoding field was removed.OpenApiDocument.GetHashCodeAsyncuses the same writer in both of its branches.Serialize_NumericValues_DoNotDependOnCurrentCulture(de-DE, fi-FI) serializes a schema with a default of 1.5 and an enum value of -5 and parses the result back;HashCodeDoesNotDependOnCurrentCulturecompares the hash under the invariant culture with the hash under de-DE.Testing
All three new test cases fail without the fix:
'5' is an invalid start of a property name;'0xE2' is an invalid start of a value;With the fix:
Checklist
Versions applicability
Additional Notes
This PR was written with AI assistance (Claude Code). I reproduced the bug, ran the tests and reviewed the change.
🤖 Generated with Claude Code