7
7
import sys
8
8
9
9
import jsonschema .validators
10
+ from referencing import Registry , Resource
11
+ from referencing .jsonschema import DRAFT202012
10
12
11
13
12
14
def parse_args (program_name ):
@@ -39,9 +41,9 @@ def parse_args(program_name):
39
41
40
42
parser .add_argument (
41
43
'--schema_root' ,
42
- default = script_path / 'series.json' ,
44
+ default = script_path ,
43
45
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.
45
47
"""
46
48
)
47
49
parser .add_argument ('openpmd_file' ,
@@ -55,16 +57,24 @@ def parse_args(program_name):
55
57
args = parse_args (sys .argv [0 ])
56
58
57
59
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 )
62
71
63
72
with open (args .openpmd_file [0 ], "r" ) as instance :
73
+ loaded_instance = json .load (instance )
64
74
jsonschema .validate (
65
- instance = json . load ( instance ) ,
75
+ instance = loaded_instance ,
66
76
schema = {"$ref" : "./series.json" },
67
- resolver = resolver ,
77
+ registry = registry ,
68
78
)
69
79
print ("File {} was validated successfully against schema {}." .format (
70
80
instance .name , args .schema_root ))
0 commit comments