Skip to content

Commit

Permalink
updated validate script to use referencing library
Browse files Browse the repository at this point in the history
  • Loading branch information
jtauber committed Feb 6, 2024
1 parent 12b2951 commit c546528
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions code/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/'
Expand All @@ -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__':
Expand Down

0 comments on commit c546528

Please sign in to comment.