diff --git a/code/validate.py b/code/validate.py index 69fb3e0..6e6e155 100755 --- a/code/validate.py +++ b/code/validate.py @@ -3,10 +3,7 @@ import os.path import json import jsonschema - - -if int(jsonschema.__version__.split('.', 1)[0]) < 3: - raise RuntimeError("Please update jsonschema to 3.0.0 or later.") +from referencing import Registry, Resource schema_uri_prefix = 'https://burrito.bible/schema/' @@ -20,20 +17,16 @@ def http_handler(uri): assert uri.startswith(schema_uri_prefix) path = uri[len(schema_uri_prefix):].replace('/', os.sep) path = os.path.join(schema_dir, path) - return json.load(open(path, encoding='utf-8')) + return Resource.from_contents(json.load(open(path, encoding='utf-8'))) -resolver = jsonschema.RefResolver( - handlers={'http': http_handler, 'https': http_handler}, - referrer=schema, - base_uri='file://' + schema_dir.replace('\\', '/') + '/', -) +registry = Registry(retrieve=http_handler) def validate(input): "Validates the given file-like object against the schema." data = json.load(input) - jsonschema.validate(data, schema, resolver=resolver) + jsonschema.validate(data, schema, registry=registry) if __name__ == '__main__':