|
662 | 662 | The path from this root schema to any particular keyword (that
|
663 | 663 | includes any "$ref" and "$dynamicRef" keywords that may have
|
664 | 664 | been resolved) is considered the keyword's "validation path."
|
665 |
| - <cref> |
666 |
| - Or should this be the schema object at which processing |
667 |
| - begins, even if it is not a root? This has some implications |
668 |
| - for the case where "$dynamicAnchor" is only allowed in the |
669 |
| - root schema but processing begins in a subschema. |
670 |
| - </cref> |
671 | 665 | </t>
|
672 | 666 | <t>
|
673 | 667 | Lexical and dynamic scopes align until a reference keyword
|
|
1383 | 1377 | The "$anchor" and "$dynamicAnchor" keywords are used to specify such
|
1384 | 1378 | fragments. They are identifier keywords that can only be used to create
|
1385 | 1379 | plain name fragments, rather than absolute URIs as seen with "$id".
|
1386 |
| - The behavior of the created fragment is identical for both keywords. |
1387 | 1380 | </t>
|
1388 | 1381 | <t>
|
1389 | 1382 | The base URI to which the resulting fragment is appended is the canonical
|
|
1393 | 1386 | for the document as determined according to RFC 3986.
|
1394 | 1387 | </t>
|
1395 | 1388 | <t>
|
1396 |
| - Separately from the usual usage of URIs, "$dynamicAnchor" |
1397 |
| - indicates that the fragment is an extension point when used with |
1398 |
| - the "$dynamicRef" keyword. This low-level, advanced feature |
1399 |
| - makes it easier to extend recursive schemas such as the meta-schemas, |
1400 |
| - without imposing any particular semantics on that extension. |
1401 |
| - See the section on <xref target="dynamic-ref">"$dynamicRef"</xref> |
1402 |
| - for details. |
| 1389 | + In addition to setting an anchor, "$dynamicAnchor" is used to mark locations that |
| 1390 | + can be used for dynamic scope resolution. This low-level, advanced feature makes |
| 1391 | + it easier to extend recursive schemas such as the meta-schemas, without imposing |
| 1392 | + any particular semantics on that extension. See the section on |
| 1393 | + <xref target="dynamic-ref">"$dynamicRef"</xref> for details. |
1403 | 1394 | </t>
|
1404 | 1395 | <t>
|
1405 | 1396 | In most cases, the normal fragment behavior both suffices and
|
|
1451 | 1442 | <t>
|
1452 | 1443 | The "$ref" keyword is an applicator that is used to reference a statically
|
1453 | 1444 | identified schema. Its results are the results of the referenced schema.
|
1454 |
| - <cref> |
1455 |
| - Note that this definition of how the results are determined means that |
1456 |
| - other keywords can appear alongside of "$ref" in the same schema object. |
1457 |
| - </cref> |
1458 | 1445 | </t>
|
1459 | 1446 | <t>
|
1460 |
| - The value of the "$ref" property MUST be a string which is a URI-Reference. |
| 1447 | + The value of the "$ref" keyword MUST be a string which is a URI-Reference. |
1461 | 1448 | Resolved against the current URI base, it produces the URI of the schema
|
1462 | 1449 | to apply. This resolution is safe to perform on schema load, as the
|
1463 | 1450 | process of evaluating an instance cannot change how the reference resolves.
|
|
1466 | 1453 |
|
1467 | 1454 | <section title='Dynamic References with "$dynamicRef"' anchor="dynamic-ref">
|
1468 | 1455 | <t>
|
1469 |
| - The "$dynamicRef" keyword is an applicator that allows for deferring the |
1470 |
| - full resolution until runtime, at which point it is resolved each time it is |
1471 |
| - encountered while evaluating an instance. |
| 1456 | + The "$dynamicRef" keyword is an applicator that uses the dynamic scope to |
| 1457 | + reference a schema. Its results are the results of the referenced schema. |
1472 | 1458 | </t>
|
1473 | 1459 | <t>
|
1474 |
| - Together with "$dynamicAnchor", "$dynamicRef" implements a cooperative |
1475 |
| - extension mechanism that is primarily useful with recursive schemas |
1476 |
| - (schemas that reference themselves). Both the extension point and the |
1477 |
| - runtime-determined extension target are defined with "$dynamicAnchor", |
1478 |
| - and only exhibit runtime dynamic behavior when referenced with |
1479 |
| - "$dynamicRef". |
| 1460 | + The URI base for the "$dynamicRef" keyword is the outermost schema resource in |
| 1461 | + the <xref target="scopes">dynamic scope</xref> that defines an identically named |
| 1462 | + fragment with "$dynamicAnchor". If no "$dynamicAnchor" is found matching the |
| 1463 | + fragment in the "$dynamicRef", the URI base is the current lexical scope. |
1480 | 1464 | </t>
|
1481 | 1465 | <t>
|
1482 |
| - The value of the "$dynamicRef" property MUST be a string which is |
1483 |
| - a URI-Reference. Resolved against the current URI base, it produces |
1484 |
| - the URI used as the starting point for runtime resolution. This initial |
1485 |
| - resolution is safe to perform on schema load. |
1486 |
| - </t> |
1487 |
| - <t> |
1488 |
| - If the initially resolved starting point URI includes a fragment that |
1489 |
| - was created by the "$dynamicAnchor" keyword, the initial URI MUST be |
1490 |
| - replaced by the URI (including the fragment) for the outermost schema |
1491 |
| - resource in the <xref target="scopes">dynamic scope</xref> that defines |
1492 |
| - an identically named fragment with "$dynamicAnchor". |
1493 |
| - <cref> |
1494 |
| - Requiring both the initial and final URI fragment to be defined |
1495 |
| - by "$dynamicAnchor" ensures that the more common "$anchor" |
1496 |
| - never unexpectedly changes the dynamic resolution process |
1497 |
| - due to a naming conflict across resources. Users of |
1498 |
| - "$dynamicAnchor" are expected to be aware of the possibility |
1499 |
| - of such name collisions, while users of "$anchor" are not. |
1500 |
| - </cref> |
1501 |
| - </t> |
1502 |
| - <t> |
1503 |
| - Otherwise, its behavior is identical to "$ref", and no runtime |
1504 |
| - resolution is needed. |
| 1466 | + The value of the "$dynamicRef" keyword MUST be a string which is a URI-Reference. |
| 1467 | + Resolved against the URI base, it produces the URI of the schema to apply. This |
| 1468 | + resolution is not safe to perform on schema load, as the process of evaluating an |
| 1469 | + instance can change how the reference resolves. |
1505 | 1470 | </t>
|
1506 | 1471 | <t>
|
1507 | 1472 | For a full example using these keyword, see appendix
|
@@ -3580,7 +3545,7 @@ https://example.com/schemas/common#/$defs/count/minimum
|
3580 | 3545 | {
|
3581 | 3546 | "$schema": "https://json-schema.org/draft/2020-11/schema",
|
3582 | 3547 | "$id": "https://example.com/strict-tree",
|
3583 |
| - "$dynamicAnchor": node, |
| 3548 | + "$dynamicAnchor": "node", |
3584 | 3549 |
|
3585 | 3550 | "$ref": "tree",
|
3586 | 3551 | "unevaluatedProperties": false
|
@@ -3608,10 +3573,8 @@ https://example.com/schemas/common#/$defs/count/minimum
|
3608 | 3573 | If we apply the "strict-tree" schema to the instance, we will follow
|
3609 | 3574 | the "$ref" to the "tree" schema, examine its "children" subschema,
|
3610 | 3575 | and find the "$dynamicRef": to "#node" (note the "#" for URI fragment syntax)
|
3611 |
| - in its "items" subschema. That reference resolves to |
3612 |
| - "https://example.com/tree#node", which is a URI with a fragment |
3613 |
| - created by "$dynamicAnchor". Therefore we must examine the dynamic |
3614 |
| - scope before following the reference. |
| 3576 | + in its "items" subschema. We then need to examine the dynamic scope before |
| 3577 | + following the reference. |
3615 | 3578 | </t>
|
3616 | 3579 | <t>
|
3617 | 3580 | At this point, the dynamic path is
|
|
0 commit comments