From edc022017f75231c5bbf96ed1a20e0eb242acaa4 Mon Sep 17 00:00:00 2001 From: Toby Fleming Date: Wed, 12 Sep 2018 14:23:09 -0700 Subject: [PATCH] Use jsonschema draft-6 For now, this needs the pre-release version of jsonschema: * https://github.com/Julian/jsonschema/issues/337 * https://pypi.org/project/jsonschema/#history --- README.rst | 1 + uluru/data_loaders.py | 15 ++++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index a0ecdffb2..70dc4fef1 100644 --- a/README.rst +++ b/README.rst @@ -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 . diff --git a/uluru/data_loaders.py b/uluru/data_loaders.py index fea9ecd9c..481479462 100644 --- a/uluru/data_loaders.py +++ b/uluru/data_loaders.py @@ -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__) @@ -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 ) @@ -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