@@ -102,3 +102,85 @@ Here are some examples to illustrate the changes.
102
102
</td >
103
103
</tr >
104
104
</table >
105
+
106
+ ## $dynamicRef and $dynamicAnchor
107
+ The ` $recursiveRef ` and ` $recursiveAnchor ` keywords were replaced by the more
108
+ powerful ` $dynamicRef ` and ` $dynamicAnchor ` keywords. ` $recursiveRef ` and
109
+ ` $recursiveAnchor ` were introduced in the previous draft to solve the problem of
110
+ extending recursive schemas. As the "recursive" keywords got some use and we
111
+ understood them better, we discovered how we could generalize them to solve even
112
+ more types of problems. The name change reflects that these keywords are useful
113
+ for more than just extending recursive schemas.
114
+
115
+ A ` $dynamicAnchor ` can be thought of like a normal ` $anchor ` except that it can
116
+ be referenced across schemas rather than just in the schema it was defined in.
117
+ You can think of the old ` $recursiveAnchor ` as working the same way except that
118
+ it only allowed you to create an anchor at the root of the schema and the anchor
119
+ name is always empty.
120
+
121
+ ` $dynamicRef ` works the same as the old ` $recursiveRef ` except that fragments
122
+ are no longer empty (` "$dynamicRef": "#my-anchor" ` instead of `"$recursiveRef":
123
+ "#"` ) and non-fragment-only URIs are allowed. When a ` $dynamicRef` contains a
124
+ non-fragment-only URI-Reference, the schema the URI-Reference resolves to is
125
+ used as the starting point for dynamic resolution.
126
+
127
+ Here's how you would covert a schema using ` $recursiveRef ` to use ` $dynamicRef ` .
128
+
129
+ <table >
130
+ <tr >
131
+ <th>Draft 2019-09</th>
132
+ <th>Draft 2020-12</th>
133
+ </tr >
134
+ <tr >
135
+ <td><pre>// tree schema, extensible
136
+ {
137
+ "$schema": "https://json-schema.org/draft/2019-09/schema ",
138
+ "$id": "https://example.com/tree ",
139
+ "$recursiveAnchor": true,
140
+
141
+ "type": "object",
142
+ "properties": {
143
+ "data": true,
144
+ "children": {
145
+ "type": "array",
146
+ "items": { "$recursiveRef": "#" }
147
+ }
148
+ }
149
+ }
150
+
151
+ // strict-tree schema, guards against misspelled properties
152
+ {
153
+ "$schema": "https://json-schema.org/draft/2019-09/schema ",
154
+ "$id": "https://example.com/strict-tree ",
155
+ "$recursiveAnchor": true,
156
+
157
+ "$ref": "tree",
158
+ "unevaluatedProperties": false
159
+ }</pre ></td >
160
+ <td ><pre >// tree schema, extensible
161
+ {
162
+ "$schema": "https://json-schema.org/draft/2020-12/schema ",
163
+ "$id": "https://example.com/tree ",
164
+ "$dynamicAnchor": "node",
165
+
166
+ "type": "object",
167
+ "properties": {
168
+ "data": true,
169
+ "children": {
170
+ "type": "array",
171
+ "items": { "$dynamicRef": "#node" }
172
+ }
173
+ }
174
+ }
175
+
176
+ // strict-tree schema, guards against misspelled properties
177
+ {
178
+ "$schema": "https://json-schema.org/draft/2020-12/schema ",
179
+ "$id": "https://example.com/strict-tree ",
180
+ "$dynamicAnchor": "node",
181
+
182
+ "$ref": "tree",
183
+ "unevaluatedProperties": false
184
+ }</pre ></td >
185
+ </tr >
186
+ </table >
0 commit comments