Skip to content

Commit 3027781

Browse files
committed
Allow boolean subschemas everywhere.
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.
1 parent 70d6eff commit 3027781

File tree

4 files changed

+81
-60
lines changed

4 files changed

+81
-60
lines changed

hyper-schema.json

+20-22
Original file line numberDiff line numberDiff line change
@@ -3,48 +3,38 @@
33
"id": "http://json-schema.org/draft/hyper-schema#",
44
"title": "JSON Hyper-Schema",
55
"allOf": [
6-
{"$ref": "http://json-schema.org/draft-04/schema#"}
6+
{"$ref": "http://json-schema.org/draft/schema#"}
77
],
88
"properties": {
9-
"additionalItems": {
10-
"anyOf": [
11-
{"type": "boolean"},
12-
{"$ref": "#"}
13-
]
14-
},
15-
"additionalProperties": {
16-
"anyOf": [
17-
{"type": "boolean"},
18-
{"$ref": "#"}
19-
]
20-
},
9+
"additionalItems": { "$ref": "#/definitions/subSchema" },
10+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
2111
"dependencies": {
2212
"additionalProperties": {
2313
"anyOf": [
24-
{"$ref": "#"},
14+
{"$ref": "#/definitions/subSchema"},
2515
{"type": "array"}
2616
]
2717
}
2818
},
2919
"items": {
3020
"anyOf": [
31-
{"$ref": "#"},
21+
{"$ref": "#/definitions/subSchema"},
3222
{"$ref": "#/definitions/schemaArray"}
3323
]
3424
},
3525
"definitions": {
36-
"additionalProperties": {"$ref": "#"}
26+
"additionalProperties": {"$ref": "#/definitions/subSchema"}
3727
},
3828
"patternProperties": {
39-
"additionalProperties": {"$ref": "#"}
29+
"additionalProperties": {"$ref": "#/definitions/subSchema"}
4030
},
4131
"properties": {
42-
"additionalProperties": {"$ref": "#"}
32+
"additionalProperties": {"$ref": "#/definitions/subSchema"}
4333
},
4434
"allOf": {"$ref": "#/definitions/schemaArray"},
4535
"anyOf": {"$ref": "#/definitions/schemaArray"},
4636
"oneOf": {"$ref": "#/definitions/schemaArray"},
47-
"not": { "$ref": "#" },
37+
"not": { "$ref": "#/definitions/subSchema" },
4838

4939
"base": {
5040
"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.",
@@ -69,9 +59,17 @@
6959
}
7060
},
7161
"definitions": {
62+
"subSchema": {
63+
"anyOf": [
64+
{"$ref": "#"},
65+
{"type": "boolean"},
66+
{"$ref": "http://json-schema.org/draft/schema#/definitions/jsonReference"}
67+
],
68+
"default": true
69+
},
7270
"schemaArray": {
7371
"type": "array",
74-
"items": {"$ref": "#"}
72+
"items": {"$ref": "#/definitions/subSchema"}
7573
},
7674
"linkDescription": {
7775
"title": "Link Description Object",
@@ -92,7 +90,7 @@
9290
},
9391
"targetSchema": {
9492
"description": "JSON Schema describing the link target",
95-
"$ref": "#"
93+
"$ref": "#/definitions/subschema"
9694
},
9795
"mediaType": {
9896
"description": "media type (as defined by RFC 2046) describing the link target",
@@ -109,7 +107,7 @@
109107
},
110108
"schema": {
111109
"description": "Schema describing the data to submit along with the request",
112-
"$ref": "#"
110+
"$ref": "/definitions/subschema#"
113111
}
114112
}
115113
}

jsonschema-core.xml

+27-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
<t>
186186
A JSON Schema document, or simply a schema, is a JSON document used to describe an instance.
187187
A schema is itself interpreted as an instance.
188-
A JSON schema MUST be an object.
188+
A JSON Schema document MUST consist of an object, known as the root schema.
189189
</t>
190190
<t>
191191
Properties that are used to describe the instance are called keywords, or schema keywords.
@@ -227,6 +227,31 @@
227227
In this example document, the schema titled "array item" is a subschema,
228228
and the schema titled "root" is the root schema.
229229
</t>
230+
<t>
231+
A subschema MUST be an object or a boolean, where boolean values are equivalent to object schemas as follows:
232+
</t>
233+
<t>
234+
true:
235+
</t>
236+
<figure>
237+
<artwork>
238+
<![CDATA[
239+
{}
240+
]]>
241+
</artwork>
242+
</figure>
243+
<t>
244+
false:
245+
</t>
246+
<figure>
247+
<artwork>
248+
<![CDATA[
249+
{
250+
"not": {}
251+
}
252+
]]>
253+
</artwork>
254+
</figure>
230255
</section>
231256

232257
</section>
@@ -319,7 +344,7 @@
319344
<xref target="RFC3986">RFC3986 Section 5.1</xref> defines how to determine the default base URI of a document.
320345
</t>
321346
<t>
322-
Informatively, the initial base URI of a schema is the URI it was found at, or a suitable substitute URI if none is known.
347+
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.
323348
</t>
324349
</section>
325350

jsonschema-validation.xml

+9-13
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@
312312

313313
<section title="items">
314314
<t>
315-
The value of "items" MUST be either an object or an array of objects.
316-
Each object MUST be a valid JSON Schema.
315+
The value of "items" MUST be either a valid subschema or an array of valid subschemas.
317316
</t>
318317
<t>
319318
If absent, it can be considered present with an empty schema.
@@ -335,8 +334,7 @@
335334

