|
|
|
@ -42,6 +42,12 @@ except ImportError as e:
|
|
|
|
|
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import referencing
|
|
|
|
|
except ImportError as e:
|
|
|
|
|
import_error("referencing", "referencing", "referencing", e)
|
|
|
|
|
raise
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import yaml
|
|
|
|
|
except ImportError as e:
|
|
|
|
@ -70,10 +76,12 @@ class SchemaDirReport:
|
|
|
|
|
self.errors += other_report.errors
|
|
|
|
|
|
|
|
|
|
def check_example(path, schema, example):
|
|
|
|
|
# URI with scheme is necessary to make RefResolver work.
|
|
|
|
|
# $id as a URI with scheme is necessary to make registry resolver work.
|
|
|
|
|
fileurl = "file://" + os.path.abspath(path)
|
|
|
|
|
resolver = jsonschema.RefResolver(fileurl, schema, handlers={"file": helpers.load_file_from_uri})
|
|
|
|
|
validator = jsonschema.Draft202012Validator(schema, resolver)
|
|
|
|
|
schema["$id"] = fileurl
|
|
|
|
|
|
|
|
|
|
registry = referencing.Registry(retrieve=helpers.load_resource_from_uri)
|
|
|
|
|
validator = jsonschema.validators.Draft202012Validator(schema, registry=registry)
|
|
|
|
|
|
|
|
|
|
validator.validate(example)
|
|
|
|
|
|
|
|
|
@ -128,7 +136,7 @@ def check_schema_file(schema_path):
|
|
|
|
|
|
|
|
|
|
# Check schema is valid.
|
|
|
|
|
try:
|
|
|
|
|
validator = jsonschema.Draft202012Validator
|
|
|
|
|
validator = jsonschema.validators.Draft202012Validator
|
|
|
|
|
validator.check_schema(schema)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
print(f"Failed to validate JSON schema: {e}")
|
|
|
|
|