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
Copy file name to clipboardExpand all lines: content/2020-12/core/dynamicAnchor.markdown
+56-2Lines changed: 56 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,7 +22,61 @@ related:
22
22
keyword: $anchor
23
23
---
24
24
25
-
The `$dynamicAnchor` keyword allows the creation of plain name fragments that are not tied to a particular structural location within a schema. This is particularly useful for making subschemas reusable and relocatable without needing to update JSON Pointer references. Unlike `$anchor`, `$dynamicAnchor` indicates an extension point when used with the `$dynamicRef` keyword, facilitating the extension of recursive schemas without imposing specific semantics on that extension. Without `$dynamicRef`, `$dynamicAnchor` behaves the same as `$anchor`.
25
+
26
+
The [`$dynamicAnchor`]({{< ref "2020-12/core/dynamicanchor" >}}) keyword is an
27
+
extension of the [`$anchor`]({{< ref "2020-12/core/anchor" >}}) keyword that
28
+
not only associates a subschema with the given URI fragment identifier, but
29
+
also records this association in the [dynamic
30
+
scope](https://json-schema.org/blog/posts/dynamicref-and-generics). When
31
+
resolving a dynamic anchor using the [`$dynamicRef`]({{< ref
32
+
"2020-12/core/dynamicref" >}}) keyword, the base URI of the origin is not
33
+
considered. Instead, evaluation jumps to the first encountered occurence of the
by Greg Dennis (co-author of the JSON Schema specification) for a hands-on
53
+
discussion of this concept.
54
+
55
+
{{</best-practice>}}
56
+
57
+
{{<learning-more>}}
58
+
59
+
The official JSON Schema meta-schemas define, by convention, a dynamic anchor
60
+
called `meta`. This is a fundamental building block for schema extensibility.
61
+
The meta-schema of every vocabulary (official or third-party) hooks into this
62
+
dynamic anchor to extend the recursive definition of what constitutes a valid
63
+
schema for the given dialect.
64
+
65
+
More specifically, by relying on the `meta` dynamic anchor, a vocabulary
66
+
meta-schema can validate the presence of a new keyword and have those
67
+
constraints be automatically discovered and applied by any applicator of any
68
+
other vocabulary (even future ones).
69
+
70
+
{{</learning-more>}}
71
+
72
+
{{<common-pitfall>}}
73
+
74
+
The schema resource from where the dynamic anchor lookup originates _must_
75
+
declare such dynamic anchor. Otherwise, the schema would be unusable until
76
+
another schema provides a definition for dynamic such anchor. This rule is
77
+
informally referred to as the _bookending requirement_.
78
+
79
+
{{</common-pitfall>}}
26
80
27
81
## Examples
28
82
@@ -61,4 +115,4 @@ The `$dynamicAnchor` keyword allows the creation of plain name fragments that ar
61
115
[ "foo", 42 ]
62
116
{{</instance-fail>}}
63
117
64
-
_**Note:** A `$dynamicRef` referencing a `$dynamicAnchor` within the same schema resource functions similarly to a standard `$ref` referencing an `$anchor`. Similarly, a `$dynamicRef` referencing an `$anchor` within the same schema resource behaves like a typical `$ref` referencing an `$anchor`. Likewise, a `$ref` targeting a `$dynamicAnchor` within the same schema resource behaves like a regular `$ref` targeting an `$anchor`._
118
+
_**Note:** A `$dynamicRef` referencing a `$dynamicAnchor` within the same schema resource functions similarly to a standard `$ref` referencing an `$anchor`. Similarly, a `$dynamicRef` referencing an `$anchor` within the same schema resource behaves like a typical `$ref` referencing an `$anchor`. Likewise, a `$ref` targeting a `$dynamicAnchor` within the same schema resource behaves like a regular `$ref` targeting an `$anchor`._
0 commit comments