Commit 8d0accc
committed
feat(schema): resolve $dynamicRef against $dynamicAnchor via OpenApiSchemaReference
Implements document-scoped $dynamicRef resolution per JSON Schema
2020-12 §8.2.3.2. Bare $dynamicRef schemas (no $ref) now deserialize
as OpenApiSchemaReference whose Target resolves via per-document
$dynamicAnchor and $anchor registries in OpenApiWorkspace.
Resolution order in Target:
1. $dynamicAnchor index (single candidate → resolved automatically)
2. $anchor fallback when zero $dynamicAnchor candidates exist (per §8.2.3.2)
3. null when ambiguous (multiple candidates need dynamic-scope tracking)
Anchor registries are populated by recursively walking the entire
document tree: component schemas, reusable component definitions
(parameters, responses, request bodies, headers, callbacks, path items,
media types), inline schemas (paths, operations, webhooks), and all
nested subschema locations ($defs, properties, items, allOf, if/then/else,
etc.). Anchor registration is merged into RegisterSchemaIdentifiers
(#2918) so the schema tree is walked once instead of twice.
IsDynamicRefOnly is computed from whether $dynamicRef is set and
ReferenceV3 does not point to a component path — no field to forget
when building from the object model.
ResolveDynamicAnchorInContext special-cases OpenApiSchemaReference to
read from Reference.DynamicAnchor/Definitions directly, never falling
through to Target.
Reference holder guards prevent the structural walk from crossing
document boundaries through OpenApiParameterReference,
OpenApiResponseReference, etc.
Test snapshots use a custom JsonConverter<IOpenApiSchema> that routes
schema serialization through the native OpenAPI writer, avoiding
reflection cycles from recursive $dynamicRef.
Public APIs for consumers tracking dynamic scope:
- GetDynamicAnchorCandidates(doc, anchorName): returns all candidate schemas
- ResolveDynamicAnchorInContext(contextSchema, anchorName): resolves against
a specific entry-point schema's $defs without crossing reference boundaries
Known limitation: relative URI resolution in $dynamicRef is not yet
implemented (tracked as #2928). Cross-document resolution works for
absolute URIs only.1 parent 1591007 commit 8d0accc
20 files changed
Lines changed: 3300 additions & 140 deletions
File tree
- performance/benchmark/BenchmarkDotNet.Artifacts/results
- src/Microsoft.OpenApi
- Models
- References
- Reader
- V31
- V32
- Services
- test/Microsoft.OpenApi.Readers.Tests
- V31Tests
- V32Tests
Lines changed: 7 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
Lines changed: 8 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.
Lines changed: 31 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
0 commit comments