Skip to content

Commit 1f2aae4

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 368d88f commit 1f2aae4

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
@@ -3414,6 +3414,57 @@ User-Agent: product-name/5.4.1 so-cool-json-schema/1.0.2 curl/7.43.0
34143414
</t>
34153415
</section>
34163416

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

0 commit comments

Comments
 (0)