Skip to content

Fix array handling for JSON pointers when resolving OpenAPI schemas - #67573

Merged
Youssef1313 merged 3 commits into
mainfrom
dev/ygerges/json-ref-handling
Jul 3, 2026
Merged

Youssef1313 merged 3 commits into
mainfrom
dev/ygerges/json-ref-handling

Conversation

@Youssef1313

Copy link
Copy Markdown
Member

Fix array handling for JSON pointers when resolving OpenAPI schemas

Fixes #66800
Fixes #65759

The algorithm for resolving a reference (a JSON pointer) was naive and didn't implement the spec correctly.

  1. It didn't handle retrieving a JsonArray element by index.
  2. It didn't handle unescaping of ~1 and ~0.
  3. It didn't handle unescaping url-encoded values in the reference.

This PR attempts to implement it per the specification, referencing the relevant spec parts when needed.

Copilot AI review requested due to automatic review settings July 3, 2026 08:22
@Youssef1313
Youssef1313 requested a review from a team as a code owner July 3, 2026 08:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes JSON Pointer ($ref) resolution in OpenApiSchemaService to follow RFC 6901 more closely, addressing failures when navigating into arrays (e.g., anyOf/0/...) and when reference tokens require unescaping. It also adds regression coverage for polymorphic schemas with dictionary-valued properties to ensure derived schemas are fully populated.

Changes:

  • Update $ref resolution to parse JSON Pointer tokens, including ~0/~1 unescaping and URI unescaping, and to support navigating JsonArray by index.
  • Add regression test coverage for polymorphic derived schemas that previously ended up with empty additionalProperties due to unresolved pointers.
  • Adjust the test helper to return the generated OpenApiDocument so tests can serialize/compare full documents.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs Implements JSON Pointer parsing/token evaluation for $ref resolution (including arrays and unescaping).
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Shared/SharedTypes.Polymorphism.cs Adds polymorphic dictionary-container types used by the new regression test.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiSchemaService/OpenApiSchemaService.PolymorphicSchemas.cs Adds regression test asserting dictionary schemas are complete for every derived type; compares serialized document JSON.
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Services/OpenApiDocumentServiceTestsBase.cs Changes helper to return OpenApiDocument to support follow-up serialization/assertions.

@Youssef1313
Youssef1313 marked this pull request as draft July 3, 2026 08:34
@Youssef1313
Youssef1313 marked this pull request as ready for review July 3, 2026 09:03
@Youssef1313
Youssef1313 merged commit db4dc2c into main Jul 3, 2026
25 checks passed
@Youssef1313
Youssef1313 deleted the dev/ygerges/json-ref-handling branch July 3, 2026 16:44
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants