Skip to content

Commit 41abe7c

Browse files
committed
Allow boolean subschemas everywhere.
This implements issue #101
1 parent 4090d4c commit 41abe7c

File tree

4 files changed

+65
-59
lines changed

4 files changed

+65
-59
lines changed

hyper-schema.json

+15-21
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,35 @@
66
{"$ref": "http://json-schema.org/draft-04/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
"links": {
5040
"type": "array",
@@ -73,9 +63,13 @@
7363
}
7464
},
7565
"definitions": {
66+
"subSchema": {
67+
"anyOf": [ {"$ref": "#"}, {"type": "boolean"} ],
68+
"default": true
69+
},
7670
"schemaArray": {
7771
"type": "array",
78-
"items": {"$ref": "#"}
72+
"items": {"$ref": "#/definitions/subSchema"}
7973
},
8074
"linkDescription": {
8175
"title": "Link Description Object",
@@ -96,7 +90,7 @@
9690
},
9791
"targetSchema": {
9892
"description": "JSON Schema describing the link target",
99-
"$ref": "#"
93+
"$ref": "#/definitions/subschema"
10094
},
10195
"mediaType": {
10296
"description": "media type (as defined by RFC 2046) describing the link target",
@@ -113,7 +107,7 @@
113107
},
114108
"schema": {
115109
"description": "Schema describing the data to submit along with the request",
116-
"$ref": "#"
110+
"$ref": "/definitions/subschema#"
117111
}
118112
}
119113
}

jsonschema-core.xml

+27-2
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
<t>
188188
A JSON Schema document, or simply a schema, is a JSON document used to describe an instance.
189189
A schema is itself interperted as an instance.
190-
A JSON schema MUST be an object.
190+
A JSON Schema document MUST consist of an object, known as the root schema.
191191
</t>
192192
<t>
193193
Properties that are used to describe the instance are called keywords, or schema keywords.
@@ -229,6 +229,31 @@
229229
In this example document, the schema titled "array item" is a subschema,
230230
and the schema titled "root" is the root schema.
231231
</t>
232+
<t>
233+
A subschema MUST be an object or a boolean, where boolean values are equivalent to object schemas as follows:
234+
</t>
235+
<t>
236+
true:
237+
</t>
238+
<figure>
239+
<artwork>
240+
<![CDATA[
241+
{}
242+
]]>
243+
</artwork>
244+
</figure>
245+
<t>
246+
false:
247+
</t>
248+
<figure>
249+
<artwork>
250+
<![CDATA[
251+
{
252+
"not": {}
253+
}
254+
]]>
255+
</artwork>
256+
</figure>
232257
</section>
233258

234259
</section>
@@ -321,7 +346,7 @@
321346
<xref target="RFC3986">RFC3986 Section 5.1</xref> defines how to determine the default base URI of a document.
322347
</t>
323348
<t>
324-
Informatively, the initial base URI of a schema is the URI it was found at, or a suitable substitute URI if none is known.
349+
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.
325350
</t>
326351
</section>
327352

jsonschema-validation.xml

+9-13
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,7 @@
313313

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

337336
<section title="additionalItems">
338337
<t>
339-
The value of "additionalItems" MUST be a boolean or an object.
340-
If it is an object, the object MUST be a valid JSON Schema.
338+
The value of "additionalItems" MUST be a valid subschema.
341339
</t>
342340
<t>
343341
If absent, it can be considered present with an empty schema.
@@ -448,7 +446,7 @@
448446
<section title="properties">
449447
<t>
450448
The value of "properties" MUST be an object. Each value of this object
451-
MUST be an object, and each object MUST be a valid JSON Schema.
449+
MUST be a valid subschema.
452450
</t>
453451
<t>
454452
If absent, it can be considered the same as an empty object.
@@ -469,7 +467,7 @@
469467
The value of "patternProperties" MUST be an object. Each property name
470468
of this object SHOULD be a valid regular expression, according to the
471469
ECMA 262 regular expression dialect. Each property value of this object
472-
MUST be an object, and each object MUST be a valid JSON Schema.
470+
MUST be a valid subschema.
473471
</t>
474472
<t>
475473
If absent, it can be considered the same as an empty object.
@@ -488,8 +486,7 @@
488486

