Skip to content

Commit

Permalink
Merge pull request #62 from cwacek/feature/feature/check-schema-first
Browse files Browse the repository at this point in the history
feature: Use jsonschema to validate the schema itself before load
  • Loading branch information
cwacek authored Nov 18, 2016
2 parents 0b54c41 + d19a6ea commit 88c08b8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 3 additions & 0 deletions python_jsonschema_objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ def __init__(self, schema_uri, resolved={}):
}
)

meta_validator = Draft4Validator(Draft4Validator.META_SCHEMA)
meta_validator.validate(self.schema)
self.validator = Draft4Validator(self.schema,
resolver=self.resolver)


self._classes = None
self._resolved = None

Expand Down
21 changes: 19 additions & 2 deletions test/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,38 @@

import json
import six
import pkg_resources
import jsonschema
import python_jsonschema_objects as pjs

import logging
logging.basicConfig(level=logging.DEBUG)


def test_schema_validation():
""" Test that the ObjectBuilder validates the schema itself.
"""
schema = {
"$schema": "http://json-schema.org/schema#",
"id": "test",
"type": "object",
"properties": {
"name": "string",
"email": {"oneOf": [{"type": "string"}, {"type": "integer"}]},
},
"required": ["email"]
}
with pytest.raises(jsonschema.ValidationError):
pjs.ObjectBuilder(schema)


def test_regression_9():
schema = {
"$schema": "http://json-schema.org/schema#",
"id": "test",
"type": "object",
"properties": {
"name": {"type": "string"},
"email": {"oneOf": ["string", "integer"]},
"email": {"oneOf": [{"type": "string"}, {"type": "integer"}]},
},
"required": ["email"]
}
Expand Down
1 change: 0 additions & 1 deletion test/test_regression_17.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def test_class():
"id": "claimed",
"type": ["string", "integer", "null"],
"description": "Robots Only. The human agent that has claimed this robot.",
"required": False
},
}
}
Expand Down

0 comments on commit 88c08b8

Please sign in to comment.