Skip to content

Commit

Permalink
Use jsonschema ≥4.18.0 and new referencing library
Browse files Browse the repository at this point in the history
In v4.18.0, jsonschema.RefResolver was deprecated in favor of the new
referencing library.¹ The intro² and API³ docs were helpful in
determining the necessary changes.

I've tested that our new usage is not backwards compatible with v4.17.3,
so I've updated the minimum requirement to v4.18.0.

Mismatches are now a "PointerToNowhere" error instead of an
"Unresolvable JSON pointer" error. It shows the entire schema JSON in
the output which can seem unnecessarily verbose, but I think it's fine
since this is only intended to show on internal errors with the schema.

¹ https://github.com/python-jsonschema/jsonschema/blob/93e0caa5752947ec77333da81a634afe41a022ed/CHANGELOG.rst#v4180
² https://python-jsonschema.readthedocs.io/en/stable/referencing/#introduction-to-the-referencing-api
³ https://referencing.readthedocs.io/en/stable/api/#referencing.Registry.with_contents
  • Loading branch information
victorlin committed Dec 5, 2024
1 parent 4088b0d commit 0292963
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions augur/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import jsonschema.exceptions
import re
from itertools import groupby
from referencing import Registry
from textwrap import indent
from typing import Iterable, Union
from augur.data import as_file
Expand Down Expand Up @@ -48,8 +49,8 @@ def load_json_schema(path, refs=None):
for k, v in refs.items():
with as_file(v) as file, open_file(file, "r") as fh:
schema_store[k] = json.load(fh)
resolver = jsonschema.RefResolver.from_schema(schema,store=schema_store)
schema_validator = Validator(schema, resolver=resolver)
registry = Registry().with_contents(schema_store.items())
schema_validator = Validator(schema, registry=registry)
else:
schema_validator = Validator(schema)

Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"cvxopt >=1.1.9, ==1.*",
"importlib_resources >=5.3.0; python_version < '3.11'",
"isodate ==0.6.*",
"jsonschema >=3.0.0, ==3.*",
"jsonschema >=4.18.0, ==4.*",
"referencing >=0.30.0",
"networkx >= 2.5, <4",
"numpy ==1.*",
"packaging >=19.2",
Expand Down

0 comments on commit 0292963

Please sign in to comment.