From 6f33e918e29d785b42d123c4a0eacc7bf315916e Mon Sep 17 00:00:00 2001 From: Henry Andrews Date: Tue, 29 Nov 2016 12:15:18 -0800 Subject: [PATCH 1/2] Allow boolean schemas everywhere, including root This is an option for implementing issue #101, this time not just for subschemas but for all schemas including the root schema. The meta-schema changes will be added after PR #168 is approved, at which point the changes for this will be much simpler. --- jsonschema-core.xml | 35 +++++++++++++++++++++++++++++++---- jsonschema-validation.xml | 20 ++++++++------------ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/jsonschema-core.xml b/jsonschema-core.xml index f387940c..d4905e11 100644 --- a/jsonschema-core.xml +++ b/jsonschema-core.xml @@ -185,12 +185,34 @@ -
+
A JSON Schema document, or simply a schema, is a JSON document used to describe an instance. A schema is itself interpreted as an instance. - A JSON schema MUST be an object. + A JSON Schema MUST be an object or a boolean, where boolean values are equivalent to object schemas as follows. +
+ + true: + + + + +
+
+ + false: + + + + +
Properties that are used to describe the instance are called keywords, or schema keywords. The meaning of properties is specified by the vocabulary that the schema is using. @@ -231,6 +253,9 @@ In this example document, the schema titled "array item" is a subschema, and the schema titled "root" is the root schema. + + As with the root schema, a subschema MUST be an object or a boolean. +
@@ -299,7 +324,8 @@
- Any time a subschema is expected, a schema may instead use an object containing a "$ref" property. + In addition to a boolean value or an object using schema kewyords defined + in the meta-schema, a schema may be represnted by an object containing a "$ref" property. The value of the $ref is a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use. All other properties in a "$ref" object MUST be ignored. @@ -323,7 +349,7 @@ RFC3986 Section 5.1 defines how to determine the default base URI of a document. - Informatively, the initial base URI of a schema is the URI it was found at, or a suitable substitute URI if none is known. + Informatively, the initial base URI of a schema is the URI at which it was found, or a suitable substitute URI if none is known.
@@ -660,6 +686,7 @@ User-Agent: so-cool-json-schema/1.0.2 curl/7.43.0 Updated intro + Allowed for any schema to be a boolean diff --git a/jsonschema-validation.xml b/jsonschema-validation.xml index 7bbd6c70..637051df 100644 --- a/jsonschema-validation.xml +++ b/jsonschema-validation.xml @@ -327,8 +327,7 @@
- The value of "items" MUST be either an object or an array of objects. - Each object MUST be a valid JSON Schema. + The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas. If absent, it can be considered present with an empty schema. @@ -350,8 +349,7 @@
- The value of "additionalItems" MUST be a boolean or an object. - If it is an object, the object MUST be a valid JSON Schema. + The value of "additionalItems" MUST be a valid JSON Schema. If absent, it can be considered present with an empty schema. @@ -466,7 +464,7 @@
The value of "properties" MUST be an object. Each value of this object - MUST be an object, and each object MUST be a valid JSON Schema. + MUST be a valid JSON Schema. If absent, it can be considered the same as an empty object. @@ -487,7 +485,7 @@ The value of "patternProperties" MUST be an object. Each property name of this object SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. Each property value of this object - MUST be an object, and each object MUST be a valid JSON Schema. + MUST be a valid JSON Schema. If absent, it can be considered the same as an empty object. @@ -506,8 +504,7 @@
- The value of "additionalProperties" MUST be a boolean or an - object. If it is an object, the object MUST be a valid JSON Schema. + The value of "additionalProperties" MUST be a valid JSON Schema. If "additionalProperties" is absent, it may be considered present with @@ -535,12 +532,11 @@ This keyword's value MUST be an object. Each property specifies a dependency. - Each dependency value MUST be an object or an array. + Each dependency value MUST be an array or a valid JSON Schema. - If the dependency value is an object, it MUST be a valid JSON Schema. If the - dependency key is a property in the instance, the dependency value must validate - against the entire instance. + If the dependency value is a subschema, and the dependency key is a property + in the instance, the entire instance must validate against the dependency value. If the dependency value is an array, each element in the array, From b414be80ddcb008689c0ed6976635a1b0239d711 Mon Sep 17 00:00:00 2001 From: Austin Wright Date: Tue, 29 Nov 2016 21:55:07 -0700 Subject: [PATCH 2/2] Core: Updates on boolean schema and $ref behavior --- jsonschema-core.xml | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/jsonschema-core.xml b/jsonschema-core.xml index d4905e11..75eecd4a 100644 --- a/jsonschema-core.xml +++ b/jsonschema-core.xml @@ -189,30 +189,15 @@ A JSON Schema document, or simply a schema, is a JSON document used to describe an instance. A schema is itself interpreted as an instance. - A JSON Schema MUST be an object or a boolean, where boolean values are equivalent to object schemas as follows. + A JSON Schema MUST be an object or a boolean. + + + Boolean values are equivalent to the following behaviors: + + Always passes validation, as if the empty schema {} + Always fails validation, as if the schema { "not":{} } + -
- - true: - - - - -
-
- - false: - - - - -
Properties that are used to describe the instance are called keywords, or schema keywords. The meaning of properties is specified by the vocabulary that the schema is using. @@ -254,7 +239,7 @@ and the schema titled "root" is the root schema. - As with the root schema, a subschema MUST be an object or a boolean. + As with the root schema, a subschema is either an object or a boolean.
@@ -324,9 +309,11 @@
- In addition to a boolean value or an object using schema kewyords defined - in the meta-schema, a schema may be represnted by an object containing a "$ref" property. - The value of the $ref is a URI Reference. + The "$ref" keyword is used to reference a schema, and provides the ability to validate recursive structures through self-reference. + + + An object schema with a "$ref" property MUST be interpreted as a "$ref" reference. + The value of the "$ref" property MUST be a URI Reference. Resolved against the current URI base, it identifies the URI of a schema to use. All other properties in a "$ref" object MUST be ignored.