Skip to content

Commit

Permalink
Allow boolean subschemas everywhere.
Browse files Browse the repository at this point in the history
This implements issue #101

Also add JSON Reference schema for subSchemas.

Since "$ref" is now only allowed as a JSON Reference where a schema
is acceptable, it can now be described in JSON Schema and included
in the "anyOf" that defines legal subschemas.
  • Loading branch information
handrews committed Nov 17, 2016
1 parent 5340c4b commit fe7f820
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 59 deletions.
40 changes: 19 additions & 21 deletions hyper-schema.json
Expand Up @@ -6,45 +6,35 @@
{"$ref": "http://json-schema.org/draft-04/schema#"}
],
"properties": {
"additionalItems": {
"anyOf": [
{"type": "boolean"},
{"$ref": "#"}
]
},
"additionalProperties": {
"anyOf": [
{"type": "boolean"},
{"$ref": "#"}
]
},
"additionalItems": { "$ref": "#/definitions/subSchema" },
"additionalProperties": { "$ref": "#/definitions/subSchema" },
"dependencies": {
"additionalProperties": {
"anyOf": [
{"$ref": "#"},
{"$ref": "#/definitions/subSchema"},
{"type": "array"}
]
}
},
"items": {
"anyOf": [
{"$ref": "#"},
{"$ref": "#/definitions/subSchema"},
{"$ref": "#/definitions/schemaArray"}
]
},
"definitions": {
"additionalProperties": {"$ref": "#"}
"additionalProperties": {"$ref": "#/definitions/subSchema"}
},
"patternProperties": {
"additionalProperties": {"$ref": "#"}
"additionalProperties": {"$ref": "#/definitions/subSchema"}
},
"properties": {
"additionalProperties": {"$ref": "#"}
"additionalProperties": {"$ref": "#/definitions/subSchema"}
},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": { "$ref": "#" },
"not": { "$ref": "#/definitions/subSchema" },

"base": {
"description": "URI Template resolved as for the 'href' keyword in the Link Description Object. The resulting URI Reference is resolved against the current URI base and sets the new URI base for URI references within the instance.",
Expand All @@ -69,9 +59,17 @@
}
},
"definitions": {
"subSchema": {
"anyOf": [
{"$ref": "#"},
{"type": "boolean"},
{"$ref": "http://json-schema.org/draft/hyper-schema#/definitions/jsonReference"}
],
"default": true
},
"schemaArray": {
"type": "array",
"items": {"$ref": "#"}
"items": {"$ref": "#/definitions/subSchema"}
},
"linkDescription": {
"title": "Link Description Object",
Expand All @@ -92,7 +90,7 @@
},
"targetSchema": {
"description": "JSON Schema describing the link target",
"$ref": "#"
"$ref": "#/definitions/subschema"
},
"mediaType": {
"description": "media type (as defined by RFC 2046) describing the link target",
Expand All @@ -109,7 +107,7 @@
},
"schema": {
"description": "Schema describing the data to submit along with the request",
"$ref": "#"
"$ref": "/definitions/subschema#"
}
}
}
Expand Down
29 changes: 27 additions & 2 deletions jsonschema-core.xml
Expand Up @@ -187,7 +187,7 @@
<t>
A JSON Schema document, or simply a schema, is a JSON document used to describe an instance.
A schema is itself interperted as an instance.
A JSON schema MUST be an object.
A JSON Schema document MUST consist of an object, known as the root schema.
</t>
<t>
Properties that are used to describe the instance are called keywords, or schema keywords.
Expand Down Expand Up @@ -229,6 +229,31 @@
In this example document, the schema titled "array item" is a subschema,
and the schema titled "root" is the root schema.
</t>
<t>
A subschema MUST be an object or a boolean, where boolean values are equivalent to object schemas as follows:
</t>
<t>
true:
</t>
<figure>
<artwork>
<![CDATA[
{}
]]>
</artwork>
</figure>
<t>
false:
</t>
<figure>
<artwork>
<![CDATA[
{
"not": {}
}
]]>
</artwork>
</figure>
</section>

