Skip to content

Commit 11cb49d

Browse files
authored
Merge pull request #1537 from json-schema-org/gregsdennis/id-updates
`$id` updates
2 parents 08943f7 + b64d297 commit 11cb49d

File tree

2 files changed

+94
-91
lines changed

2 files changed

+94
-91
lines changed

jsonschema-core.md

+93-90
Original file line numberDiff line numberDiff line change
@@ -452,8 +452,8 @@ The lexical scope of a keyword is determined by the nested JSON data structure
452452
of objects and arrays. The largest such scope is an entire schema document. The
453453
smallest scope is a single schema object with no subschemas.
454454

455-
Keywords MAY be defined with a partial value, such as a IRI-reference, which
456-
must be resolved against another value, such as another IRI-reference or a full
455+
Keywords MAY be defined with a partial value, such as a IRI reference, which
456+
must be resolved against another value, such as another IRI reference or a full
457457
IRI, which is found through the lexical structure of the JSON document. The
458458
`$id`, `$ref`, and `$dynamicRef` core keywords, and the "base" JSON Hyper-Schema
459459
keyword, are examples of this sort of behavior.
@@ -542,7 +542,7 @@ Identifiers define IRIs for a schema, or affect how such IRIs are resolved in
542542
keywords, most notably `$id`.
543543

544544
Canonical schema IRIs MUST NOT change while processing an instance, but keywords
545-
that affect IRI-reference resolution MAY have behavior that is only fully
545+
that affect IRI reference resolution MAY have behavior that is only fully
546546
determined at runtime.
547547

548548
While custom identifier keywords are possible, extension designers should take
@@ -894,50 +894,45 @@ by other parties.
894894

895895
### Base IRI, Anchors, and Dereferencing
896896

