diff --git a/README.rst b/README.rst index a0ecdffb..70dc4fef 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/buildspec.yml b/buildspec.yml index 0bd2ab23..4f06d230 100644 --- a/buildspec.yml +++ b/buildspec.yml @@ -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/" diff --git a/uluru/data_loaders.py b/uluru/data_loaders.py index fea9ecd9..48147946 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