Skip to content

Commit

Permalink
Trust the spec, not the metaschema, on enum.
Browse files Browse the repository at this point in the history
It says that these two conditions are recommendations, but can be
ignored if someone feels like it.

Thanks @Zac-HD.

Refs: python-jsonschema#529
  • Loading branch information
Julian committed Feb 25, 2019
1 parent 21838cd commit 028392a
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 12 deletions.
4 changes: 1 addition & 3 deletions jsonschema/schemas/draft3.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@
"type": "number"
},
"enum": {
"minItems": 1,
"type": "array",
"uniqueItems": true
"type": "array"
},
"exclusiveMaximum": {
"default": false,
Expand Down
4 changes: 1 addition & 3 deletions jsonschema/schemas/draft4.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@
"type": "string"
},
"enum": {
"minItems": 1,
"type": "array",
"uniqueItems": true
"type": "array"
},
"exclusiveMaximum": {
"default": false,
Expand Down
4 changes: 1 addition & 3 deletions jsonschema/schemas/draft6.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@
"propertyNames": { "$ref": "#" },
"const": {},
"enum": {
"type": "array",
"minItems": 1,
"uniqueItems": true
"type": "array"
},
"type": {
"anyOf": [
Expand Down
4 changes: 1 addition & 3 deletions jsonschema/schemas/draft7.json
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@
"const": true,
"enum": {
"type": "array",
"items": true,
"minItems": 1,
"uniqueItems": true
"items": true
},
"type": {
"anyOf": [
Expand Down
16 changes: 16 additions & 0 deletions jsonschema/tests/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1085,6 +1085,22 @@ def test_minItems_invalid_string(self):
# needs to be an integer
self.Validator.check_schema({"minItems": "1"})

def test_enum_allows_empty_arrays(self):
"""
Technically, all the spec says is they SHOULD have elements, not MUST.
See https://github.com/Julian/jsonschema/issues/529.
"""
self.Validator.check_schema({"enum": []})

def test_enum_allows_non_unique_items(self):
"""
Technically, all the spec says is they SHOULD be unique, not MUST.
See https://github.com/Julian/jsonschema/issues/529.
"""
self.Validator.check_schema({"enum": [12, 12]})


class ValidatorTestMixin(MetaSchemaTestsMixin, object):
def test_valid_instances_are_valid(self):
Expand Down

0 comments on commit 028392a

Please sign in to comment.