_WrappedReferencingError: Unresolvable: happens unpredictable for file paths #1401
Copy link
Copy link
Closed
Description
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.
def find_refs(json_obj):
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
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 = str(ref.split('#')[0])
path = pathlib.Path(ref)
if not path.exists() and ref.startswith('..'):
path = pathlib.Path(ref.replace('..', '.'))
with open(path.__str__()) as fp:
referenced = json.load(fp)
draft7_resources.append(('/',DRAFT7.create_resource(referenced)))
registry = Registry().with_resources(draft7_resources)
validator = Draft7Validator(base, registry=registry)
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 ?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
Julian commentedon Aug 19, 2025
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.