Skip to content

Commit 440cf2e

Browse files
committed
Add guidance on bundling and references
This should make clear what use cases are considered valid and safe, vs when someone is on their own in terms of figuring that out.
1 parent d7ed9b1 commit 440cf2e

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

jsonschema-core.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3435,6 +3435,57 @@ User-Agent: product-name/5.4.1 so-cool-json-schema/1.0.2 curl/7.43.0
34353435
</t>
34363436
</section>
34373437

3438+
<section title="Manipulating schema documents and references">
3439+
<t>
3440+
Various tools have been created to rearrange schema documents
3441+
based on how and where references ("$ref") appear. This appendix discusses
3442+
which use cases and actions are compliant with this specification.
3443+
</t>
3444+
<section title="Bundling schema resources into a single document">
3445+
<t>
3446+
A set of schema resources intended for use together can be organized
3447+
with each in its own schema document, all in the same schema document,
3448+
or any granularity of document grouping in between.
3449+
</t>
3450+
<t>
3451+
Numerous tools exist to perform various sorts of reference removal.
3452+
A common case of this is producing a single file where all references
3453+
can be resolved within that file. This is typically done to simplify
3454+
distribution, or to simplify coding so that various invocations
3455+
of JSON Schema libraries do not have to keep track of and load
3456+
a large number of resources.
3457+
</t>
3458+
<t>
3459+
This transformation can be safely and reversibly done as long as
3460+
all static references (e.g. "$ref") use URI-references that resolve
3461+
to canonical URIs, and all schema resources have an absolute-URI
3462+
as the "$id" in their root schema.
3463+
</t>
3464+
<t>
3465+
With these conditions met, each external resource can be copied
3466+
under "$defs", without breaking any references among the resources'
3467+
schema objects, and without changing any aspect of validation or
3468+
annotation results. The names of the schemas under "$defs" do
3469+
not affect behavior, assuming they are each unique, as they
3470+
do not appear in canonical URIs for the embedded resources.
3471+
</t>
3472+
</section>
3473+
<section title="Reference removal is not always safe">
3474+
<t>
3475+
Attempting to remove all references and produce a single schema document does not,
3476+
in all cases, produce a schema with identical behavior to the original form.
3477+
</t>
3478+
<t>
3479+
Since "$ref" is now treated like any other keyword, with other keywords allowed
3480+
in the same schema objects, fully supporting non-recursive "$ref" removal in
3481+
all cases can require relatively complex schema manipulations. It is beyond
3482+
the scope of this specification to determine or provide a set of safe "$ref"
3483+
removal transformations, as they depend not only on the schema structure
3484+
but also on the intende usage.
3485+
</t>
3486+
</section>
3487+
</section>
3488+
34383489
<section title="Working with vocabularies">
34393490
<section title="Best practices for vocabulary and meta-schema authors">
34403491
<t>

0 commit comments

Comments
 (0)