From ff02e882ba0075144209c5cdd495f556c2425e3e Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Sat, 24 Aug 2019 00:15:24 -0700 Subject: [PATCH] More consistent concept of schema resources This further clarifies the schema resource concept and how it is used. In particular, schema resources are crucial to determining when it is safe to embed a reference target into its referring schema. This also requires allowing "$ref" to take a schema value. The bundling use case should be more clear given this guidance. While many reference target embedding transformations are likely to break things and are therefor to be discouraged, when framed in terms of schema resources a clear use case emerges. This also relaxes a restriction on "$schema" that has no functional impact but avoids requiring implementations to detect and handle a rather complex case (embedding schema resources with different "$schema" values). And also means that embedding can work without having to change the embedded value by removing the "$schema" keyword. --- jsonschema-core.xml | 151 +++++++++++++++++++++++++++++++------------- 1 file changed, 108 insertions(+), 43 deletions(-) diff --git a/jsonschema-core.xml b/jsonschema-core.xml index e292e275..bfe5a8e9 100644 --- a/jsonschema-core.xml +++ b/jsonschema-core.xml @@ -100,7 +100,7 @@ This specification defines JSON Schema core terminology and mechanisms, including pointing to another JSON Schema by reference, - dereferencing a JSON Schema reference, + dereferencing a JSON Schema reference or embedding its target, specifying the vocabulary being used, and defining the expected output. @@ -409,11 +409,6 @@ canonically identified by an absolute URI. - - As discussed in section - , a JSON Schema document - can contain multiple JSON Schema resources. - The root schema is the schema that comprises the entire JSON document in question. The root schema is always a schema resource, where the @@ -442,6 +437,15 @@ As with the root schema, a subschema is either an object or a boolean. + + As discussed in section + , a JSON Schema document + can contain multiple JSON Schema resources. When used without qualification, + the term "root schema" refers to the document's root schema. In some + cases, resource root schemas are discussed. A resource's root schema + is its top-level schema object, which would also be a document root schema + if the resource were to be extracted to a standalone JSON Schema document. + @@ -624,7 +628,7 @@ Note that some keywords, such as "$schema", apply to the lexical scope of the entire schema document, and therefore MUST only - appear in the document's root schema. + appear in a schema resource's root schema. Other keywords may take into account the dynamic scope that @@ -1131,11 +1135,15 @@ media type "application/schema+json". - The "$schema" keyword SHOULD be used in a root schema. - It MUST NOT appear in subschemas. If absent from the root schema, the + The "$schema" keyword SHOULD be used in a resource root schema. + It MUST NOT appear in resource subschemas. If absent from the root schema, the resulting behavior is implementation-defined. + If multiple schema resources are present in a single document, then all + schema resources SHOULD Have the same value for "$schema". The result of + differing values for "$schema" within the same schema document is + implementation-defined. Using multiple "$schema" keywords in the same document would imply that the feature set and therefore behavior can change within a document. This would @@ -1145,6 +1153,12 @@ implementation behavior is subject to be revised or liberalized in future drafts. + + The exception made for embedded schema resources is to + allow bundling multiple schema resources into a single schema document + without needing to change their contents, as described later in this + specification. +