897-
To differentiate between schemas in a vast ecosystem, schemas are identified by
898-
[IRI](#rfc3987), and can embed references to other schemas by specifying their
899-
IRI.
897+
To differentiate between schemas in a vast ecosystem, schema resources are
898+
identified by [absolute IRIs](#rfc3987) (without fragments). These identifiers
899+
are used to create references between schema resources. When comparing IRIs for
900+
the purposes of resource identification, implementations SHOULD first follow the
901+
IRI normalization procedures defined in [RFC 3987](#rfc3987), section 5.3.
900902

901-
Several keywords can accept a relative [IRI-reference](#rfc3987), or a value
902-
used to construct a relative IRI-reference. For these keywords, it is necessary
903+
Several keywords can accept a relative [IRI reference](#rfc3987), or a value
904+
used to construct a relative IRI reference. For these keywords, it is necessary
903905
to establish a base IRI in order to resolve the reference.
904906

905907
#### The `$id` Keyword {#id-keyword}
906908

907-
The `$id` keyword identifies a schema resource with its [canonical](#rfc6596)
908-
IRI.
909+
An `$id` keyword in a schema or subschema identifies that schema or subschema as
910+
a distinct schema resource. The value for this keyword MUST be a string, and
911+
MUST represent a valid [IRI reference](#rfc3987) without a fragment.
912+
913+
When the value of this keyword is resolved against the current base IRI, the
914+
resulting absolute IRI then serves as the identifier for the schema resource and
915+
as a base IRI for relative IRI references in keywords within that schema
916+
resource and for embedded schema resources, in accordance with [RFC 3987 section
917+
6.5](#rfc3987) and [RFC 3986 section 5.1.1](#rfc3986) regarding base IRIs
918+
embedded in content and RFC 3986 section 5.1.2 regarding encapsulating entities.
909919

910920
Note that this IRI is an identifier and not necessarily a network locator. In
911921
the case of a network-addressable URL, a schema need not be downloadable from
912922
its canonical IRI.
913923

914-
If present, the value for this keyword MUST be a string, and MUST represent a
915-
valid [IRI-reference](#rfc3987). This IRI-reference SHOULD be normalized, and
916-
MUST resolve to an [absolute-IRI](#rfc3987) (without a fragment).
917-
918-
The resulting absolute-IRI serves as the base IRI for relative IRI-references in
919-
keywords within the schema resource, in accordance with [RFC 3987 section
920-
6.5](#rfc3987) and [RFC 3986 section 5.1.1](#rfc3986) regarding base IRIs
921-
embedded in content.
922-
923-
The presence of `$id` in a subschema indicates that the subschema constitutes a
924-
distinct schema resource within a single schema document. Furthermore, in
925-
accordance with [RFC 3987 section 6.5](#rfc3987) and [RFC 3986 section
926-
5.1.2](#rfc3986) regarding encapsulating entities, if an `$id` in a subschema is
927-
a relative IRI-reference, the base IRI for resolving that reference is the IRI
928-
of the parent schema resource. Note that an `$id` consisting of an empty IRI or
929-
of the empty fragment only will result in the embedded resource having the same
930-
IRI as the encapsulating resource, which SHOULD be considered an error per
931-
{{duplicate-iris}}.
924+
Also note that an `$id` consisting of an empty IRI only will result in the
925+
embedded resource having the same IRI as the encapsulating resource, which
926+
SHOULD be considered an error per {{duplicate-iris}}.
932927

933928
If no parent schema object explicitly identifies itself as a resource with
934929
`$id`, the base IRI is that of the entire document, as established by the steps
935-
given in the [previous section.](initial-base)
930+
given in {{initial-base}}.
936931

937932
##### Identifying the root schema
938933

939934
The root schema of a JSON Schema document SHOULD contain an `$id` keyword with
940-
an [absolute-IRI](#rfc3987) (containing a scheme, but no fragment).
935+
an [absolute IRI](#rfc3987) (containing a scheme, but no fragment).
941936

942937
#### Defining location-independent identifiers {#anchors}
943938

@@ -971,7 +966,7 @@ If present, the value of these keywords MUST be a string and MUST conform to the
971966
plain name fragment identifier syntax defined in {{fragments}}.[^4]
972967

973968
[^4]: Note that the anchor string does not include the "#" character, as it is
974-
not a IRI-reference. An `$anchor`: "foo" becomes the fragment `#foo` when used
969+
not a IRI reference. An `$anchor`: "foo" becomes the fragment `#foo` when used
975970
in a IRI. See below for full examples.
976971

977972
#### Duplicate schema identifiers {#duplicate-iris}
@@ -1005,7 +1000,7 @@ identified schema. Its results are the results of the referenced schema.[^5]
10051000
[^5]: Note that this definition of how the results are determined means that
10061001
other keywords can appear alongside of `$ref` in the same schema object.
10071002

1008-
The value of the `$ref` keyword MUST be a string which is a IRI-Reference.
1003+
The value of the `$ref` keyword MUST be a string which is a IRI reference.
10091004
Resolved against the current IRI base, it produces the IRI of the schema to
10101005
apply. This resolution is safe to perform on schema load, as the process of
10111006
evaluating an instance cannot change how the reference resolves.
@@ -1022,7 +1017,7 @@ reference themselves). The extension point is defined with `$dynamicAnchor` and
10221017
only exhibits runtime dynamic behavior when referenced with `$dynamicRef`.
10231018

10241019
The value of the `$dynamicRef` property MUST be a string which is a
1025-
IRI-Reference that contains a valid [plain name fragment](#anchors). Resolved
1020+
IRI reference that contains a valid [plain name fragment](#anchors). Resolved
10261021
against the current IRI base, it indicates the schema resource used as the
10271022
starting point for runtime resolution. This initial resolution is safe to
10281023
perform on schema load.
@@ -1190,15 +1185,9 @@ automatically.
11901185

11911186
When an implementation encounters the reference to "other.json", it resolves
11921187
this to `https://example.net/other.json`, which is not defined in this document.
1193-
If a schema with that identifier has otherwise been supplied to the
1194-
implementation, it can also be used automatically.[^7]
1195-
1196-
[^7]: What should implementations do when the referenced schema is not known?
1197-
Are there circumstances in which automatic network dereferencing is allowed? A
1198-
same origin policy? A user-configurable option? In the case of an evolving API
1199-
described by Hyper-Schema, it is expected that new schemas will be added to the
1200-
system dynamically, so placing an absolute requirement of pre-loading schema
1201-
documents is not feasible.
1188+
If an implementation has been configured to resolve that identifier to a schema
1189+
via pre-loading or other means, it can be used automatically; otherwise, the
1190+
behavior described in {{failed-refs}} MUST be used.
12021191

12031192
#### JSON Pointer fragments and embedded schema resources {#embedded}
12041193

@@ -1271,10 +1260,10 @@ the `$id` of the embedded or referenced resource unless it is specifically
12711260
desired to identify the object containing the `$ref` in the second
12721261
(non-embedded) arrangement.
12731262

1274-
An implementation MAY choose not to support addressing schema resource contents
1275-
by IRIs using a base other than the resource's canonical IRI, plus a JSON
1276-
Pointer fragment relative to that base. Therefore, schema authors SHOULD NOT
1277-
rely on such IRIs, as using them may reduce interoperability.[^8]
1263+
Due to the potential break in functionality described above, the behavior for
1264+
using JSON Pointer fragments that point to or cross a resource boundary is
1265+
undefined. Schema authors SHOULD NOT rely on such IRIs, as using them may
1266+
reduce interoperability.[^8]
12781267

12791268
[^8]: This is to avoid requiring implementations to keep track of a whole stack
12801269
of possible base IRIs and JSON Pointer fragments for each, given that all but
@@ -1318,7 +1307,7 @@ When the Schema Resource referenced by a by-reference applicator is bundled, it
13181307
is RECOMMENDED that the Schema Resource be located as a value of a `$defs`
13191308
object at the containing schema's root. The key of the `$defs` for the now
13201309
embedded Schema Resource MAY be the `$id` of the bundled schema or some other
1321-
form of application defined unique identifer (such as a UUID). This key is not
1310+
form of application defined unique identifier (such as a UUID). This key is not
13221311
intended to be referenced in JSON Schema, but may be used by an application to
13231312
aid the bundling process.
13241313

@@ -1381,18 +1370,15 @@ recursive nesting like this; the behavior is undefined.
13811370
#### References to Possible Non-Schemas {#non-schemas}
13821371

13831372
Subschema objects (or booleans) are recognized by their use with known
1384-
applicator keywords or with location-reserving keywords such as
1385-
[`$defs`](#defs) that take one or more subschemas as a value. These keywords may
1386-
be `$defs` and the standard applicators from this document or
1387-
implementation-specific custom keywords.
1388-
1389-
Multi-level structures of unknown keywords are capable of introducing nested
1390-
subschemas, which would be subject to the processing rules for `$id`. Therefore,
1391-
having a reference target in such an unrecognized structure cannot be reliably
1392-
implemented, and the resulting behavior is undefined. Similarly, a reference
1393-
target under a known keyword, for which the value is known not to be a schema,
1394-
results in undefined behavior in order to avoid burdening implementations with
1395-
the need to detect such targets.[^10]
1373+
applicator keywords or with location-reserving keywords, such as
1374+
[`$defs`](#defs), that take one or more subschemas as a value. These keywords
1375+
include the standard applicators from this document or implementation-specific
1376+
custom keywords.
1377+
1378+
A reference target under a keyword for which the value is not explicitly known
1379+
to be a schema results in undefined behavior. Implementations MAY support
1380+
references to these locations, however such behavior is not considered
1381+
interoperable and should not be relied upon.[^10]
13961382

13971383
[^10]: These scenarios are analogous to fetching a schema over HTTP but
13981384
receiving a response with a Content-Type other than `application/schema+json`.
@@ -1401,13 +1387,7 @@ server offered no guarantee that it actually is any such thing. Therefore,
14011387
interpreting it as such has security implication and may produce unpredictable
14021388
results.
14031389

1404-
Note that single-level custom keywords with identical syntax and semantics to
1405-
`$defs` do not allow for any intervening `$id` keywords, and therefore will
1406-
behave correctly under implementations that attempt to use any reference target
1407-
as a schema. However, this behavior is implementation-specific and MUST NOT be
1408-
relied upon for interoperability.
1409-
1410-
#### Failure to resolve references
1390+
#### Failure to resolve references {#failed-refs}
14111391

14121392
If for any reason a reference cannot be resolved, the evaluation MUST halt and
14131393
return an indeterminant result. Specifically, it MUST NOT return a passing or
@@ -2214,56 +2194,79 @@ name fragment identifiers.
22142194
}
22152195
```
22162196

2217-
The schemas at the following IRI-encoded [JSON Pointers](#rfc6901) (relative to
2218-
the root schema) have the following base IRIs, and are identifiable by any
2219-
listed IRI in accordance with {{fragments}} and {{embedded}} above.
2197+
The schemas at the following locations (indicated by plain
2198+
[JSON Pointers](#rfc6901) relative to the root document) have the following base
2199+
IRIs, and are identifiable by any listed IRI in accordance with {{fragments}}
2200+
and {{embedded}} above.
22202201

2221-
`#` (document root): canonical (and base) IRI: `https://example.com/root.json`
2202+
Document root:
2203+
- canonical (and base) IRI: `https://example.com/root.json`
22222204
- canonical resource IRI plus pointer fragment: `https://example.com/root.json#`
22232205

2224-
`#/$defs/A`: base IRI: `https://example.com/root.json`
2206+
Document location `/$defs/A`:
2207+
- base IRI: `https://example.com/root.json`
22252208
- canonical resource IRI plus plain fragment:
22262209
`https://example.com/root.json#foo`
22272210
- canonical resource IRI plus pointer fragment:
22282211
`https://example.com/root.json#/$defs/A`
22292212

2230-
`#/$defs/B`: canonical (and base) `IRI: https://example.com/other.json`
2213+
Document location `/$defs/B`:
2214+
- canonical (and base) `IRI: https://example.com/other.json`
22312215
- canonical resource IRI plus pointer fragment:
22322216
`https://example.com/other.json#`
2233-
- base IRI of enclosing (root.json) resource plus fragment:
2234-
`https://example.com/root.json#/$defs/B`
22352217

2236-
`#/$defs/B/$defs/X`: base IRI: `https://example.com/other.json`
2218+
Document location `/$defs/B/$defs/X`:
2219+
- base IRI: `https://example.com/other.json`
22372220
- canonical resource IRI plus plain fragment:
22382221
`https://example.com/other.json#bar`
22392222
- canonical resource IRI plus pointer fragment:
22402223
`https://example.com/other.json#/$defs/X`
2241-
- base IRI of enclosing (root.json) resource plus fragment:
2242-
`https://example.com/root.json#/$defs/B/$defs/X`
22432224

2244-
`#/$defs/B/$defs/Y`: canonical (and base) IRI:
2225+
Document location `/$defs/B/$defs/Y`:
2226+
- canonical (and base) IRI:
22452227
`https://example.com/t/inner.json`
22462228
- canonical IRI plus plain fragment: `https://example.com/t/inner.json#bar`
22472229
- canonical IRI plus pointer fragment: `https://example.com/t/inner.json#`
2248-
- base IRI of enclosing (other.json) resource plus fragment:
2249-
`https://example.com/other.json#/$defs/Y`
2250-
- base IRI of enclosing (root.json) resource plus fragment:
2251-
`https://example.com/root.json#/$defs/B/$defs/Y`
22522230

2253-
`#/$defs/C`: canonical (and base) IRI:
2231+
Document location `/$defs/C`:
2232+
- canonical (and base) IRI:
22542233
`urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f`
22552234
- canonical IRI plus pointer fragment:
22562235
`urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f#`
2257-
- base IRI of enclosing (root.json) resource plus fragment:
2258-
`https://example.com/root.json#/$defs/C`
22592236

22602237
Note: The fragment part of the IRI does not make it canonical or non-canonical,
22612238
rather, the base IRI used (as part of the full IRI with any fragment) is what
22622239
determines the canonical nature of the resulting full IRI.[^18]
22632240

22642241
[^18]: Multiple "canonical" IRIs? We Acknowledge this is potentially confusing,
2265-
and direct you to read the CREF located in the [JSON Pointer fragments and
2266-
embedded schema resources](#embedded) section for further comments.
2242+
and direct you to read the CREF located in {{embedded}} for further comments.
2243+
2244+
While the following IRIs do correctly indicate specific schemas, per the reasons
2245+
outlined in {{embedded}}, they are to be avoided as they may not work in all implementations:
2246+
2247+
Document location `/$defs/B`:
2248+
- canonical (and base) `IRI: https://example.com/other.json`
2249+
- base IRI of enclosing (root.json) resource plus fragment:
2250+
`https://example.com/root.json#/$defs/B`
2251+
2252+
Document location `/$defs/B/$defs/X`:
2253+
- base IRI: `https://example.com/other.json`
2254+
- base IRI of enclosing (root.json) resource plus fragment:
2255+
`https://example.com/root.json#/$defs/B/$defs/X`
2256+
2257+
Document location `/$defs/B/$defs/Y`:
2258+
- canonical (and base) IRI:
2259+
`https://example.com/t/inner.json`
2260+
- base IRI of enclosing (other.json) resource plus fragment:
2261+
`https://example.com/other.json#/$defs/Y`
2262+
- base IRI of enclosing (root.json) resource plus fragment:
2263+
`https://example.com/root.json#/$defs/B/$defs/Y`
2264+
2265+
Document location `/$defs/C`:
2266+
- canonical (and base) IRI:
2267+
`urn:uuid:ee564b8a-7a87-4125-8c96-e9f123d6766f`
2268+
- base IRI of enclosing (root.json) resource plus fragment:
2269+
`https://example.com/root.json#/$defs/C`
22672270

22682271
## [Appendix] Manipulating schema documents and references
22692272

@@ -2284,9 +2287,9 @@ simplify coding so that various invocations of JSON Schema libraries do not have
22842287
to keep track of and load a large number of resources.
22852288

22862289
This transformation can be safely and reversibly done as long as all static
2287-
references (e.g. `$ref`) use IRI-references that resolve to IRIs using the
2290+
references (e.g. `$ref`) use IRI references that resolve to IRIs using the
22882291
canonical resource IRI as the base, and all schema resources have an
2289-
absolute-IRI as the `$id` in their root schema.
2292+
absolute IRI as the `$id` in their root schema.
22902293

22912294
With these conditions met, each external resource can be copied under `$defs`,
22922295
without breaking any references among the resources' schema objects, and without
@@ -2470,7 +2473,7 @@ to the document.
24702473
- Clarify that detecting duplicate IRIs for different schemas SHOULD raise an
24712474
error
24722475
- Consolidate and clarify the syntax and rationale for plain-name fragments
2473-
- "$id" MUST be an absolute-IRI, without any fragment, even an empty one
2476+
- "$id" MUST be an absolute IRI, without any fragment, even an empty one
24742477
- Note that an empty string "$id" results in duplicate IRIs for different
24752478
schemas
24762479
- Define empty schemas as empty (no longer allowing unrecognized keywords)

jsonschema-validation.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ The value of this property MUST be a valid JSON schema. It SHOULD be ignored if
563563
location IRI included as part of the annotation will ensure that it is correctly
564564
processed as a subschema. Using the extracted annotation value directly is only
565565
safe if the schema is an embedded resource with both `$schema` and an
566-
absolute-IRI `$id`.
566+
absolute IRI `$id`.
567567

568568
### Example
569569

0 commit comments

Comments
 (0)