489487
<section title="additionalProperties">
490488
<t>
491-
The value of "additionalProperties" MUST be a boolean or an
492-
object. If it is an object, the object MUST be a valid JSON Schema.
489+
The value of "additionalProperties" MUST be a valid subschema.
493490
</t>
494491
<t>
495492
If "additionalProperties" is absent, it may be considered present with
@@ -517,12 +514,11 @@
517514
</t>
518515
<t>
519516
This keyword's value MUST be an object. Each property specifies a dependency.
520-
Each dependency value MUST be an object or an array.
517+
Each dependency value MUST be an array or a valid subschema.
521518
</t>
522519
<t>
523-
If the dependency value is an object, it MUST be a valid JSON Schema. If the
524-
dependency key is a property in the instance, the dependency value must validate
525-
against the entire instance.
520+
If the dependency value is a subschema, and the dependency key is a property
521+
in the instance, the entire instance must validate against the dependency value.
526522
</t>
527523
<t>
528524
If the dependency value is an array, it MUST have at least one element, each
@@ -621,7 +617,7 @@
621617
<section title="definitions">
622618
<t>
623619
This keyword's value MUST be an object. Each member value of this object
624-
MUST be a valid JSON Schema.
620+
MUST be a valid subschema.
625621
</t>
626622
<t>
627623
This keyword plays no role in validation per se. Its role is to provide

schema.json

+14-23
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
"$schema": "http://json-schema.org/draft/schema#",
44
"description": "Core schema meta-schema",
55
"definitions": {
6+
"subSchema": {
7+
"anyOf": [ {"$ref": "#"}, {"type": "boolean"} ],
8+
"default": true
9+
},
610
"schemaArray": {
711
"type": "array",
812
"minItems": 1,
9-
"items": { "$ref": "#" }
13+
"items": { "$ref": "#/definitions/subSchema" }
1014
},
1115
"positiveInteger": {
1216
"type": "integer",
@@ -67,19 +71,12 @@
6771
"type": "string",
6872
"format": "regex"
6973
},
70-
"additionalItems": {
71-
"anyOf": [
72-
{ "type": "boolean" },
73-
{ "$ref": "#" }
74-
],
75-
"default": {}
76-
},
74+
"additionalItems": { "$ref": "#/definitions/subSchema" },
7775
"items": {
7876
"anyOf": [
79-
{ "$ref": "#" },
77+
{ "$ref": "#/definitions/subSchema" },
8078
{ "$ref": "#/definitions/schemaArray" }
81-
],
82-
"default": {}
79+
]
8380
},
8481
"maxItems": { "$ref": "#/definitions/positiveInteger" },
8582
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
@@ -91,33 +88,27 @@
9188
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
9289
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
9390
"required": { "$ref": "#/definitions/stringArray" },
94-
"additionalProperties": {
95-
"anyOf": [
96-
{ "type": "boolean" },
97-
{ "$ref": "#" }
98-
],
99-
"default": {}
100-
},
91+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
10192
"definitions": {
10293
"type": "object",
103-
"additionalProperties": { "$ref": "#" },
94+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
10495
"default": {}
10596
},
10697
"properties": {
10798
"type": "object",
108-
"additionalProperties": { "$ref": "#" },
99+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
109100
"default": {}
110101
},
111102
"patternProperties": {
112103
"type": "object",
113-
"additionalProperties": { "$ref": "#" },
104+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
114105
"default": {}
115106
},
116107
"dependencies": {
117108
"type": "object",
118109
"additionalProperties": {
119110
"anyOf": [
120-
{ "$ref": "#" },
111+
{ "$ref": "#/definitions/subSchema" },
121112
{ "$ref": "#/definitions/stringArray" }
122113
]
123114
}
@@ -142,7 +133,7 @@
142133
"allOf": { "$ref": "#/definitions/schemaArray" },
143134
"anyOf": { "$ref": "#/definitions/schemaArray" },
144135
"oneOf": { "$ref": "#/definitions/schemaArray" },
145-
"not": { "$ref": "#" }
136+
"not": { "$ref": "#/definitions/subSchema" }
146137
},
147138
"dependencies": {
148139
"exclusiveMaximum": [ "maximum" ],

0 commit comments

Comments
 (0)