</section>
Expand Down Expand Up @@ -321,7 +346,7 @@
<xref target="RFC3986">RFC3986 Section 5.1</xref> defines how to determine the default base URI of a document.
</t>
<t>
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.
</t>
</section>

Expand Down
22 changes: 9 additions & 13 deletions jsonschema-validation.xml
Expand Up @@ -313,8 +313,7 @@

<section title="items">
<t>
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 subschema or an array of valid subschemas.
</t>
<t>
If absent, it can be considered present with an empty schema.
Expand All @@ -336,8 +335,7 @@

<section title="additionalItems">
<t>
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 subschema.
</t>
<t>
If absent, it can be considered present with an empty schema.
Expand Down Expand Up @@ -447,7 +445,7 @@
<section title="properties">
<t>
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 subschema.
</t>
<t>
If absent, it can be considered the same as an empty object.
Expand All @@ -468,7 +466,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 subschema.
</t>
<t>
If absent, it can be considered the same as an empty object.
Expand All @@ -487,8 +485,7 @@

<section title="additionalProperties">
<t>
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 subschema.
</t>
<t>
If "additionalProperties" is absent, it may be considered present with
Expand Down Expand Up @@ -516,12 +513,11 @@
</t>
<t>
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 subschema.
</t>
<t>
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.
</t>
<t>
If the dependency value is an array, each element in the array,
Expand Down Expand Up @@ -620,7 +616,7 @@
<section title="definitions">
<t>
This keyword's value MUST be an object. Each member value of this object
MUST be a valid JSON Schema.
MUST be a valid subschema.
</t>
<t>
This keyword plays no role in validation per se. Its role is to provide
Expand Down
47 changes: 24 additions & 23 deletions schema.json
Expand Up @@ -3,10 +3,24 @@
"$schema": "http://json-schema.org/draft/schema#",
"description": "Core schema meta-schema",
"definitions": {
"jsonReference": {
"type": "object",
"properties": {
"$ref": { "type": "string", "format": "uriref" }
}
},
"subSchema": {
"anyOf": [
{ "$ref": "#" },
{ "type": "boolean" },
{ "$ref": "#/definitions/jsonReference" }
],
"default": true
},
"schemaArray": {
"type": "array",
"minItems": 1,
"items": { "$ref": "#" }
"items": { "$ref": "#/definitions/subSchema" }
},
"positiveInteger": {
"type": "integer",
Expand Down Expand Up @@ -69,19 +83,12 @@
"type": "string",
"format": "regex"
},
"additionalItems": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"additionalItems": { "$ref": "#/definitions/subSchema" },
"items": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/subSchema" },
{ "$ref": "#/definitions/schemaArray" }
],
"default": {}
]
},
"maxItems": { "$ref": "#/definitions/positiveInteger" },
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
Expand All @@ -93,33 +100,27 @@
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
"required": { "$ref": "#/definitions/stringArray" },
"additionalProperties": {
"anyOf": [
{ "type": "boolean" },
{ "$ref": "#" }
],
"default": {}
},
"additionalProperties": { "$ref": "#/definitions/subSchema" },
"definitions": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"additionalProperties": { "$ref": "#/definitions/subSchema" },
"default": {}
},
"properties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"additionalProperties": { "$ref": "#/definitions/subSchema" },
"default": {}
},
"patternProperties": {
"type": "object",
"additionalProperties": { "$ref": "#" },
"additionalProperties": { "$ref": "#/definitions/subSchema" },
"default": {}
},
"dependencies": {
"type": "object",
"additionalProperties": {
"anyOf": [
{ "$ref": "#" },
{ "$ref": "#/definitions/subSchema" },
{ "$ref": "#/definitions/stringArray" }
]
}
Expand All @@ -144,7 +145,7 @@
"allOf": { "$ref": "#/definitions/schemaArray" },
"anyOf": { "$ref": "#/definitions/schemaArray" },
"oneOf": { "$ref": "#/definitions/schemaArray" },
"not": { "$ref": "#" }
"not": { "$ref": "#/definitions/subSchema" }
},
"dependencies": {
"exclusiveMaximum": [ "maximum" ],
Expand Down

0 comments on commit fe7f820

Please sign in to comment.