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

Commit df2c717

Browse files
committed
Add "$ref" for subschemas to meta-schemas.
This ensures that subschemas are either "normal" JSON Schema objects according to the declared vocabulary, or references. The separate definitions of jsonReference and notJsonReference ensure that objects with a "$ref" property that is not a URI reference fail validation. If we just negated the jsonReference defintion, then {"$ref": 4} would validate as a non-reference schema which is incorrect.
1 parent 5372503 commit df2c717

File tree

2 files changed

+58
-20
lines changed

2 files changed

+58
-20
lines changed

draft-05/hyper-schema

+23-11
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"definitions": {
66
"schemaArray": {
77
"type": "array",
8-
"items": { "$ref": "#" }
8+
"items": { "$ref": "#/definitions/subSchema" }
99
},
1010
"linkDescription": {
1111
"title": "Link Description Object",
@@ -26,7 +26,7 @@
2626
},
2727
"targetSchema": {
2828
"description": "JSON Schema describing the link target",
29-
"allOf": [ { "$ref": "#" } ]
29+
"allOf": [ { "$ref": "#/definitions/subSchema" } ]
3030
},
3131
"mediaType": {
3232
"description": "media type (as defined by RFC 2046) describing the link target",
@@ -43,52 +43,64 @@
4343
},
4444
"schema": {
4545
"description": "Schema describing the data to submit along with the request",
46-
"allOf": [ { "$ref": "#" } ]
46+
"allOf": [ { "$ref": "#/definitions/subSchema" } ]
4747
}
4848
}
49+
},
50+
"subSchema": {
51+
"oneOf": [
52+
{
53+
"allOf": [
54+
{ "$ref": "#" },
55+
{ "$ref": "http://json-schema.org/draft-05/schema#/definitions/notJsonReference" }
56+
]
57+
},
58+
{ "$ref": "http://json-schema.org/draft-05/schema#/definitions/notJsonReference#/definitions/jsonReference" }
59+
]
4960
}
5061
},
62+
5163
"allOf": [ { "$ref": "http://json-schema.org/draft-05/schema#" } ],
5264
"properties": {
5365
"additionalItems": {
5466
"anyOf": [
5567
{ "type": "boolean" },
56-
{ "$ref": "#" }
68+
{ "$ref": "#/definitions/subSchema" }
5769
]
5870
},
5971
"additionalProperties": {
6072
"anyOf": [
6173
{ "type": "boolean" },
62-
{ "$ref": "#" }
74+
{ "$ref": "#/definitions/subSchema" }
6375
]
6476
},
6577
"dependencies": {
6678
"additionalProperties": {
6779
"anyOf": [
68-
{ "$ref": "#" },
80+
{ "$ref": "#/definitions/subSchema" },
6981
{ "type": "array" }
7082
]
7183
}
7284
},
7385
"items": {
7486
"anyOf": [
75-
{ "$ref": "#" },
87+
{ "$ref": "#/definitions/subSchema" },
7688
{ "$ref": "#/definitions/schemaArray" }
7789
]
7890
},
7991
"definitions": {
80-
"additionalProperties": { "$ref": "#" }
92+
"additionalProperties": { "$ref": "#/definitions/subSchema" }
8193
},
8294
"patternProperties": {
83-
"additionalProperties": { "$ref": "#" }
95+
"additionalProperties": { "$ref": "#/definitions/subSchema" }
8496
},
8597
"properties": {
86-
"additionalProperties": { "$ref": "#" }
98+
"additionalProperties": { "$ref": "#/definitions/subSchema" }
8799
},
88100
"allOf": { "$ref": "#/definitions/schemaArray" },
89101
"anyOf": { "$ref": "#/definitions/schemaArray" },
90102
"oneOf": { "$ref": "#/definitions/schemaArray" },
91-
"not": { "$ref": "#" },
103+
"not": { "$ref": "#/definitions/subSchema" },
92104

93105
"base": {
94106
"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.",

draft-05/schema

+35-9
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,25 @@
33
"id": "http://json-schema.org/draft-05/schema#",
44
"title": "Core schema meta-schema",
55
"definitions": {
6+
"jsonReferece": {
7+
"type": "object",
8+
"properties": {
9+
"$ref": {
10+
"type": "string",
11+
"format": "uriref"
12+
}
13+
},
14+
"required": [ "$ref" ]
15+
},
16+
"notJsonReference": {
17+
"not": {
18+
"required": [ "$ref" ]
19+
}
20+
},
621
"schemaArray": {
722
"type": "array",
823
"minItems": 1,
9-
"items": { "$ref": "#" }
24+
"items": { "$ref": "#/definitions/subSchema" }
1025
},
1126
"positiveInteger": {
1227
"type": "integer",
@@ -34,6 +49,17 @@
3449
"items": { "type": "string" },
3550
"minItems": 1,
3651
"uniqueItems": true
52+
},
53+
"subSchema": {
54+
"oneOf": [
55+
{
56+
"allOf": [
57+
{ "$ref": "#" },
58+
{ "$ref": "#/definitions/notJsonReference" }
59+
]
60+
},
61+
{ "$ref": "#/definitions/jsonReference" }
62+
]
3763
}
3864
},
3965
"type": "object",
@@ -81,13 +107,13 @@
81107
"additionalItems": {
82108
"anyOf": [
83109
{ "type": "boolean" },
84-
{ "$ref": "#" }
110+
{ "$ref": "#/definitions/subSchema" }
85111
],
86112
"default": {}
87113
},
88114
"items": {
89115
"anyOf": [
90-
{ "$ref": "#" },
116+
{ "$ref": "#/definitions/subSchema" },
91117
{ "$ref": "#/definitions/schemaArray" }
92118
],
93119
"default": {}
@@ -104,30 +130,30 @@
104130
"additionalProperties": {
105131
"anyOf": [
106132
{ "type": "boolean" },
107-
{ "$ref": "#" }
133+
{ "$ref": "#/definitions/subSchema" }
108134
],
109135
"default": {}
110136
},
111137
"definitions": {
112138
"type": "object",
113-
"additionalProperties": { "$ref": "#" },
139+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
114140
"default": {}
115141
},
116142
"properties": {
117143
"type": "object",
118-
"additionalProperties": { "$ref": "#" },
144+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
119145
"default": {}
120146
},
121147
"patternProperties": {
122148
"type": "object",
123-
"additionalProperties": { "$ref": "#" },
149+
"additionalProperties": { "$ref": "#/definitions/subSchema" },
124150
"default": {}
125151
},
126152
"dependencies": {
127153
"type": "object",
128154
"additionalProperties": {
129155
"anyOf": [
130-
{ "$ref": "#" },
156+
{ "$ref": "#/definitions/subSchema" },
131157
{ "$ref": "#/definitions/stringArray" }
132158
]
133159
}
@@ -152,7 +178,7 @@
152178
"allOf": { "$ref": "#/definitions/schemaArray" },
153179
"anyOf": { "$ref": "#/definitions/schemaArray" },
154180
"oneOf": { "$ref": "#/definitions/schemaArray" },
155-
"not": { "$ref": "#" }
181+
"not": { "$ref": "#/definitions/subSchema" }
156182
},
157183
"dependencies": {
158184
"exclusiveMaximum": [ "maximum" ],

0 commit comments

Comments
 (0)