77import sys
88
99import jsonschema .validators
10+ from referencing import Registry , Resource
11+ from referencing .jsonschema import DRAFT202012
1012
1113
1214def 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):
5557args = parse_args (sys .argv [0 ])
5658
5759path = 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
6372with 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