Skip to content

Commit

Permalink
Allow boolean subschemas everywhere.
Browse files Browse the repository at this point in the history
This implements issue json-schema-org#101, including root schemas.

Also add JSON Reference objects as legal schemas in the meta-schema.

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 25, 2016
1 parent 7b628d0 commit 96000fe
Show file tree
Hide file tree
Showing 4 changed files with 228 additions and 205 deletions.
135 changes: 67 additions & 68 deletions hyper-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,6 @@
"$schema": "http://json-schema.org/draft/hyper-schema#",
"id": "http://json-schema.org/draft/hyper-schema#",
"title": "JSON Hyper-Schema",
"allOf": [
{"$ref": "http://json-schema.org/draft-04/schema#"}
],
"properties": {
"additionalItems": {
"anyOf": [
{"type": "boolean"},
{"$ref": "#"}
]
},
"additionalProperties": {
"anyOf": [
{"type": "boolean"},
{"$ref": "#"}
]
},
"dependencies": {
"additionalProperties": {
"anyOf": [
{"$ref": "#"},
{"type": "array"}
]
}
},
"items": {
"anyOf": [
{"$ref": "#"},
{"$ref": "#/definitions/schemaArray"}
]
},
"definitions": {
"additionalProperties": {"$ref": "#"}
},
"patternProperties": {
"additionalProperties": {"$ref": "#"}
},
"properties": {
"additionalProperties": {"$ref": "#"}
},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": { "$ref": "#" },

"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.",
"type": "string"
},
"links": {
"type": "array",
"items": {"$ref": "#/definitions/linkDescription"}
},
"media": {
"type": "object",
"properties": {
"type": {
"description": "A media type, as described in RFC 2046",
"type": "string"
},
"binaryEncoding": {
"description": "A content encoding scheme, as described in RFC 2045",
"type": "string"
}
}
}
},
"definitions": {
"schemaArray": {
"type": "array",
Expand All @@ -92,7 +26,7 @@
},
"targetSchema": {
"description": "JSON Schema describing the link target",
"$ref": "#"
"allOf": [{"$ref": "#"}]
},
"mediaType": {
"description": "media type (as defined by RFC 2046) describing the link target",
Expand All @@ -109,7 +43,63 @@
},
"schema": {
"description": "Schema describing the data to submit along with the request",
"$ref": "#"
"allOf": [{"$ref": "#"}]
}
}
},
"hyperSchema": {
"type": "object",
"properties": {
"additionalItems": { "$ref": "#" },
"additionalProperties": { "$ref": "#" },
"dependencies": {
"additionalProperties": {
"anyOf": [
{"$ref": "#"},
{"type": "array"}
]
}
},
"items": {
"anyOf": [
{"$ref": "#"},
{"$ref": "#/definitions/schemaArray"}
]
},
"definitions": {
"additionalProperties": {"$ref": "#"}
},
"patternProperties": {
"additionalProperties": {"$ref": "#"}
},
"properties": {
"additionalProperties": {"$ref": "#"}
},
"allOf": {"$ref": "#/definitions/schemaArray"},
"anyOf": {"$ref": "#/definitions/schemaArray"},
"oneOf": {"$ref": "#/definitions/schemaArray"},
"not": { "$ref": "#" },

"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.",
"type": "string"
},
"links": {
"type": "array",
"items": {"$ref": "#/definitions/linkDescription"}
},
"media": {
"type": "object",
"properties": {
"type": {
"description": "A media type, as described in RFC 2046",
"type": "string"
},
"binaryEncoding": {
"description": "A content encoding scheme, as described in RFC 2045",
"type": "string"
}
}
}
}
}
Expand All @@ -124,4 +114,13 @@
"href": "{+($ref)}"
}
]
"anyOf": [
{"allOf": [
{"$ref": "#/definitions/hyperSchema"},
{"$ref": "http://json-schema.org/draft/schema#/definitions/schemaObject"}
]},
{"type": "boolean"},
{"$ref": "http://json-schema.org/draft/schema#/definitions/jsonReference"}
],
"default": true
}
35 changes: 31 additions & 4 deletions jsonschema-core.xml
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,34 @@
</t>
</section>

<section title="JSON Schema document">
<section title="JSON Schema documents">
<t>
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.
</t>
<figure>
<preamble>
true:
</preamble>
<artwork>
<![CDATA[
{}
]]>
</artwork>
</figure>
<figure>
<preamble>
false:
</preamble>
<artwork>
<![CDATA[
{
"not": {}
}
]]>
</artwork>
</figure>
<t>
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.
Expand Down Expand Up @@ -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.
</t>
<t>
As with the root schema, a subschema MUST be an object or a boolean.
</t>
</section>

</section>
Expand Down Expand Up @@ -299,7 +324,8 @@

<section title="Schema references with $ref">
<t>
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.
Expand All @@ -323,7 +349,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 Expand Up @@ -660,6 +686,7 @@ User-Agent: so-cool-json-schema/1.0.2 curl/7.43.0
<t hangText="draft-wright-json-schema-01">
<list style="symbols">
<t>Updated intro</t>
<t>Allowed for any schema to be a boolean</t>
</list>
</t>
<t hangText="draft-wright-json-schema-00">
Expand Down
20 changes: 8 additions & 12 deletions jsonschema-validation.xml
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,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 JSON Schema or an array of valid JSON Schemas.
</t>
<t>
If absent, it can be considered present with an empty schema.
Expand All @@ -341,8 +340,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 JSON Schema.
</t>
<t>
If absent, it can be considered present with an empty schema.
Expand Down Expand Up @@ -457,7 +455,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 JSON Schema.
</t>
<t>
If absent, it can be considered the same as an empty object.
Expand All @@ -478,7 +476,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.
</t>
<t>
If absent, it can be considered the same as an empty object.
Expand All @@ -497,8 +495,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 JSON Schema.
</t>
<t>
If "additionalProperties" is absent, it may be considered present with
Expand Down Expand Up @@ -526,12 +523,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 JSON Schema.
</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
Loading

0 comments on commit 96000fe

Please sign in to comment.