336335
<section title="additionalItems">
337336
<t>
338-
The value of "additionalItems" MUST be a boolean or an object.
339-
If it is an object, the object MUST be a valid JSON Schema.
337+
The value of "additionalItems" MUST be a valid subschema.
340338
</t>
341339
<t>
342340
If absent, it can be considered present with an empty schema.
@@ -451,7 +449,7 @@
451449
<section title="properties">
452450
<t>
453451
The value of "properties" MUST be an object. Each value of this object
454-
MUST be an object, and each object MUST be a valid JSON Schema.
452+
MUST be a valid subschema.
455453
</t>
456454
<t>
457455
If absent, it can be considered the same as an empty object.
@@ -472,7 +470,7 @@
472470
The value of "patternProperties" MUST be an object. Each property name
473471
of this object SHOULD be a valid regular expression, according to the
474472
ECMA 262 regular expression dialect. Each property value of this object
475-
MUST be an object, and each object MUST be a valid JSON Schema.
473+
MUST be a valid subschema.
476474
</t>
477475
<t>
478476
If absent, it can be considered the same as an empty object.
@@ -491,8 +489,7 @@
491489

492490
<section title="additionalProperties">
493491
<t>
494-
The value of "additionalProperties" MUST be a boolean or an
495-
object. If it is an object, the object MUST be a valid JSON Schema.
492+
The value of "additionalProperties" MUST be a valid subschema.
496493
</t>
497494
<t>
498495
If "additionalProperties" is absent, it may be considered present with
@@ -520,12 +517,11 @@
520517
</t>
521518
<t>
522519
This keyword's value MUST be an object. Each property specifies a dependency.
523-
Each dependency value MUST be an object or an array.
520+
Each dependency value MUST be an array or a valid subschema.
524521
</t>
525522
<t>
526-
If the dependency value is an object, it MUST be a valid JSON Schema. If the
527-
dependency key is a property in the instance, the dependency value must validate
528-
against the entire instance.
523+
If the dependency value is a subschema, and the dependency key is a property
524+
in the instance, the entire instance must validate against the dependency value.
529525
</t>
530526
<t>
531527
If the dependency value is an array, each element in the array,
@@ -634,7 +630,7 @@
634630
<section title="definitions">
635631
<t>
636632
This keyword's value MUST be an object. Each member value of this object
637-
MUST be a valid JSON Schema.
633+
MUST be a valid subschema.
638634
</t>
639635
<t>
640636
This keyword plays no role in validation per se. Its role is to provide

schema.json

+25-23
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33
"$schema": "http://json-schema.org/draft/schema#",
44
"description": "Core schema meta-schema",
55
"definitions": {
6+
"jsonReference": {
7+
"type": "object",
8+
"properties": {
9+
"$ref": { "type": "string", "format": "uriref" }
10+
},
11+
"required": ["$ref"]
12+
},
13+
"subSchema": {
14+
"anyOf": [
15+
{ "$ref": "#" },
16+
{ "type": "boolean" },
17+
{ "$ref": "#/definitions/jsonReference" }
18+
],
19+
"default": true
20+
},
621
"schemaArray": {
722
"type": "array",
823
"minItems": 1,
9-
"items": { "$ref": "#" }
24+
"items": { "$ref": "#/definitions/subSchema" }
1025
},
1126
"positiveInteger": {
1227
"type": "integer",
@@ -69,19 +84,12 @@
6984
"type": "string",
7085
"format": "regex"
7186
},
72-
"additionalItems": {
73-
"anyOf": [
74-
{ "type": "boolean" },
75-
{ "$ref": "#" }
76-
],
77-
"default": {}
78-
},
87+
"additionalItems": { "$ref": "#/definitions/subSchema" },
7988
"items": {
8089
"anyOf": [
81-
{ "$ref": "#" },
90+
{ "$ref": "#/definitions/subSchema" },
8291
{ "$ref": "#/definitions/schemaArray" }
83-
],
84-
"default": {}
92+
]
8593
},
8694
"maxItems": { "$ref": "#/definitions/positiveInteger" },
8795
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
@@ -93,33 +101,27 @@
93101
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
94102
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
95103
"required": { "$ref": "#/definitions/stringArray" },
96-
"additionalProperties": {
97-
"anyOf": [
98-
{ "type": "boolean" },
99-
{ "$ref": "#" }
100-
],
101-
"default": {}
102-
},
104+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
103105
"definitions": {
104106
"type": "object",
105-
"additionalProperties": { "$ref": "#" },
107+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
106108
"default": {}
107109
},
108110
"properties": {
109111
"type": "object",
110-
"additionalProperties": { "$ref": "#" },
112+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
111113
"default": {}
112114
},
113115
"patternProperties": {
114116
"type": "object",
115-
"additionalProperties": { "$ref": "#" },
117+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
116118
"default": {}
117119
},
118120
"dependencies": {
119121
"type": "object",
120122
"additionalProperties": {
121123
"anyOf": [
122-
{ "$ref": "#" },
124+
{ "$ref": "#/definitions/subSchema" },
123125
{ "$ref": "#/definitions/stringArray" }
124126
]
125127
}
@@ -145,7 +147,7 @@
145147
"allOf": { "$ref": "#/definitions/schemaArray" },
146148
"anyOf": { "$ref": "#/definitions/schemaArray" },
147149
"oneOf": { "$ref": "#/definitions/schemaArray" },
148-
"not": { "$ref": "#" }
150+
"not": { "$ref": "#/definitions/subSchema" }
149151
},
150152
"dependencies": {
151153
"exclusiveMaximum": [ "maximum" ],

0 commit comments

Comments
 (0)