@@ -3434,15 +3434,15 @@ https://example.com/schemas/common#/$defs/count/minimum
3434
3434
{
3435
3435
"$schema": "https://json-schema.org/draft/2019-09/schema",
3436
3436
"$id": "https://example.com/tree",
3437
- "$dynamicAnchor": true ,
3437
+ "$dynamicAnchor": "node" ,
3438
3438
3439
3439
"type": "object",
3440
3440
"properties": {
3441
3441
"data": true,
3442
3442
"children": {
3443
3443
"type": "array",
3444
3444
"items": {
3445
- "$dynamicRef": "#"
3445
+ "$dynamicRef": "#node "
3446
3446
}
3447
3447
}
3448
3448
}
@@ -3452,7 +3452,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3452
3452
{
3453
3453
"$schema": "https://json-schema.org/draft/2019-09/schema",
3454
3454
"$id": "https://example.com/strict-tree",
3455
- "$dynamicAnchor": true ,
3455
+ "$dynamicAnchor": node ,
3456
3456
3457
3457
"$ref": "tree",
3458
3458
"unevaluatedProperties": false
@@ -3465,32 +3465,67 @@ https://example.com/schemas/common#/$defs/count/minimum
3465
3465
]]>
3466
3466
</artwork >
3467
3467
</figure >
3468
+ <t >
3469
+ When we load these two schemas, we will notice the "$dynamicAnchor"
3470
+ named "node" (note the lack of "#" as this is just the name)
3471
+ present in each, resulting in the following full schema URIs:
3472
+ <list style =" symbols" >
3473
+ <t >"https://example.com/tree#node"</t >
3474
+ <t >"https://example.com/strict-tree#node"</t >
3475
+ </list >
3476
+ In addition, JSON Schema implementations keep track of the fact
3477
+ that these fragments were created with "$dynamicAnchor".
3478
+ </t >
3468
3479
<t >
3469
3480
If we apply the "strict-tree" schema to the instance, we will follow
3470
3481
the "$ref" to the "tree" schema, examine its "children" subschema,
3471
- and find the "$dynamicAnchor" in its "items" subschema.
3482
+ and find the "$dynamicRef": to "#node" (note the "#" for URI fragment syntax)
3483
+ in its "items" subschema. That reference resolves to
3484
+ "https://example.com/tree#node", which is a URI with a fragment
3485
+ created by "$dynamicAnchor". Therefore we must examine the dynamic
3486
+ scope before following the reference.
3487
+ </t >
3488
+ <t >
3472
3489
At this point, the dynamic path is
3473
- "#/$ref/properties/children/items/$dynamicRef".
3490
+ "#/$ref/properties/children/items/$dynamicRef", with a dynamic scope
3491
+ containing (from the outermost scope to the innermost):
3492
+ <list style =" numbers" >
3493
+ <t >"https://example.com/strict-tree#"</t >
3494
+ <t >"https://example.com/tree#"</t >
3495
+ <t >"https://example.com/tree#/properties/children"</t >
3496
+ <t >"https://example.com/tree#/properties/children/items"</t >
3497
+ </list >
3474
3498
</t >
3475
3499
<t >
3476
- The base URI at this point is "https://example.com/tree", so the
3477
- "$dynamicRef" initially resolves to "https://example.com/tree#".
3478
- Since "$dynamicAnchor" is true, we examine the dynamic path to
3479
- see if there is a different base URI to use. We find
3480
- "$dynamicAnchor" with a true value at the dynamic paths of
3481
- "#" and "#/$ref".
3500
+ Since we are looking for a plain name fragment, which can be
3501
+ defined anywhere within a schema resource, the JSON Pointer fragments
3502
+ are irrelevant to this check. That means that we can remove those
3503
+ fragments and eliminate consecutive duplicates, producing:
3504
+ <list style =" numbers" >
3505
+ <t >"https://example.com/strict-tree"</t >
3506
+ <t >"https://example.com/tree"</t >
3507
+ </list >
3482
3508
</t >
3483
3509
<t >
3484
- The outermost is "#", which is the root schema of the "strict-tree"
3485
- schema, so we use its base URI of "https://example.com/strict-tree",
3486
- which produces a final resolved URI of
3487
- "https://example.com/strict-tree#" for the "$dynamicRef ".
3510
+ In this case, the outermost resource also has a "node" fragment
3511
+ defined by "$dynamicAnchor". Therefore instead of resolving the
3512
+ "$dynamicRef" to "https://example.com/tree#node", we resolve it to
3513
+ "https://example.com/strict-tree#node ".
3488
3514
</t >
3489
3515
<t >
3490
3516
This way, the recursion in the "tree" schema recurses to the root
3491
3517
of "strict-tree", instead of only applying "strict-tree" to the
3492
3518
instance root, but applying "tree" to instance children.
3493
3519
</t >
3520
+ <t >
3521
+ This example shows both "$dynamicAnchor"s in the same place
3522
+ in each schema, specifically the resource root schema.
3523
+ Since plain-name fragments are independent of the JSON structure,
3524
+ this would work just as well if one or both of the node schema objects
3525
+ were moved under "$defs". It is the matching "$dynamicAnchor" values
3526
+ which tell us how to resolve the dynamic reference, not any sort of
3527
+ correlation in JSON structure.
3528
+ </t >
3494
3529
</section >
3495
3530
3496
3531
<section title =" Working with vocabularies" >
@@ -3590,7 +3625,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3590
3625
{
3591
3626
"$schema": "https://json-schema.org/draft/2019-09/schema",
3592
3627
"$id": "https://example.com/meta/general-use-example",
3593
- "$dynamicAnchor": true ,
3628
+ "$dynamicAnchor": "meta" ,
3594
3629
"$vocabulary": {
3595
3630
"https://json-schema.org/draft/2019-09/vocab/core": true,
3596
3631
"https://json-schema.org/draft/2019-09/vocab/applicator": true,
@@ -3625,7 +3660,7 @@ https://example.com/schemas/common#/$defs/count/minimum
3625
3660
{
3626
3661
"$schema": "https://json-schema.org/draft/2019-09/schema",
3627
3662
"$id": "https://example.com/meta/example-vocab",
3628
- "$dynamicAnchor": true ,
3663
+ "$dynamicAnchor": "meta" ,
3629
3664
"$vocabulary": {
3630
3665
"https://example.com/vocab/example-vocab": true,
3631
3666
},
0 commit comments