fix(reader): preserve Null flag when nullable appears before type in V3.0/V3.1/V3.2 deserializers#2853
Merged
Conversation
…able in V3.1/V3.2 deserializers Agent-Logs-Url: https://github.com/microsoft/OpenAPI.NET/sessions/40596ef1-e9f2-4d1b-b9e2-0650b96d73b4 Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix OpenAPI 3.1 V31 deserializer losing nullable for key order
fix(reader): preserve Null flag when nullable appears before type in V3.1/V3.2 deserializers
May 26, 2026
Member
|
@copilot duplicate the test for 3.0 and 3.2 as well |
Agent-Logs-Url: https://github.com/microsoft/OpenAPI.NET/sessions/6de5cea9-ff8f-4a95-804d-493007f279f3 Co-authored-by: baywet <7905502+baywet@users.noreply.github.com>
Contributor
Author
Copilot
AI
changed the title
fix(reader): preserve Null flag when nullable appears before type in V3.1/V3.2 deserializers
fix(reader): preserve Null flag when nullable appears before type in V3.0/V3.1/V3.2 deserializers
May 26, 2026
baywet
approved these changes
May 26, 2026
Member
|
do not merge before #2854 has been merged and published. |
|
baywet
approved these changes
May 26, 2026
adrian05-ms
approved these changes
May 26, 2026
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.


The V3.1/V3.2 schema deserializer's
"type"handler unconditionally overwroteo.Type, discarding anyJsonSchemaType.Nullflag already set by a preceding"nullable": truehandler. Result:nullable: truewas silently dropped whenever it appeared beforetypein the document.Description
Key-order bug in
OpenApiV31Deserializer(and V32): the"nullable"handler setso.Type = JsonSchemaType.Nullwhen type is unknown, but the"type"handler then does a direct assignment, erasing it. V3.0 is unaffected by the production code bug — it appliesnullableas a post-processing step after all keys are parsed, making it inherently order-independent.Before:
After:
Type of Change
Changes Made
V31/OpenApiSchemaDeserializer.cs:"type"handler now checks for an existingNullflag (set by a precedingnullable: true) and preserves it via bitwise OR for both scalar and array type valuesV32/OpenApiSchemaDeserializer.cs: same fix appliedV31Tests/OpenApiSchemaTests.cs: added parameterized test assertingnullablebefore or aftertypeboth yieldJsonSchemaType.String | JsonSchemaType.NullV3Tests/OpenApiSchemaTests.cs: same test duplicated for OpenAPI 3.0V32Tests/OpenApiSchemaTests.cs: same test duplicated for OpenAPI 3.2Testing
Checklist
Versions applicability
Additional Notes
The V3.0 deserializer is not affected by the production code bug — it applies
nullableas a deferred post-processing step after all keys have been parsed, making it inherently order-independent. Tests for V3.0 were added to confirm this behaviour is and remains correct.