Skip to content

Commit da0ab16

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 6873d66 commit da0ab16

File tree

4 files changed

+80
-60
lines changed

4 files changed

+80
-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/hyper-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
@@ -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.
@@ -447,7 +445,7 @@
447445
<section title="properties">
448446
<t>
449447
The value of "properties" MUST be an object. Each value of this object
450-
MUST be an object, and each object MUST be a valid JSON Schema.
448+
MUST be a valid subschema.
451449
</t>
452450
<t>
453451
If absent, it can be considered the same as an empty object.
@@ -468,7 +466,7 @@
468466
The value of "patternProperties" MUST be an object. Each property name
469467
of this object SHOULD be a valid regular expression, according to the
470468
ECMA 262 regular expression dialect. Each property value of this object
471-
MUST be an object, and each object MUST be a valid JSON Schema.
469+
MUST be a valid subschema.
472470
</t>
473471
<t>
474472
If absent, it can be considered the same as an empty object.
@@ -487,8 +485,7 @@
487485

488486
<section title="additionalProperties">
489487
<t>
490-
The value of "additionalProperties" MUST be a boolean or an
491-
object. If it is an object, the object MUST be a valid JSON Schema.
488+
The value of "additionalProperties" MUST be a valid subschema.
492489
</t>
493490
<t>
494491
If "additionalProperties" is absent, it may be considered present with
@@ -516,12 +513,11 @@
516513
</t>
517514
<t>
518515
This keyword's value MUST be an object. Each property specifies a dependency.
519-
Each dependency value MUST be an object or an array.
516+
Each dependency value MUST be an array or a valid subschema.
520517
</t>
521518
<t>
522-
If the dependency value is an object, it MUST be a valid JSON Schema. If the
523-
dependency key is a property in the instance, the dependency value must validate
524-
against the entire instance.
519+
If the dependency value is a subschema, and the dependency key is a property
520+
in the instance, the entire instance must validate against the dependency value.
525521
</t>
526522
<t>
527523
If the dependency value is an array, each element in the array,
@@ -630,7 +626,7 @@
630626
<section title="definitions">
631627
<t>
632628
This keyword's value MUST be an object. Each member value of this object
633-
MUST be a valid JSON Schema.
629+
MUST be a valid subschema.
634630
</t>
635631
<t>
636632
This keyword plays no role in validation per se. Its role is to provide

schema.json

+24-23
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,24 @@
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+
},
12+
"subSchema": {
13+
"anyOf": [
14+
{ "$ref": "#" },
15+
{ "type": "boolean" },
16+
{ "$ref": "#/definitions/jsonReference" }
17+
],
18+
"default": true
19+
},
620
"schemaArray": {
721
"type": "array",
822
"minItems": 1,
9-
"items": { "$ref": "#" }
23+
"items": { "$ref": "#/definitions/subSchema" }
1024
},
1125
"positiveInteger": {
1226
"type": "integer",
@@ -69,19 +83,12 @@
6983
"type": "string",
7084
"format": "regex"
7185
},
72-
"additionalItems": {
73-
"anyOf": [
74-
{ "type": "boolean" },
75-
{ "$ref": "#" }
76-
],
77-
"default": {}
78-
},
86+
"additionalItems": { "$ref": "#/definitions/subSchema" },
7987
"items": {
8088
"anyOf": [
81-
{ "$ref": "#" },
89+
{ "$ref": "#/definitions/subSchema" },
8290
{ "$ref": "#/definitions/schemaArray" }
83-
],
84-
"default": {}
91+
]
8592
},
8693
"maxItems": { "$ref": "#/definitions/positiveInteger" },
8794
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
@@ -93,33 +100,27 @@
93100
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
94101
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
95102
"required": { "$ref": "#/definitions/stringArray" },
96-
"additionalProperties": {
97-
"anyOf": [
98-
{ "type": "boolean" },
99-
{ "$ref": "#" }
100-
],
101-
"default": {}
102-
},
103+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
103104
"definitions": {
104105
"type": "object",
105-
"additionalProperties": { "$ref": "#" },
106+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
106107
"default": {}
107108
},
108109
"properties": {
109110
"type": "object",
110-
"additionalProperties": { "$ref": "#" },
111+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
111112
"default": {}
112113
},
113114
"patternProperties": {
114115
"type": "object",
115-
"additionalProperties": { "$ref": "#" },
116+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
116117
"default": {}
117118
},
118119
"dependencies": {
119120
"type": "object",
120121
"additionalProperties": {
121122
"anyOf": [
122-
{ "$ref": "#" },
123+
{ "$ref": "#/definitions/subSchema" },
123124
{ "$ref": "#/definitions/stringArray" }
124125
]
125126
}
@@ -145,7 +146,7 @@
145146
"allOf": { "$ref": "#/definitions/schemaArray" },
146147
"anyOf": { "$ref": "#/definitions/schemaArray" },
147148
"oneOf": { "$ref": "#/definitions/schemaArray" },
148-
"not": { "$ref": "#" }
149+
"not": { "$ref": "#/definitions/subSchema" }
149150
},
150151
"dependencies": {
151152
"exclusiveMaximum": [ "maximum" ],

0 commit comments

Comments
 (0)