88import os
99from os import listdir
1010from os .path import isdir , join
11+ from pathlib import Path
1112from uuid import uuid4
1213
13- from jsonschema import Draft4Validator , RefResolver
14+ from jsonschema import Draft4Validator , FormatChecker
1415from jsonschema .exceptions import ValidationError
16+ from referencing import Registry
17+ from referencing .jsonschema import DRAFT4
1518
1619from isatools .io import isatab_parser
1720
@@ -38,11 +41,24 @@ def createCEDARjson(self, work_dir, json_dir, inv_identifier):
3841 log .info ("Converting ISA to CEDAR model for {}" .format (work_dir ))
3942 schema_file = "investigation_template.json"
4043 with open (join (CEDAR_SCHEMA_PATH , schema_file )) as json_fp :
41- schema = json .load (json_fp )
42- if schema is None :
44+ investigation_schema = json .load (json_fp )
45+ if investigation_schema is None :
4346 raise IOError ("Could not load schema from {}" .format (join (CEDAR_SCHEMA_PATH , schema_file )))
44- resolver = RefResolver ("file://{}" .format (join (CEDAR_SCHEMA_PATH , schema_file )), schema )
45- validator = Draft4Validator (schema , resolver = resolver )
47+
48+ resources = []
49+ schemas_dir = Path (CEDAR_SCHEMA_PATH )
50+ investigation_schema_path = Path (join (CEDAR_SCHEMA_PATH , schema_file ))
51+
52+ for p in sorted (schemas_dir .glob ("*.json" )):
53+ contents = json .loads (p .read_text (encoding = "utf-8" ))
54+ resource = DRAFT4 .create_resource (contents )
55+ resources .append ((p .resolve ().as_uri (), resource ))
56+
57+ registry = Registry ().with_resources (resources )
58+ main_uri = investigation_schema_path .resolve ().as_uri ()
59+ print (registry .contents (main_uri ))
60+ schema_ref = {"$ref" : main_uri , "$schema" : "http://json-schema.org/draft-04/schema" }
61+ validator = Draft4Validator (schema_ref , registry = registry , format_checker = FormatChecker ())
4662
4763 isa_tab = isatab_parser .parse (work_dir )
4864
@@ -121,7 +137,7 @@ def createCEDARjson(self, work_dir, json_dir, inv_identifier):
121137 study_identifier = ""
122138
123139 try :
124- validator .validate (cedar_json , schema )
140+ validator .validate (cedar_json )
125141 except ValidationError as e :
126142 error_file_name = os .path .join (json_dir , "error.log" )
127143 with open (error_file_name , "w" ) as errorfile :
0 commit comments