Skip to content

Commit

Permalink
Updated test for a safer version of Draft202012.
Browse files Browse the repository at this point in the history
  • Loading branch information
gaurav committed Sep 16, 2021
1 parent e409986 commit bde8ace
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tests/test_validate_artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,19 @@ def test_validate_json_schema(self):
assert_that(json_schema_file_path).exists().is_file()

with open(json_schema_file_path) as f:
json_schema = json.load(f)
try:
json_schema = json.load(f)
except json.JSONDecodeError as e:
fail(f'JSON Schema {json_schema_file_path} is not a valid JSON document: {e}')

assert_that(json_schema).is_not_empty()

# Idea from https://github.com/Julian/jsonschema/issues/348#issuecomment-647418176
class SaferDraft202012Validator(jsonschema.Draft202012Validator):
META_SCHEMA = {**jsonschema.Draft202012Validator.META_SCHEMA, "additionalProperties": False}

try:
jsonschema.Draft7Validator.check_schema(json_schema)
SaferDraft202012Validator.check_schema(json_schema)
except jsonschema.exceptions.SchemaError as e:
fail(f'JSON Schema {json_schema_file_path} is not valid: {e}')
fail(f'JSON Schema {json_schema_file_path} is not a valid JSON Schema: {e}')

0 comments on commit bde8ace

Please sign in to comment.