Replies: 3 comments 2 replies
-
Hi there, I don't believe there are any open issues related to this type of question specifically. Resolving to files should work fine as long as your references are actually valid JSON Schema. There's docs and examples here. If you're having issues please include a full reproducer (i.e. something I can run.). |
Beta Was this translation helpful? Give feedback.
-
Hi there, thanks for that link it slipped through for me. I currently struggle loading a bunch of schema files with that example, will try again tomorrow |
Beta Was this translation helpful? Give feedback.
-
@Julian looked at the example and it is difficult to debug and does not do anything when having a bunch of schemas in the schemas folder. Registry is always <Registry (0 resources)> for me. doesn't it mixup paths and files !? for me loading referenced schemas worked with def find_refs(json_obj): """Find all $ref values in Draft 7 schema.""" refs = [] if isinstance(json_obj, dict): if '$ref' in json_obj: ref = str(json_obj['$ref']) if not ref.startswith('#'): refs.append(json_obj['$ref']) # Recursively check all dictionary values for key, value in json_obj.items(): refs.extend(find_refs(value)) elif isinstance(json_obj, list): for item in json_obj: refs.extend(find_refs(item)) return refs schema_path = './test_schema.json' with open(schema_path) as fp: base = json.load(fp) base_resource = DRAFT7.create_resource(base) draft7_resources = [('/', base_resource)] refs = find_refs(base) refs = set(refs) for ref in refs: if '#' in ref: ref_path = str(ref.split('#')[0]) path = pathlib.Path(ref_path) if not path.exists() and ref_path.startswith('..'): path = pathlib.Path(ref_path.replace('..', '.')) with open(path.__str__()) as fp: referenced = json.load(fp) draft7_resources.append((ref,DRAFT7.create_resource(referenced))) registry = Registry().with_resources(draft7_resources) that gives me all refs look in my case like "$ref": "../DIRECTORY/json_schema.json#SOME_DEFINITION_ROOT". print(registry.contents("../DIRECTORY/json_schema.json#SOME_DEFINITION_ROOT") However validation file_name = "./test_data.json" with open(file_name) as fp: data = json.load(fp) validator = Draft7Validator(base, registry=registry) result = validator.is_valid(data) still fails with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
As refresolver is deprecated I tried to work around it by iterating a base scheme for all nested ref links.
In our case usually some relative path to another schema like
"properties": { "address": { "$ref": "../address/json_schema.json#/definitions/address" } },
here the very basic code which actually works fine for very small cases.
and than this
result = validator.is_valid(data)
fails sometimes with _WrappedReferencingError: Unresolvable
the docs only mention direct links to http based jsonschemas.
there are quite some issues open around that question
What would be the correct way to handle nested file references in json schemas before validation ?
Beta Was this translation helpful? Give feedback.
All reactions