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/id.markdown
+41-17Lines changed: 41 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,34 +29,58 @@ related:
29
29
keyword: $vocabulary
30
30
---
31
31
32
-
{{<learning-more>}}
33
-
Generally, `schema` and `schema resource` might create confusion. Let's clarify the terminology first:
34
-
35
-
**Schema**: This refers to the entire JSON boolean or JSON object passed to an evaluator.
32
+
The `$id` keyword explicitly turns a schema into a _schema resource_ (a schema
33
+
that is associated with a URI). Relative URIs are resolved against the
34
+
_current_ base URI, which is either the closest parent `$id` keyword
35
+
(applicable in the case of compound schemas) or the base URI as determined by
36
+
the context on which the schema is declared (i.e. serving a schema over HTTP
37
+
_may_ implicitly award it such URL as the base).
36
38
37
-
**Schema Resource**: A schema may consist of one or more schema resources (`$id` boundaries). When you introduce nested schema objects with `$id` in your schema, you create new schema resources.
39
+
Note that you cannot set this keyword to a URI that contains a fragment
40
+
identifier. Instead, fragment identifiers must be set with the [`$anchor`]({{<
41
+
ref "2020-12/core/anchor" >}}) keyword.
38
42
39
-
**Schema Object**: This is a single subschema in the schema tree, considering only its immediate keywords and not including nested subschemas.
43
+
{{<learning-more>}}
40
44
45
+
This keyword directly applies (without modifications or extensions) the concept
46
+
of URIs to schemas. **If you are having a hard time following the concepts
47
+
discussed in this page, it is probably because you don't have a strong grasp of
48
+
URIs yet** (a notably hard but universal pre-requisite!).
41
49
42
-
_Relationships_:
43
-
* A _schema_ has one or more schema resources.
44
-
* A _schema resource_ has one or more schema objects.
45
-
* A _schema object_ has one or more keywords.
50
+
To learn more about URIs, we strongly suggest studying the [IETF RFC
51
+
3986](https://www.rfc-editor.org/info/rfc3986) URI standard. To avoid
52
+
confusion, note that there is also a [WHATWG URL
53
+
Standard](https://url.spec.whatwg.org) that targets URLs in the context of web
54
+
browsers. However, JSON Schema only implements and expects the IETF original
55
+
standard.
46
56
47
-
_**Note**: A schema resource does not include its children schema resources, as they are conceptually distinct entities (just like html iframes in a web page), despite being nested. However, all of them are part of the same schema. Refer to the last example for clarification._
48
57
{{</learning-more>}}
49
58
50
-
The `$id` keyword declares the URI for a schema, usually set at the top level. However, any subschema has the flexibility to declare its own `$id` to distinguish itself with a distinct URI. Each subschema with an `$id` in a compound schema is called a _schema resource_.
59
+
{{<common-pitfall>}}
60
+
61
+
In JSON Schema, schema identifiers are merely identifiers and no behaviour is
62
+
imposed on them. In particular, JSON Schema does not guarantee that a schema
63
+
with an HTTP URL identifier is actually resolvable at such URL. To avoid
64
+
surprises, JSON Schema implementations must be careful with automatically
65
+
sending remote network requests when encountering supposely resolvable schema
66
+
identifiers.
67
+
68
+
{{</common-pitfall>}}
51
69
52
-
* The top-level schema resource is referred to as the root schema resource.
53
-
* The identifier of the root schema resource, if set, must be an absolute URI.
54
-
* The presence of an identifier sets a new base URI for such schema resource.
70
+
{{<best-practice>}}
55
71
56
-
It's worth noting that if the `$id` identifier is a URL, it's common for the URL to respond with the schema when accessed through a web browser, but this behavior is not mandatory; the URL primarily serves as an identifier. Additionally, for non-locatable URIs, such as those not intended for direct accessibility over the declared protocol (e.g., HTTPS), it is advisable to consider using URNs.
72
+
It is strongly recommended for every schema file to explicitly declare an
73
+
_absolute_ URI using this keyword. By doing so, you completely avoid various
74
+
complex URI resolution edge cases, mainly when the base URI is implicit and
75
+
context-dependent.
57
76
58
-
_**Note:** Check out the [URI RFC](https://datatracker.ietf.org/doc/html/rfc3986) to gain a deeper understanding of how resolution works, providing valuable insights into the essential role of URIs in JSON Schema._
77
+
If you are serving schemas over the network (i.e. over HTTP), a common practice
78
+
is to set this keyword to the expected URL. However, if your schemas are not
79
+
accessible over the network, prefer using a [URN (Uniform Resource
80
+
Name)](https://en.wikipedia.org/wiki/Uniform_Resource_Name) or a non-locatable
81
+
URI scheme such as a [Tag URI](https://www.taguri.org).
0 commit comments