@@ -240,7 +240,7 @@ A schema that itself describes a schema is called a meta-schema. Meta-schemas
240
240
are used to validate JSON Schemas and specify the set of keywords those schemas
241
241
are using.
242
242
243
- #### Root Schema and Subschemas and Resources {#root}
243
+ #### Root Schema, Subschemas, and Resources {#root}
244
244
245
245
A JSON Schema resource is a schema which is
246
246
[ canonically] ( https://www.rfc-editor.org/info/rfc6596 ) identified by an
@@ -334,9 +334,8 @@ NCNameChar = NCNameStartChar / "-" / "." / DIGIT
334
334
All fragment identifiers that do not match the JSON Pointer syntax MUST be
335
335
interpreted as plain name fragment identifiers.
336
336
337
- Defining and referencing a plain name fragment identifier within an
338
- ` application/schema+json ` document are specified in the [ ` $anchor `
339
- keyword] ( #anchors ) section.
337
+ Defining a plain name fragment identifier within an ` application/schema+json `
338
+ document is specified in the [ ` $anchor ` keyword] ( #anchors ) section.
340
339
341
340
## General Considerations
342
341
@@ -950,40 +949,35 @@ an [absolute IRI](https://www.rfc-editor.org/rfc/rfc3987.html#section-2.2)
950
949
951
950
#### Defining location-independent identifiers {#anchors}
952
951
953
- Using JSON Pointer fragments requires knowledge of the structure of the schema.
954
- When writing schema documents with the intention to provide re-usable schemas,
955
- it may be preferable to use a plain name fragment that is not tied to any
956
- particular structural location. This allows a subschema to be relocated without
957
- requiring JSON Pointer references to be updated.
958
-
959
- The ` $anchor ` and ` $dynamicAnchor ` keywords are used to specify such fragments.
960
- They are identifier keywords that can only be used to create plain name
961
- fragments, rather than absolute IRIs as seen with ` $id ` .
962
-
963
- ` $anchor ` defines a reference target for ` $ref ` . The fragment defined by this
964
- keyword is appended to the IRI of the schema resource containing it. As
965
- discussed in {{id-keyword}}, this is either the nearest ` $id ` in the same or an
966
- ancestor schema object, or the base IRI for the document as determined according
967
- to [ RFC 3987] [ rfc3987 ] and
968
- [ RFC 3986] [ rfc3986 ] .
969
-
970
- In contrast, ` $dynamicAnchor ` operates independently of resource IRIs and is
971
- instead dependent on the dynamic scope of the evaluation. ` $dynamicAnchor `
972
- defines a reference target for the ` $dynamicRef ` keyword. This advanced feature
973
- makes it easier to extend recursive schemas such as the meta-schemas, without
974
- imposing any particular semantics on that extension. See {{dynamic-ref}} for
975
- details.
952
+ Using JSON Pointers in IRI fragments to reference subschemas couples the IRI to
953
+ the structure of the schema. Using plain name fragment identifiers in IRI
954
+ fragments to identify subschemas is sometimes preferable because it is not tied
955
+ to a particular structural location. This allows a subschema to be relocated
956
+ without requiring references to be updated.
976
957
977
- In most cases, the normal fragment behavior both suffices and is more intuitive.
978
- Therefore it is RECOMMENDED that ` $anchor ` be used to create plain name
979
- fragments unless there is a clear need for ` $dynamicAnchor ` .
958
+ The ` $anchor ` and ` $dynamicAnchor ` keywords are used to define
959
+ location-independent identifiers for subschemas within a schema resource.
980
960
981
- If present, the value of these keywords MUST be a string and MUST conform to the
982
- plain name fragment identifier syntax defined in {{fragments}}.[ ^ 4 ]
961
+ ` $anchor ` defines a plain name fragment identifier that can be used in IRI
962
+ fragments as an alternative to JSON Pointers. [ ^ 4 ] See {{fragments}}.
983
963
984
964
[ ^ 4 ] : Note that the anchor string does not include the "#" character, as it is
985
- not a IRI reference. An ` $anchor ` : "foo" becomes the fragment ` #foo ` when used
986
- in a IRI. See below for full examples.
965
+ just a fragment identifier not an IRI reference. To reference the "foo"
966
+ ` $anchor ` from the same schema resource, you would use the fragment-only IRI
967
+ ` #foo ` . See below for full examples.
968
+
969
+ ` $dynamicAnchor ` defines a different kind of fragment identifier that only has
970
+ meaning when used with ` $dynamicRef ` . It's not a normal fragment identifier and
971
+ therefore can't be used anywhere other than ` $dynamicRef ` . Normal [ fragment
972
+ identifiers] ( https://www.rfc-editor.org/rfc/rfc3986#section-3.5 ) identify the
973
+ secondary resource (the subschema) while the rest of the IRI identifies the
974
+ primary resource (the schema resource). The fragment identifiers defined by
975
+ ` $dynamicAnchor ` are not normal fragment identifies because they identify both
976
+ the primary resource and the secondary resource. See {{dynamic-ref}} for
977
+ details.
978
+
979
+ If present, the value of these keywords MUST be a string and MUST conform to the
980
+ plain name fragment identifier syntax defined in {{fragments}}.
987
981
988
982
#### Duplicate schema identifiers {#duplicate-iris}
989
983
@@ -1007,7 +1001,7 @@ identified schema. Its results are the results of the referenced schema.[^5]
1007
1001
[ ^ 5 ] : Note that this definition of how the results are determined means that
1008
1002
other keywords can appear alongside of ` $ref ` in the same schema object.
1009
1003
1010
- The value of the ` $ref ` keyword MUST be a string which is a IRI reference.
1004
+ The value of the ` $ref ` keyword MUST be a string which is an IRI reference.
1011
1005
Resolved against the current IRI base, it produces the IRI of the schema to
1012
1006
apply. This resolution is safe to perform on schema load, as the process of
1013
1007
evaluating an instance cannot change how the reference resolves.
@@ -1019,28 +1013,25 @@ default to operating offline.
1019
1013
1020
1014
##### Dynamic References with ` $dynamicRef ` {#dynamic-ref}
1021
1015
1022
- The ` $dynamicRef ` keyword is an applicator that allows for deferring the full
1023
- resolution until runtime, at which point it is resolved each time it is
1024
- encountered while evaluating an instance.
1025
-
1026
- Together with ` $dynamicAnchor ` , ` $dynamicRef ` implements a cooperative extension
1027
- mechanism that is primarily useful to to create open schemas, where
1028
- ` $dynamicRef ` defines the extension point and ` $dynamicAnchor ` defines the
1029
- target.
1016
+ The ` $dynamicRef ` keyword is an applicator that is used when the referencing
1017
+ schema might need to override where a reference in the referenced schema will
1018
+ resolve. This is useful for cases such as authoring a recursive schema that can
1019
+ be extended or a generic schema such as a list whose items are defined by the
1020
+ referencing schema.
1030
1021
1031
1022
The value of the ` $dynamicRef ` property MUST be formatted as a valid
1032
- [ IRI plain name fragment] ( #fragments ) .[ ^ 3 ]
1023
+ [ fragment-only IRI ] ( #fragments ) .[ ^ 3 ]
1033
1024
1034
- [ ^ 3 ] : ` $dynamicAnchor ` defines the anchor with plain text, e.g. ` foo ` . Although
1035
- the value of ` $dynamicRef ` is not an IRI fragment, for historical reasons, the
1036
- value still uses an IRI fragment syntax, e.g. ` #foo ` .
1025
+ [ ^ 3 ] : ` $dynamicAnchor ` defines the anchor with plain text, e.g. ` foo ` . Although,
1026
+ for historical reasons, the value of ` $dynamicRef ` still uses a fragment-only
1027
+ IRI syntax, e.g. ` #foo ` .
1037
1028
1038
- Resolution of ` $dynamicRef ` begins by identifying the outermost schema
1039
- resource in the [ dynamic scope] ( #scopes ) which defines a matching
1040
- ` $dynamicAnchor ` . The schema to apply is the subschema of this resource which
1041
- contains the matching ` $dynamicAnchor ` .
1029
+ Resolution of ` $dynamicRef ` begins by identifying the outermost schema resource
1030
+ in the [ dynamic scope] ( #scopes ) which defines a matching ` $dynamicAnchor ` . The
1031
+ schema to apply is the subschema of this resource which contains the matching
1032
+ ` $dynamicAnchor ` . If no matching ` $dynamicAnchor ` is found, see {{failed-refs}} .
1042
1033
1043
- For a full example using these keywords, see {{recursive -example}}.[ ^ 6 ]
1034
+ For a full example using these keywords, see {{dynamic -example}}.[ ^ 6 ]
1044
1035
1045
1036
[ ^ 6 ] : The differences in the hyper-schema meta-schemas from draft-07 and draft
1046
1037
2019-09 dramatically demonstrates the utility of these keywords.
@@ -1205,22 +1196,23 @@ If an implementation has been configured to resolve that identifier to a schema
1205
1196
via pre-loading or other means, it can be used automatically; otherwise, the
1206
1197
behavior described in {{failed-refs}} MUST be used.
1207
1198
1208
- #### JSON Pointer fragments and embedded schema resources {#embedded}
1199
+ #### JSON Pointer fragment identifiers and embedded schema resources {#embedded}
1209
1200
1210
- Since JSON Pointer IRI fragments are constructed based on the structure of the
1211
- schema document, an embedded schema resource and its subschemas can be
1212
- identified by JSON Pointer fragments relative to either its own canonical IRI,
1213
- or relative to any containing resource's IRI.
1201
+ Since JSON Pointer fragment identifiers are based on the structure of the schema
1202
+ document, an embedded schema resource and its subschemas can be identified using
1203
+ JSON Pointer IRI fragments relative to either its own IRI, or relative to any
1204
+ containing resource's IRI.
1214
1205
1215
1206
Conceptually, a set of linked schema resources should behave identically whether
1216
1207
each resource is a separate document connected with [ schema
1217
1208
references] ( #referenced ) , or is structured as a single document with one or more
1218
1209
schema resources embedded as subschemas.
1219
1210
1220
- Since IRIs involving JSON Pointer fragments relative to the parent schema
1221
- resource's IRI cease to be valid when the embedded schema is moved to a separate
1222
- document and referenced, applications and schemas SHOULD NOT use such IRIs to
1223
- identify embedded schema resources or locations within them.
1211
+ Since IRIs with JSON Pointer fragments are relative to the parent schema
1212
+ resource's IRI, they cease to be valid when the embedded schema is moved to a
1213
+ separate document and referenced. Because of this, applications and schemas
1214
+ SHOULD NOT use such IRIs to identify embedded schema resources or locations
1215
+ within them.
1224
1216
1225
1217
Consider the following schema document that contains another schema resource
1226
1218
embedded within it:
@@ -1244,7 +1236,7 @@ For the `additionalProperties` schema within that embedded resource, the IRI
1244
1236
object, but that object's IRI relative to its resource's canonical IRI is
1245
1237
` https://example.com/bar#/additionalProperties ` .
1246
1238
1247
- Now consider the following two schema resources linked by reference using a IRI
1239
+ Now consider the following two schema resources linked by reference using an IRI
1248
1240
value for ` $ref ` :
1249
1241
1250
1242
``` jsonschema
@@ -1264,10 +1256,11 @@ value for `$ref`:
1264
1256
```
1265
1257
1266
1258
Here we see that ` https://example.com/bar#/additionalProperties ` , using a JSON
1267
- Pointer fragment appended to the canonical IRI of the "bar" schema resource, is
1268
- still valid, while ` https://example.com/foo#/items/additionalProperties ` , which
1269
- relied on a JSON Pointer fragment appended to the canonical IRI of the "foo"
1270
- schema resource, no longer resolves to anything.
1259
+ Pointer fragment identifier appended to the canonical IRI of the "bar" schema
1260
+ resource, is still valid, while
1261
+ ` https://example.com/foo#/items/additionalProperties ` , which relied on a JSON
1262
+ Pointer fragment identifier appended to the canonical IRI of the "foo" schema
1263
+ resource, no longer resolves to anything.
1271
1264
1272
1265
Note also that ` https://example.com/foo#/items ` is valid in both arrangements,
1273
1266
but resolves to a different value. This IRI ends up functioning similarly to a
@@ -1282,14 +1275,15 @@ undefined. Schema authors SHOULD NOT rely on such IRIs, as using them may
1282
1275
reduce interoperability.[ ^ 8 ]
1283
1276
1284
1277
[ ^ 8 ] : This is to avoid requiring implementations to keep track of a whole stack
1285
- of possible base IRIs and JSON Pointer fragments for each, given that all but
1286
- one will be fragile if the schema resources are reorganized. Some have argued
1287
- that this is easy so there is no point in forbidding it, while others have
1288
- argued that it complicates schema identification and should be forbidden.
1289
- Feedback on this topic is encouraged. After some discussion, we feel that we
1290
- need to remove the use of "canonical" in favour of talking about JSON Pointers
1291
- which reference across schema resource boundaries as undefined or even forbidden
1292
- behavior (< https://github.com/json-schema-org/json-schema-spec/issues/937 > ,
1278
+ of possible base IRIs and JSON Pointer fragment identifiers for each, given
1279
+ that all but one will be fragile if the schema resources are reorganized. Some
1280
+ have argued that this is easy so there is no point in forbidding it, while
1281
+ others have argued that it complicates schema identification and should be
1282
+ forbidden. Feedback on this topic is encouraged. After some discussion, we feel
1283
+ that we need to remove the use of "canonical" in favour of talking about JSON
1284
+ Pointers which reference across schema resource boundaries as undefined or even
1285
+ forbidden behavior
1286
+ (< https://github.com/json-schema-org/json-schema-spec/issues/937 > ,
1293
1287
< https://github.com/json-schema-org/json-schema-spec/issues/1183 > )
1294
1288
1295
1289
Further examples of such non-canonical IRI construction, as well as the
@@ -1578,9 +1572,9 @@ subschema, then validation succeeds against this keyword if the instance also
1578
1572
successfully validates against this keyword's subschema.
1579
1573
1580
1574
This keyword has no effect when ` if ` is absent, or when the instance fails to
1581
- validate against the ` if ` subschema. Implementations MUST NOT evaluate the instance
1582
- against this keyword, for either validation or annotation collection purposes,
1583
- in such cases.
1575
+ validate against the ` if ` subschema. Implementations MUST NOT evaluate the
1576
+ instance against this keyword, for either validation or annotation collection
1577
+ purposes, in such cases.
1584
1578
1585
1579
##### ` else `
1586
1580
@@ -1591,8 +1585,8 @@ then validation succeeds against this keyword if the instance successfully
1591
1585
validates against this keyword's subschema.
1592
1586
1593
1587
This keyword has no effect when ` if ` is absent, or when the instance
1594
- successfully validates against the ` if ` subschema. Implementations MUST NOT evaluate
1595
- the instance against this keyword, for either validation or annotation
1588
+ successfully validates against the ` if ` subschema. Implementations MUST NOT
1589
+ evaluate the instance against this keyword, for either validation or annotation
1596
1590
collection purposes, in such cases.
1597
1591
1598
1592
##### ` dependentSchemas ` {#dependent-schemas}
@@ -1856,8 +1850,8 @@ Omitting this keyword has the same assertion behavior as an empty schema.
1856
1850
1857
1851
The value of ` unevaluatedProperties ` MUST be a valid JSON Schema.
1858
1852
1859
- This keyword applies to object instances by applying its subschema to the object's
1860
- property values.
1853
+ This keyword applies to object instances by applying its subschema to the
1854
+ object's property values.
1861
1855
1862
1856
The behavior of this keyword depends on all adjacent keywords as well as
1863
1857
keywords in successfully validated subschemas that apply to the same instance
@@ -1872,9 +1866,9 @@ subschema validates against all applicable property values.
1872
1866
The annotation result of this keyword is the set of instance property names
1873
1867
validated by this keyword's subschema.
1874
1868
1875
- The presence of this keyword affects the behavior of other ` unevaluatedProperties `
1876
- keywords found earlier in the dynamic scope that apply to the same instance
1877
- location.
1869
+ The presence of this keyword affects the behavior of other
1870
+ ` unevaluatedProperties ` keywords found earlier in the dynamic scope that apply
1871
+ to the same instance location.
1878
1872
1879
1873
Omitting this keyword has the same assertion behavior as an empty schema.
1880
1874
@@ -2115,7 +2109,8 @@ determines the canonical nature of the resulting full IRI.[^18]
2115
2109
and direct you to read the CREF located in {{embedded}} for further comments.
2116
2110
2117
2111
While the following IRIs do correctly indicate specific schemas, per the reasons
2118
- outlined in {{embedded}}, they are to be avoided as they may not work in all implementations:
2112
+ outlined in {{embedded}}, they are to be avoided as they may not work in all
2113
+ implementations:
2119
2114
2120
2115
Document location ` /$defs/B ` :
2121
2116
- canonical (and base) ` IRI: https://example.com/other.json `
@@ -2183,7 +2178,7 @@ scope of this specification to determine or provide a set of safe `$ref` removal
2183
2178
transformations, as they depend not only on the schema structure but also on the
2184
2179
intended usage.
2185
2180
2186
- ## %appendix% Example of recursive schema extension {#recursive -example}
2181
+ ## %appendix% Example of recursive schema extension {#dynamic -example}
2187
2182
2188
2183
Consider the following two schemas describing a simple recursive tree structure,
2189
2184
where each node in the tree can have a "data" field of any type. The first
@@ -2235,7 +2230,7 @@ the following full schema IRIs:
2235
2230
- ` https://example.com/strict-tree#node `
2236
2231
2237
2232
In addition, JSON Schema implementations keep track of the fact that these
2238
- fragments were created with ` $dynamicAnchor ` .
2233
+ fragment identifiers were created with ` $dynamicAnchor ` .
2239
2234
2240
2235
If we apply the "strict-tree" schema to the instance, we will follow the ` $ref `
2241
2236
to the "tree" schema, examine its "children" subschema, and find the
@@ -2253,25 +2248,25 @@ At this point, the evaluation path is
2253
2248
1 . ` https://example.com/tree#/properties/children `
2254
2249
1 . ` https://example.com/tree#/properties/children/items `
2255
2250
2256
- Since we are looking for a plain name fragment, which can be defined anywhere
2257
- within a schema resource, the JSON Pointer fragments are irrelevant to this
2258
- check. That means that we can remove those fragments and eliminate consecutive
2259
- duplicates, producing:
2251
+ Since we are looking for a plain name fragment identifier , which can be defined
2252
+ anywhere within a schema resource, the JSON Pointer IRI fragments are irrelevant
2253
+ to this check. That means that we can remove the fragments and eliminate
2254
+ consecutive duplicates, producing:
2260
2255
2261
2256
1 . ` https://example.com/strict-tree `
2262
2257
1 . ` https://example.com/tree `
2263
2258
2264
- In this case, the outermost resource also has a "node" fragment defined by
2265
- ` $dynamicAnchor ` . Therefore instead of resolving the ` $dynamicRef ` to
2259
+ In this case, the outermost resource also has a "node" fragment identifier
2260
+ defined by ` $dynamicAnchor ` . Therefore instead of resolving the ` $dynamicRef ` to
2266
2261
` https://example.com/tree#node ` , we resolve it to
2267
2262
` https://example.com/strict-tree#node ` .
2268
2263
2269
- This way, the recursion in the "tree" schema recurses to the root of
2270
- "strict-tree", instead of only applying "strict-tree" to the instance root, but
2271
- applying "tree" to instance children.
2264
+ The reference in the "tree" schema resolves to the root of "strict-tree", so
2265
+ "strict-tree" is applied not only to the tree instance's root, but also its
2266
+ children.
2272
2267
2273
2268
This example shows both ` $dynamicAnchor ` s in the same place in each schema,
2274
- specifically the resource root schema. Since plain-name fragments are
2269
+ specifically the resource root schema. Since plain-name fragment identifiers are
2275
2270
independent of the JSON structure, this would work just as well if one or both
2276
2271
of the node schema objects were moved under ` $defs ` . It is the matching
2277
2272
` $dynamicAnchor ` values which tell us how to resolve the dynamic reference, not
0 commit comments