Skip to content

Commit 2db9c58

Browse files
committed
Update the Draft 3 and 4 metaschemas.
For draft 4 this pulls in upstream fixes which were not present locally, notably fixing `id` to not have `format: uri` in it, because location independent identifiers are indeed not URIs (they're URI references as later metaschemas use). For enum, on draft 3 and 4, this also *re-adds* constraints that enum items MUST be unique and the array non-empty. In later drafts, this restriction was loosened (see json-schema-org/json-schema-spec@cf0ec72) as well as json-schema-org/json-schema-spec#717 (comment) but in drafts 3 and 4 it is present. The draft 4 metaschema contains these assertions, the draft 3 one is still buggy and does not, so they're just applied locally here. Ref: json-schema-org/json-schema-spec#310
1 parent f40199d commit 2db9c58

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

jsonschema/schemas/draft3.json

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
"properties" : {
1717
"type" : "object",
18-
"additionalProperties" : {"$ref" : "#", "type" : "object"},
18+
"additionalProperties" : {"$ref" : "#"},
1919
"default" : {}
2020
},
2121

@@ -47,7 +47,7 @@
4747
},
4848

4949
"dependencies" : {
50-
"type" : ["string", "array", "object"],
50+
"type" : "object",
5151
"additionalProperties" : {
5252
"type" : ["string", "array", {"$ref" : "#"}],
5353
"items" : {
@@ -75,11 +75,6 @@
7575
"default" : false
7676
},
7777

78-
"maxDecimal": {
79-
"minimum": 0,
80-
"type": "number"
81-
},
82-
8378
"minItems" : {
8479
"type" : "integer",
8580
"minimum" : 0,
@@ -112,7 +107,9 @@
112107
},
113108

114109
"enum" : {
115-
"type" : "array"
110+
"type" : "array",
111+
"minItems" : 1,
112+
"uniqueItems" : true
116113
},
117114

118115
"default" : {
@@ -153,13 +150,11 @@
153150
},
154151

155152
"id" : {
156-
"type" : "string",
157-
"format" : "uri"
153+
"type" : "string"
158154
},
159155

160156
"$ref" : {
161-
"type" : "string",
162-
"format" : "uri"
157+
"type" : "string"
163158
},
164159

165160
"$schema" : {

jsonschema/schemas/draft4.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,10 @@
2828
"type": "object",
2929
"properties": {
3030
"id": {
31-
"format": "uri",
3231
"type": "string"
3332
},
3433
"$schema": {
35-
"type": "string",
36-
"format": "uri"
34+
"type": "string"
3735
},
3836
"title": {
3937
"type": "string"
@@ -122,7 +120,9 @@
122120
}
123121
},
124122
"enum": {
125-
"type": "array"
123+
"type": "array",
124+
"minItems": 1,
125+
"uniqueItems": true
126126
},
127127
"type": {
128128
"anyOf": [

jsonschema/tests/test_validators.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,17 +1453,35 @@ def test_enum_allows_empty_arrays(self):
14531453
"""
14541454
Technically, all the spec says is they SHOULD have elements, not MUST.
14551455
1456+
(As of Draft 6. Previous drafts do say MUST).
1457+
14561458
See #529.
14571459
"""
1458-
self.Validator.check_schema({"enum": []})
1460+
if self.Validator in {
1461+
validators.Draft3Validator,
1462+
validators.Draft4Validator,
1463+
}:
1464+
with self.assertRaises(exceptions.SchemaError):
1465+
self.Validator.check_schema({"enum": []})
1466+
else:
1467+
self.Validator.check_schema({"enum": []})
14591468

14601469
def test_enum_allows_non_unique_items(self):
14611470
"""
14621471
Technically, all the spec says is they SHOULD be unique, not MUST.
14631472
1473+
(As of Draft 6. Previous drafts do say MUST).
1474+
14641475
See #529.
14651476
"""
1466-
self.Validator.check_schema({"enum": [12, 12]})
1477+
if self.Validator in {
1478+
validators.Draft3Validator,
1479+
validators.Draft4Validator,
1480+
}:
1481+
with self.assertRaises(exceptions.SchemaError):
1482+
self.Validator.check_schema({"enum": [12, 12]})
1483+
else:
1484+
self.Validator.check_schema({"enum": [12, 12]})
14671485

14681486

14691487
class ValidatorTestMixin(MetaSchemaTestsMixin, object):

0 commit comments

Comments
 (0)