Skip to content

Commit 4fab8fc

Browse files
committed
Remove deprecated jsonschema.validators.RefResolver
Apparently it's better to make everything 100 times more complicated
1 parent 4493034 commit 4fab8fc

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

.github/workflows/linux.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ jobs:
266266
cd build
267267
ctest --output-on-failure
268268
269-
python3 -m pip install jsonschema
269+
python3 -m pip install jsonschema referencing
270270
cd ../share/openPMD/json_schema
271271
PATH="../../../build/bin:$PATH" make -j 2
272272
# We need to exclude the thetaMode example since that has a different

share/openPMD/json_schema/check.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import sys
88

99
import jsonschema.validators
10+
from referencing import Registry, Resource
11+
from referencing.jsonschema import DRAFT202012
1012

1113

1214
def parse_args(program_name):
@@ -39,9 +41,9 @@ def parse_args(program_name):
3941

4042
parser.add_argument(
4143
'--schema_root',
42-
default=script_path / 'series.json',
44+
default=script_path,
4345
help="""\
44-
The .json file describing the root file of the schema to validate against.
46+
Directory where to resolve JSON schema files to validate against.
4547
"""
4648
)
4749
parser.add_argument('openpmd_file',
@@ -55,16 +57,24 @@ def parse_args(program_name):
5557
args = parse_args(sys.argv[0])
5658

5759
path = Path(os.path.dirname(os.path.realpath(args.schema_root)))
58-
resolver = jsonschema.validators.RefResolver(
59-
base_uri=f"{path.as_uri()}/",
60-
referrer=True,
61-
)
60+
61+
62+
def retrieve_from_filesystem(uri):
63+
filepath = args.schema_root / uri
64+
with open(filepath, "r") as referred:
65+
loaded_json = json.load(referred)
66+
return Resource.from_contents(
67+
loaded_json, default_specification=DRAFT202012)
68+
69+
70+
registry = Registry(retrieve=retrieve_from_filesystem)
6271

6372
with open(args.openpmd_file[0], "r") as instance:
73+
loaded_instance = json.load(instance)
6474
jsonschema.validate(
65-
instance=json.load(instance),
75+
instance=loaded_instance,
6676
schema={"$ref": "./series.json"},
67-
resolver=resolver,
77+
registry=registry,
6878
)
6979
print("File {} was validated successfully against schema {}.".format(
7080
instance.name, args.schema_root))

0 commit comments

Comments
 (0)