Skip to content

Commit 8ca6faa

Browse files
committed
Allow boolean subschemas everywhere.
This implements issue #101
1 parent 356af3b commit 8ca6faa

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.
@@ -437,7 +435,7 @@
437435
<section title="properties">
438436
<t>
439437
The value of "properties" MUST be an object. Each value of this object
440-
MUST be an object, and each object MUST be a valid JSON Schema.
438+
MUST be a valid subschema.
441439
</t>
442440
<t>
443441
If absent, it can be considered the same as an empty object.
@@ -458,7 +456,7 @@
458456
The value of "patternProperties" MUST be an object. Each property name
459457
of this object SHOULD be a valid regular expression, according to the
460458
ECMA 262 regular expression dialect. Each property value of this object
461-
MUST be an object, and each object MUST be a valid JSON Schema.
459+
MUST be a valid subschema.
462460
</t>
463461
<t>
464462
If absent, it can be considered the same as an empty object.
@@ -477,8 +475,7 @@
477475

478476
<section title="additionalProperties">
479477
<t>
480-
The value of "additionalProperties" MUST be a boolean or an
481-
object. If it is an object, the object MUST be a valid JSON Schema.
478+
The value of "additionalProperties" MUST be a valid subschema.
482479
</t>
483480
<t>
484481
If "additionalProperties" is absent, it may be considered present with
@@ -506,12 +503,11 @@
506503
</t>
507504
<t>
508505
This keyword's value MUST be an object. Each property specifies a dependency.
509-
Each dependency value MUST be an object or an array.
506+
Each dependency value MUST be an array or a valid subschema.
510507
</t>
511508
<t>
512-
If the dependency value is an object, it MUST be a valid JSON Schema. If the
513-
dependency key is a property in the instance, the dependency value must validate
514-
against the entire instance.
509+
If the dependency value is a subschema, and the dependency key is a property
510+
in the instance, the entire instance must validate against the dependency value.
515511
</t>
516512
<t>
517513
If the dependency value is an array, it MUST have at least one element, each
@@ -610,7 +606,7 @@
610606
<section title="definitions">
611607
<t>
612608
This keyword's value MUST be an object. Each member value of this object
613-
MUST be a valid JSON Schema.
609+
MUST be a valid subschema.
614610
</t>
615611
<t>
616612
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-04/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" },
@@ -90,33 +87,27 @@
9087
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
9188
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
9289
"required": { "$ref": "#/definitions/stringArray" },
93-
"additionalProperties": {
94-
"anyOf": [
95-
{ "type": "boolean" },
96-
{ "$ref": "#" }
97-
],
98-
"default": {}
99-
},
90+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
10091
"definitions": {
10192
"type": "object",
102-
"additionalProperties": { "$ref": "#" },
93+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
10394
"default": {}
10495
},
10596
"properties": {
10697
"type": "object",
107-
"additionalProperties": { "$ref": "#" },
98+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
10899
"default": {}
109100
},
110101
"patternProperties": {
111102
"type": "object",
112-
"additionalProperties": { "$ref": "#" },
103+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
113104
"default": {}
114105
},
115106
"dependencies": {
116107
"type": "object",
117108
"additionalProperties": {
118109
"anyOf": [
119-
{ "$ref": "#" },
110+
{ "$ref": "#/definitions/subSchema" },
120111
{ "$ref": "#/definitions/stringArray" }
121112
]
122113
}
@@ -141,7 +132,7 @@
141132
"allOf": { "$ref": "#/definitions/schemaArray" },
142133
"anyOf": { "$ref": "#/definitions/schemaArray" },
143134
"oneOf": { "$ref": "#/definitions/schemaArray" },
144-
"not": { "$ref": "#" }
135+
"not": { "$ref": "#/definitions/subSchema" }
145136
},
146137
"dependencies": {
147138
"exclusiveMaximum": [ "maximum" ],

0 commit comments

Comments
 (0)