Skip to content

Commit

Permalink
Use jsonschema draft-6
Browse files Browse the repository at this point in the history
For now, this needs the pre-release version of jsonschema:
* python-jsonschema/jsonschema#337
* https://pypi.org/project/jsonschema/#history
  • Loading branch information
tobywf committed Sep 12, 2018
1 parent 1b1be68 commit 1b059cd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ tool.)
virtualenv -p python3 env
source env/bin/activate
pip install --upgrade --pre jsonschema
pip install -r requirements.txt
pip install -e .
Expand Down
1 change: 1 addition & 0 deletions buildspec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ phases:
pre_build:
commands:
- pip install --upgrade pip wheel -r requirements.txt .
- pip install --upgrade --pre jsonschema
build:
commands:
- isort --check-only --verbose --recursive "setup.py" "run_lint" "uluru/" "tests/"
Expand Down
15 changes: 8 additions & 7 deletions uluru/data_loaders.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import json
import logging

import jsonschema
import pkg_resources
import yaml
from jsonschema import Draft6Validator
from jsonschema.exceptions import ValidationError

LOG = logging.getLogger(__name__)

Expand All @@ -22,10 +23,10 @@ def load_resource_spec(resource_spec_file):
) as f:
resource_spec_schema = json.load(f)

validator = Draft6Validator(resource_spec_schema)
try:
jsonschema.validate(resource_spec, resource_spec_schema)
# the unit tests should catch `SchemaError`/if the schema is invalid
except jsonschema.exceptions.ValidationError as e:
validator.validate(resource_spec)
except ValidationError as e:
LOG.error(
"The resource provider definition is invalid: %s", e.message # noqa: B306
)
Expand Down Expand Up @@ -57,10 +58,10 @@ def load_project_settings(plugin, project_settings_file):
"to further customize code generation."
)

validator = Draft6Validator(plugin.project_settings_schema())
try:
jsonschema.validate(project_settings, plugin.project_settings_schema())
# the unit tests should catch `SchemaError`/if the schema is invalid
except jsonschema.exceptions.ValidationError as e:
validator.validate(project_settings)
except ValidationError as e:
LOG.error("The project settings are invalid: %s", e.message) # noqa: B306
raise # TODO: error handling

Expand Down

0 comments on commit 1b059cd

Please sign in to comment.