Skip to content

fix(support/v2): backport nullability round-tripping fix from PR #2994 - #7

Merged
Youssef1313 merged 1 commit into
support/v2from
copilot/backport-pr-2994-to-support-v2
Aug 11, 2026
Merged

fix(support/v2): backport nullability round-tripping fix from PR #2994#7
Youssef1313 merged 1 commit into
support/v2from
copilot/backport-pr-2994-to-support-v2

Conversation

Copilot AI commented Aug 11, 2026

Copy link
Copy Markdown

Pull Request

Description

Backports the nullability round-tripping fix from microsoft#2994 to support/v2.
This addresses loss of null semantics during OpenAPI 3.0 schema serialize/deserialize flows, especially around enum-null patterns and nullable emission.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

Related Issue(s)

N/A

Changes Made

  • OpenAPI 3.0 schema serialization

    • Reworked type-property serialization path to always evaluate nullable emission for 3.0 output.
    • Ensures nullable: true is preserved when nullability is represented without a serializable type value.
  • Null enum preservation in reader

    • Updated JSON array materialization to preserve explicit null entries via JsonNullSentinel.
    • Prevents enum: [null] values from being dropped during deserialization.
  • Deserializer normalization for null-only enum

    • Detects enum: [null] with no explicit type and normalizes to Type = JsonSchemaType.Null.
    • Clears enum in this case to keep internal representation consistent for round-tripping.
  • Regression coverage

    • Updated OpenApiSchemaTests expectations for nullable output in 3.0 serialization.
    • Added OpenApiSchemaV30CompatibilityTests covering nullable enum/type round-tripping and compatibility transforms.

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • All existing tests pass

Checklist

  • My code follows the code style of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Versions applicability

  • My change applies to the version 1.X of the library, if so PR link:
  • My change applies to the version 2.X of the library, if so PR link: (this PR)
  • My change applies to the version 3.X of the library, if so PR link: Better nullability round-tripping microsoft/OpenAPI.NET#2994
  • I have evaluated the applicability of my change against the other versions above.

See the contributing guidelines for more information about how patches are applied across multiple versions.

Additional Notes

Example of the normalized case now preserved across round-trip:

{
  "enum": [null],
  "nullable": true
}

This is deserialized as Type = JsonSchemaType.Null (instead of dropping the null enum signal), improving fidelity when re-serializing.

fixes a bug in deserialization where a null in enum array would be dropped
emits "nullable": true when we detect a null type, even if we haven't serialized a type (i.e, we allow emitting a redundant nullable property)
detects the pattern of `enum: [ null ]`, and deserialize it `JsonSchemaType.Null`. This makes round-tripping behavior better.

(cherry picked from commit 655c2c8)

Co-authored-by: Youssef1313 <31348972+Youssef1313@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants