Skip to content
This repository was archived by the owner on Nov 2, 2023. It is now read-only.

Commit 26b5456

Browse files
committed
Allow references wherever a schema is allowed.
This is the final change for Draft 05. The main definitions for both core/validation and hyper-schema are moved into the "definitions" section. In both meta-schemas, the root schemas are now a "oneOf" of either a JSON reference, or (for core/validation) the regular schema object or (for hyper-schema) both the regular schema object and the hyper-schema object. The regular core/validation schema object forbids any "$ref" property, ensuring that both sides of the "oneOf" are never matched at the same time. This ensures that any schema with a "$ref" that is a string validates as a JSON reference and not as a regular schema (as additional properties within a JSON reference are legal but MUST be ignored). Note that an object with a non-string "$ref" will not validate at all.
1 parent da51748 commit 26b5456

File tree

2 files changed

+191
-176
lines changed

2 files changed

+191
-176
lines changed

draft-05/hyper-schema

+63-59
Original file line numberDiff line numberDiff line change
@@ -34,73 +34,77 @@
3434
},
3535
"schema": { "$ref": "#" }
3636
}
37-
}
38-
},
39-
"allOf": [
40-
{
41-
"$ref": "http://json-schema.org/draft-05/schema"
42-
}
43-
],
44-
"properties": {
45-
"additionalItems": {
46-
"anyOf": [
47-
{ "type": "boolean" },
48-
{ "$ref": "#" }
49-
]
50-
},
51-
"additionalProperties": {
52-
"anyOf": [
53-
{ "type": "boolean" },
54-
{ "$ref": "#" }
55-
]
56-
},
57-
"dependencies": {
58-
"additionalProperties": {
59-
"anyOf": [
60-
{ "$ref": "#" },
61-
{ "type": "array" }
62-
]
63-
}
64-
},
65-
"items": {
66-
"anyOf": [
67-
{ "$ref": "#" },
68-
{ "$ref": "#/definitions/schemaArray" }
69-
]
70-
},
71-
"definitions": {
72-
"additionalProperties": { "$ref": "#" }
73-
},
74-
"patternProperties": {
75-
"additionalProperties": { "$ref": "#" }
76-
},
77-
"properties": {
78-
"additionalProperties": { "$ref": "#" }
79-
},
80-
"allOf": { "$ref": "#/definitions/schemaArray" },
81-
"anyOf": { "$ref": "#/definitions/schemaArray" },
82-
"oneOf": { "$ref": "#/definitions/schemaArray" },
83-
"not": { "$ref": "#" },
84-
85-
"base": {
86-
"type": "string"
8737
},
88-
"links": {
89-
"type": "array",
90-
"items": { "$ref": "#/definitions/linkDescription" }
91-
},
92-
"media": {
93-
"type": "object",
38+
"hyperSchemaObject": {
9439
"properties": {
95-
"type": {
96-
"type": "string"
40+
"additionalItems": {
41+
"anyOf": [
42+
{ "type": "boolean" },
43+
{ "$ref": "#" }
44+
]
45+
},
46+
"additionalProperties": {
47+
"anyOf": [
48+
{ "type": "boolean" },
49+
{ "$ref": "#" }
50+
]
51+
},
52+
"dependencies": {
53+
"additionalProperties": {
54+
"anyOf": [
55+
{ "$ref": "#" },
56+
{ "type": "array" }
57+
]
58+
}
59+
},
60+
"items": {
61+
"anyOf": [
62+
{ "$ref": "#" },
63+
{ "$ref": "#/definitions/schemaArray" }
64+
]
9765
},
98-
"binaryEncoding": {
66+
"definitions": {
67+
"additionalProperties": { "$ref": "#" }
68+
},
69+
"patternProperties": {
70+
"additionalProperties": { "$ref": "#" }
71+
},
72+
"properties": {
73+
"additionalProperties": { "$ref": "#" }
74+
},
75+
"allOf": { "$ref": "#/definitions/schemaArray" },
76+
"anyOf": { "$ref": "#/definitions/schemaArray" },
77+
"oneOf": { "$ref": "#/definitions/schemaArray" },
78+
"not": { "$ref": "#" },
79+
80+
"base": {
9981
"type": "string"
82+
},
83+
"links": {
84+
"type": "array",
85+
"items": { "$ref": "#/definitions/linkDescription" }
86+
},
87+
"media": {
88+
"type": "object",
89+
"properties": {
90+
"type": {
91+
"type": "string"
92+
},
93+
"binaryEncoding": {
94+
"type": "string"
95+
}
96+
}
10097
}
10198
}
10299
}
103100
},
101+
"oneOf": [
102+
"allOf": [
103+
{ "$ref": "http://json-schema.org/draft-05/schema#/definitions/schemaObject" },
104+
{ "$ref": "#/definitions/hyperSchemaObject" }
105+
],
106+
{ "$ref": "http://json-schema.org/draft-05/schema#/definitions/jsonReference" }
107+
],
104108
"links": [
105109
{
106110
"rel": "self",

draft-05/schema

+128-117
Original file line numberDiff line numberDiff line change
@@ -44,129 +44,140 @@
4444
"items": { "type": "string" },
4545
"minItems": 1,
4646
"uniqueItems": true
47-
}
48-
},
49-
"type": "object",
50-
"properties": {
51-
"id": {
52-
"type": "string",
53-
"format": "uriref"
54-
},
55-
"$schema": {
56-
"type": "string",
57-
"format": "uri"
58-
},
59-
"title": {
60-
"type": "string"
61-
},
62-
"description": {
63-
"type": "string"
64-
},
65-
"default": {},
66-
"multipleOf": {
67-
"type": "number",
68-
"minimum": 0,
69-
"exclusiveMinimum": true
70-
},
71-
"maximum": {
72-
"type": "number"
73-
},
74-
"exclusiveMaximum": {
75-
"type": "boolean",
76-
"default": false
77-
},
78-
"minimum": {
79-
"type": "number"
80-
},
81-
"exclusiveMinimum": {
82-
"type": "boolean",
83-
"default": false
8447
},
85-
"maxLength": { "$ref": "#/definitions/positiveInteger" },
86-
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
87-
"pattern": {
88-
"type": "string",
89-
"format": "regex"
90-
},
91-
"additionalItems": {
92-
"anyOf": [
93-
{ "type": "boolean" },
94-
{ "$ref": "#" }
95-
],
96-
"default": {}
97-
},
98-
"items": {
99-
"anyOf": [
100-
{ "$ref": "#" },
101-
{ "$ref": "#/definitions/schemaArray" }
102-
],
103-
"default": {}
104-
},
105-
"maxItems": { "$ref": "#/definitions/positiveInteger" },
106-
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
107-
"uniqueItems": {
108-
"type": "boolean",
109-
"default": false
110-
},
111-
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
112-
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
113-
"required": { "$ref": "#/definitions/stringArray" },
114-
"additionalProperties": {
115-
"anyOf": [
116-
{ "type": "boolean" },
117-
{ "$ref": "#" }
118-
],
119-
"default": {}
120-
},
121-
"definitions": {
48+
"schemaObject": {
12249
"type": "object",
123-
"additionalProperties": { "$ref": "#" },
124-
"default": {}
125-
},
126-
"properties": {
127-
"type": "object",
128-
"additionalProperties": { "$ref": "#" },
129-
"default": {}
130-
},
131-
"patternProperties": {
132-
"type": "object",
133-
"additionalProperties": { "$ref": "#" },
134-
"default": {}
135-
},
136-
"dependencies": {
137-
"type": "object",
138-
"additionalProperties": {
139-
"anyOf": [
140-
{ "$ref": "#" },
141-
{ "$ref": "#/definitions/stringArray" }
142-
]
143-
}
144-
},
145-
"enum": {
146-
"type": "array",
147-
"minItems": 1,
148-
"uniqueItems": true
149-
},
150-
"type": {
151-
"anyOf": [
152-
{ "$ref": "#/definitions/simpleTypes" },
153-
{
50+
"properties": {
51+
"id": {
52+
"type": "string",
53+
"format": "uriref"
54+
},
55+
"$schema": {
56+
"type": "string",
57+
"format": "uri"
58+
},
59+
"title": {
60+
"type": "string"
61+
},
62+
"description": {
63+
"type": "string"
64+
},
65+
"default": {},
66+
"multipleOf": {
67+
"type": "number",
68+
"minimum": 0,
69+
"exclusiveMinimum": true
70+
},
71+
"maximum": {
72+
"type": "number"
73+
},
74+
"exclusiveMaximum": {
75+
"type": "boolean",
76+
"default": false
77+
},
78+
"minimum": {
79+
"type": "number"
80+
},
81+
"exclusiveMinimum": {
82+
"type": "boolean",
83+
"default": false
84+
},
85+
"maxLength": { "$ref": "#/definitions/positiveInteger" },
86+
"minLength": { "$ref": "#/definitions/positiveIntegerDefault0" },
87+
"pattern": {
88+
"type": "string",
89+
"format": "regex"
90+
},
91+
"additionalItems": {
92+
"anyOf": [
93+
{ "type": "boolean" },
94+
{ "$ref": "#" }
95+
],
96+
"default": {}
97+
},
98+
"items": {
99+
"anyOf": [
100+
{ "$ref": "#" },
101+
{ "$ref": "#/definitions/schemaArray" }
102+
],
103+
"default": {}
104+
},
105+
"maxItems": { "$ref": "#/definitions/positiveInteger" },
106+
"minItems": { "$ref": "#/definitions/positiveIntegerDefault0" },
107+
"uniqueItems": {
108+
"type": "boolean",
109+
"default": false
110+
},
111+
"maxProperties": { "$ref": "#/definitions/positiveInteger" },
112+
"minProperties": { "$ref": "#/definitions/positiveIntegerDefault0" },
113+
"required": { "$ref": "#/definitions/stringArray" },
114+
"additionalProperties": {
115+
"anyOf": [
116+
{ "type": "boolean" },
117+
{ "$ref": "#" }
118+
],
119+
"default": {}
120+
},
121+
"definitions": {
122+
"type": "object",
123+
"additionalProperties": { "$ref": "#" },
124+
"default": {}
125+
},
126+
"properties": {
127+
"type": "object",
128+
"additionalProperties": { "$ref": "#" },
129+
"default": {}
130+
},
131+
"patternProperties": {
132+
"type": "object",
133+
"additionalProperties": { "$ref": "#" },
134+
"default": {}
135+
},
136+
"dependencies": {
137+
"type": "object",
138+
"additionalProperties": {
139+
"anyOf": [
140+
{ "$ref": "#" },
141+
{ "$ref": "#/definitions/stringArray" }
142+
]
143+
}
144+
},
145+
"enum": {
154146
"type": "array",
155-
"items": { "$ref": "#/definitions/simpleTypes" },
156147
"minItems": 1,
157148
"uniqueItems": true
149+
},
150+
"type": {
151+
"anyOf": [
152+
{ "$ref": "#/definitions/simpleTypes" },
153+
{
154+
"type": "array",
155+
"items": { "$ref": "#/definitions/simpleTypes" },
156+
"minItems": 1,
157+
"uniqueItems": true
158+
}
159+
]
160+
},
161+
"format": { "type": "string" },
162+
"allOf": { "$ref": "#/definitions/schemaArray" },
163+
"anyOf": { "$ref": "#/definitions/schemaArray" },
164+
"oneOf": { "$ref": "#/definitions/schemaArray" },
165+
"not": { "$ref": "#" }
166+
},
167+
"dependencies": {
168+
"exclusiveMaximum": [ "maximum" ],
169+
"exclusiveMinimum": [ "minimum" ]
170+
},
171+
"not": {
172+
"properties": {
173+
"$ref": {}
158174
}
159-
]
160-
},
161-
"format": { "type": "string" },
162-
"allOf": { "$ref": "#/definitions/schemaArray" },
163-
"anyOf": { "$ref": "#/definitions/schemaArray" },
164-
"oneOf": { "$ref": "#/definitions/schemaArray" },
165-
"not": { "$ref": "#" }
166-
},
167-
"dependencies": {
168-
"exclusiveMaximum": [ "maximum" ],
169-
"exclusiveMinimum": [ "minimum" ]
175+
}
176+
}
170177
},
178+
"oneOf": [
179+
{ "$ref": "#/definitions/schemaObject" },
180+
{ "$ref": "#/definitions/jsonReference" }
181+
],
171182
"default": {}
172183
}

0 commit comments

Comments
 (0)