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
feat(library): resolve JSON Schema dialects when reading - #3160
This starts the reader-side work for #2963. Schemas use their explicit $schema, then the enclosing schema's dialect, the document's jsonSchemaDialect, and finally the OpenAPI default.
The known dialects use the existing version services. Unknown dialects keep their schema data and produce a diagnostic. With external loading enabled, their meta-schema chains can resolve to a supported dialect without parsing the document again, so custom reader changes and callbacks are preserved.
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)
Related to #2963. This is a draft for the reader work discussed there, not a claim that the full issue is complete.
Changes Made
Add context-owned dialect selection for OpenAPI 3.1 and 3.2, using the existing schema readers.
Resolve unknown meta-schema chains through the configured loader, with per-read caching, cycle detection, cancellation, a 16-load limit and a 1 MiB response limit.
Correct absolute-URI handling in the default loader and add reader, loader, diagnostic and callback regressions, plus usage documentation.
Testing
Unit tests added/updated
Integration tests added/updated
Manual testing performed
All existing tests pass
Verified locally for PR head 24af207, based on main 113803c, using .NET SDK 10.0.403:
Dialect-focused tests: 88 passed.
Full solution tests with coverage: 2,041 passed, no failures or skips.
Release solution build: no warnings or errors.
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: not opened yet.
My change applies to the version 3.X of the library, if so PR link: this PR.
I have evaluated the applicability of my change against the other versions above.
The 3.1 reader behavior and loader correction are also relevant to 2.X; no backport is included in this draft. Version 1.X has no 3.1/3.2 dialect support and its loader does not use the affected synthetic-base path.
Writing still follows the requested OpenAPI output version. This does not add parsing rules for older JSON Schema drafts or custom vocabularies; it resolves chains to the two dialects already handled by the version services. The writer-side direction can be worked through during draft review.
The repository's performance and Windows trimming/NativeAOT checks were not run locally and still need to pass before merge.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The fallback can discard unsupported schema constraints, while resolver timeout handling can abort document loading and fragment-insensitive mappings can incorrectly suppress unresolved-dialect diagnostics.
Adds reader-side JSON Schema dialect selection for OpenAPI 3.1 and 3.2, advancing #2963 while leaving serialization tied to the requested OpenAPI version.
Changes:
Selects dialects using schema declarations, inheritance, document settings, and defaults.
Adds opt-in meta-schema chain resolution with caching, cycle detection, and resource limits.
Corrects absolute-URI loading and adds documentation and regression coverage.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Dialect URI fragments are ignored, potentially suppressing unsupported-dialect diagnostics, and non-boolean $vocabulary values in unsupported schemas can throw instead of being preserved with diagnostics.
An unsupported draft-07 schema with $vocabulary: { "urn:example:vocab": "custom" } throws FormatException through CreateSimpleMap(LoadBool) instead of preserving the keyword and returning a schema with diagnostics. The scalar-only recovery guard excludes this field because its value is a JsonObject. Recover conversion failures from non-schema containers too, while preserving exception propagation from explicitly supported nested schemas.
Resolve dialect fragments before checking schema support
The default HTTP/file loader returns the whole resource, but this code reads only its root $schema, ignoring a non-empty dialect URI fragment. Consequently, https://example.com/meta#missing is treated as supported when the root declares a known dialect, and its unsupported-dialect diagnostic is removed. Resolve the JSON Pointer or anchor and determine the target schema's effective dialect before following the chain; retain the diagnostic if the target cannot be resolved.
For A0 -> A1 -> ... -> A16 -> known, resolving A0 before A1 leaves A0 unsupported, but resolving A1 first caches its success and lets A0 succeed here. Both orders perform 17 loads overall, yet produce different diagnostics. Apply consistent limit accounting to cached chains (for example, retain their hop counts for a chain-depth limit), and add a regression that reverses schema order.
Preserve incompatible reference keywords during initial schema extraction
For an unsupported dialect, an object-valued $dynamicRef throws during LoadSchemaCore's initial keyword extraction, before fallback preservation runs. In components.schemas, this aborts the map assignment and loses otherwise valid sibling schemas too. Make the initial $ref, $dynamicRef, and $id extraction fallback-aware in both V31 and V32 deserializers, preserving incompatible values as raw keywords while continuing to parse the schema.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because diagnostics for unsupported schema declarations in composition arrays omit element indices, causing distinct declarations to share the same reported location.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Security-sensitive external meta-schema loading and inferred dialect compatibility require maintainer validation of trust boundaries, with Windows trimming/NativeAOT checks still outstanding.
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
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
This starts the reader-side work for #2963. Schemas use their explicit
$schema, then the enclosing schema's dialect, the document'sjsonSchemaDialect, and finally the OpenAPI default.The known dialects use the existing version services. Unknown dialects keep their schema data and produce a diagnostic. With external loading enabled, their meta-schema chains can resolve to a supported dialect without parsing the document again, so custom reader changes and callbacks are preserved.
Type of Change
Related Issue(s)
Related to #2963. This is a draft for the reader work discussed there, not a claim that the full issue is complete.
Changes Made
Testing
Verified locally for PR head
24af207, based on main113803c, using .NET SDK 10.0.403:Checklist
Versions applicability
The 3.1 reader behavior and loader correction are also relevant to 2.X; no backport is included in this draft. Version 1.X has no 3.1/3.2 dialect support and its loader does not use the affected synthetic-base path.
See the contributing guidelines for how patches are applied across versions.
Additional Notes
Writing still follows the requested OpenAPI output version. This does not add parsing rules for older JSON Schema drafts or custom vocabularies; it resolves chains to the two dialects already handled by the version services. The writer-side direction can be worked through during draft review.
The repository's performance and Windows trimming/NativeAOT checks were not run locally and still need to pass before merge.