@@ -3444,15 +3444,15 @@ https://example.com/schemas/common#/$defs/count/minimum
3444
3444
{
3445
3445
"$schema": "https://json-schema.org/draft/2019-09/schema",
3446
3446
"$id": "https://example.com/tree",
3447
- "$dynamicAnchor": true ,
3447
+ "$dynamicAnchor": "node" ,
3448
3448
3449
3449
"type": "object",
3450
3450
"properties": {
3451
3451
"data": true,
3452
3452
"children": {
3453
3453
"type": "array",
3454
3454
"items": {
3455
- "$dynamicRef": "#"
3455
+ "$dynamicRef": "#node "
3456
3456
}
3457
3457
}
3458
3458
}
@@ -3462,7 +3462,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3462
3462
{
3463
3463
"$schema": "https://json-schema.org/draft/2019-09/schema",
3464
3464
"$id": "https://example.com/strict-tree",
3465
- "$dynamicAnchor": true ,
3465
+ "$dynamicAnchor": node ,
3466
3466
3467
3467
"$ref": "tree",
3468
3468
"unevaluatedProperties": false
@@ -3475,32 +3475,67 @@ https://example.com/schemas/common#/$defs/count/minimum
3475
3475
]]>
3476
3476
</artwork >
3477
3477
</figure >
3478
+ <t >
3479
+ When we load these two schemas, we will notice the "$dynamicAnchor"
3480
+ named "node" (note the lack of "#" as this is just the name)
3481
+ present in each, resulting in the following full schema URIs:
3482
+ <list style =" symbols" >
3483
+ <t >"https://example.com/tree#node"</t >
3484
+ <t >"https://example.com/strict-tree#node"</t >
3485
+ </list >
3486
+ In addition, JSON Schema implementations keep track of the fact
3487
+ that these fragments were created with "$dynamicAnchor".
3488
+ </t >
3478
3489
<t >
3479
3490
If we apply the "strict-tree" schema to the instance, we will follow
3480
3491
the "$ref" to the "tree" schema, examine its "children" subschema,
3481
- and find the "$dynamicAnchor" in its "items" subschema.
3492
+ and find the "$dynamicRef": to "#node" (note the "#" for URI fragment syntax)
3493
+ in its "items" subschema. That reference resolves to
3494
+ "https://example.com/tree#node", which is a URI with a fragment
3495
+ created by "$dynamicAnchor". Therefore we must examine the dynamic
3496
+ scope before following the reference.
3497
+ </t >
3498
+ <t >
3482
3499
At this point, the dynamic path is
3483
- "#/$ref/properties/children/items/$dynamicRef".
3500
+ "#/$ref/properties/children/items/$dynamicRef", with a dynamic scope
3501
+ containing (from the outermost scope to the innermost):
3502
+ <list style =" numbers" >
3503
+ <t >"https://example.com/strict-tree#"</t >
3504
+ <t >"https://example.com/tree#"</t >
3505
+ <t >"https://example.com/tree#/properties/children"</t >
3506
+ <t >"https://example.com/tree#/properties/children/items"</t >
3507
+ </list >
3484
3508
</t >
3485
3509
<t >
3486
- The base URI at this point is "https://example.com/tree", so the
3487
- "$dynamicRef" initially resolves to "https://example.com/tree#".
3488
- Since "$dynamicAnchor" is true, we examine the dynamic path to
3489
- see if there is a different base URI to use. We find
3490
- "$dynamicAnchor" with a true value at the dynamic paths of
3491
- "#" and "#/$ref".
3510
+ Since we are looking for a plain name fragment, which can be
3511
+ defined anywhere within a schema resource, the JSON Pointer fragments
3512
+ are irrelevant to this check. That means that we can remove those
3513
+ fragments and eliminate consecutive duplicates, producing:
3514
+ <list style =" numbers" >
3515
+ <t >"https://example.com/strict-tree"</t >
3516
+ <t >"https://example.com/tree"</t >
3517
+ </list >
3492
3518
</t >
3493
3519
<t >
3494
- The outermost is "#", which is the root schema of the "strict-tree"
3495
- schema, so we use its base URI of "https://example.com/strict-tree",
3496
- which produces a final resolved URI of
3497
- "https://example.com/strict-tree#" for the "$dynamicRef ".
3520
+ In this case, the outermost resource also has a "node" fragment
3521
+ defined by "$dynamicAnchor". Therefore instead of resolving the
3522
+ "$dynamicRef" to "https://example.com/tree#node", we resolve it to
3523
+ "https://example.com/strict-tree#node ".
3498
3524
</t >
3499
3525
<t >
3500
3526
This way, the recursion in the "tree" schema recurses to the root
3501
3527
of "strict-tree", instead of only applying "strict-tree" to the
3502
3528
instance root, but applying "tree" to instance children.
3503
3529
</t >
3530
+ <t >
3531
+ This example shows both "$dynamicAnchor"s in the same place
3532
+ in each schema, specifically the resource root schema.
3533
+ Since plain-name fragments are independent of the JSON structure,
3534
+ this would work just as well if one or both of the node schema objects
3535
+ were moved under "$defs". It is the matching "$dynamicAnchor" values
3536
+ which tell us how to resolve the dynamic reference, not any sort of
3537
+ correlation in JSON structure.
3538
+ </t >
3504
3539
</section >
3505
3540
3506
3541
<section title =" Working with vocabularies" >
@@ -3600,7 +3635,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3600
3635
{
3601
3636
"$schema": "https://json-schema.org/draft/2019-09/schema",
3602
3637
"$id": "https://example.com/meta/general-use-example",
3603
- "$dynamicAnchor": true ,
3638
+ "$dynamicAnchor": "meta" ,
3604
3639
"$vocabulary": {
3605
3640
"https://json-schema.org/draft/2019-09/vocab/core": true,
3606
3641
"https://json-schema.org/draft/2019-09/vocab/applicator": true,
@@ -3635,7 +3670,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3635
3670
{
3636
3671
"$schema": "https://json-schema.org/draft/2019-09/schema",
3637
3672
"$id": "https://example.com/meta/example-vocab",
3638
- "$dynamicAnchor": true ,
3673
+ "$dynamicAnchor": "meta" ,
3639
3674
"$vocabulary": {
3640
3675
"https://example.com/vocab/example-vocab": true,
3641
3676
},
0 commit comments