@@ -39,7 +39,7 @@ be created out of simpler ones. A reference may set its URI fragment to a [JSON
39
39
Pointer] ( https://www.rfc-editor.org/rfc/rfc6901 ) that determines the
40
40
destination of the reference after first resolving the rest of the URI.
41
41
42
- {{<common-pitfall >}}
42
+ {{<common-pitfall >}}
43
43
44
44
** Avoid referencing other schema files using their file paths** . While some
45
45
implementations support this by automatically constructing schema URIs that
@@ -48,9 +48,9 @@ standard and guaranteed mechanism of declaring a schema URI for identification
48
48
and referencing purposes is through the [ ` $id ` ] ({{< ref "2020-12/core/id" >}})
49
49
keyword.
50
50
51
- {{</common-pitfall >}}
51
+ {{</common-pitfall >}}
52
52
53
- {{<common-pitfall >}}
53
+ {{<common-pitfall >}}
54
54
55
55
The target of a reference must be a schema. Referencing a JSON value that is
56
56
not unambiguously recognised as a schema leads to undefined behaviour. This
@@ -59,7 +59,7 @@ referencing parts of a schema that a JSON Schema evaluator does not consider to
59
59
be a subschema. For example, referencing the contents of the [ ` examples ` ] ({{<
60
60
ref "2020-12/meta-data/examples" >}}) keyword.
61
61
62
- {{</common-pitfall >}}
62
+ {{</common-pitfall >}}
63
63
64
64
References are either _ internal_ (pointing at schemas within the same schema
65
65
definition) or _ external_ (pointing at schema resources outside the given
@@ -71,19 +71,19 @@ are notable examples of the latter. A relative reference from a schema embedded
71
71
in an OpenAPI specification is resolved from the root of the API specification,
72
72
and not from the root of the schema.
73
73
74
- {{<best-practice >}}
74
+ {{<best-practice >}}
75
75
76
76
It is highly recommended to make use of _ external_ references to break down
77
77
complex monolithic schemas into smaller schema files. However, for performance
78
78
and integrity reasons, avoid resolving these external schemas (i.e. over HTTP
79
- or the filesystem) at runtime.
79
+ or the filesystem) at runtime.
80
80
81
81
You can automatically inline external references at build time using the
82
82
[ `jsonschema
83
83
bundle`] ( https://github.com/sourcemeta/jsonschema/blob/main/docs/bundle.markdown )
84
84
command.
85
85
86
- {{</best-practice >}}
86
+ {{</best-practice >}}
87
87
88
88
Note that a reference to an absolute URI does not necessarily mean that the
89
89
reference is external. Conversely, a reference to a relative URI does not
@@ -97,7 +97,7 @@ is considered internal. This internal-first lookup is what enables the standard
97
97
] ( https://json-schema.org/blog/posts/bundling-json-schema-compound-documents )
98
98
process.
99
99
100
- {{<learning-more >}}
100
+ {{<learning-more >}}
101
101
102
102
If you are having a hard time understanding references and some of its more
103
103
subtle scenarios (like base URI resolution), it is probably because you don't
@@ -116,8 +116,8 @@ representation](https://www.rfc-editor.org/rfc/rfc6901#section-6).
116
116
117
117
{{</learning-more >}}
118
118
119
- To debug references and how JSON Schema is interpreting your specific relative
120
- URIs, try the [ `jsonschema
119
+ To debug references and how JSON Schema is interpreting your relative URIs, try
120
+ the [ `jsonschema
121
121
inspect`] ( https://github.com/sourcemeta/jsonschema/blob/main/docs/inspect.markdown )
122
122
command. This command prints detailed information about each schema reference
123
123
and of each location of the schema. For example:
@@ -142,22 +142,22 @@ $ jsonschema inspect schema.json
142
142
"$schema": "https://json-schema.org/draft/2020-12/schema ",
143
143
"$id": "https://example.com/my-schema ",
144
144
"properties": {
145
- "byRelativeFragmentPointer": {
145
+ "byRelativeFragmentPointer": {
146
146
"$ref": "#/$defs/helper"
147
147
},
148
- "byAbsoluteFragmentPointer": {
148
+ "byAbsoluteFragmentPointer": {
149
149
"$ref": "https://example.com/my-schema#/$defs/helper "
150
150
},
151
- "byRelativeURI": {
151
+ "byRelativeURI": {
152
152
"$ref": "my-helper"
153
153
},
154
- "byRelativeRootPathURI": {
154
+ "byRelativeRootPathURI": {
155
155
"$ref": "/my-helper"
156
156
},
157
- "byRelativeBackslashURI": {
157
+ "byRelativeBackslashURI": {
158
158
"$ref": "my-schema/../my-helper"
159
159
},
160
- "byAbsoluteURI": {
160
+ "byAbsoluteURI": {
161
161
"$ref": "https://example.com/my-helper "
162
162
}
163
163
},
@@ -175,16 +175,16 @@ $ jsonschema inspect schema.json
175
175
"$schema": "https://json-schema.org/draft/2020-12/schema ",
176
176
"$id": "https://example.com/my-schema ",
177
177
"properties": {
178
- "byAbsoluteURI": {
178
+ "byAbsoluteURI": {
179
179
"$ref": "https://example.com/my-other-schema "
180
180
},
181
- "byRelativeURI": {
181
+ "byRelativeURI": {
182
182
"$ref": "my-other-schema"
183
183
},
184
- "byRelativeRootPathURI": {
184
+ "byRelativeRootPathURI": {
185
185
"$ref": "/my-other-schema"
186
186
},
187
- "byRelativeBackslashURI": {
187
+ "byRelativeBackslashURI": {
188
188
"$ref": "my-schema/../my-other-schema"
189
189
}
190
190
}
@@ -195,7 +195,7 @@ $ jsonschema inspect schema.json
195
195
{
196
196
"$schema": "https://json-schema.org/draft/2020-12/schema ",
197
197
"properties": {
198
- "byAbsoluteURI": {
198
+ "byAbsoluteURI": {
199
199
"$ref": "urn:example: my-other-schema "
200
200
}
201
201
}
0 commit comments