Open dbushong opened 9 months ago
I believe this is due to that RefResolver does not take into account relative references, i.e., its not looking for file relative to the file the reference is coming from. This can be fixed by adding the base location to RefResolver, or by supplying the base location when calling resolver.lookup from API, or even resolving relative locations in API before calling resolver.lookup.
For the simple case of a relative reference from the provided schema file, it does not make a big difference, but fixing it in API keeps changes localized to only API, and not to RefResolver, which I can image is then preferred.
This will, however, only provide a partial solution, because if a file is referenced that has relative references itself, then these subsequent references need to be resolved relative to a new base. So that need fixes by e.g. instantiating new RefResolvers for each external reference, but I cant see what that would do to the caching. Or we need to track the full reference tree somehow in API, and flatten it somehow to a single uri before calling resolver.lookup. But also in that case, I cant oversee the complexity with a combination of absolute and relative references.
A much more fundamental change would be to mimic the complete reference tree in a complete python code tree: every schema source file would generate its own python file, referencing each other in the same way as schema files do. But that would be such a major (breaking) change that that is probably out of scope anyway.
If you run
jsonschema-gentypes
with a path like--json=../path/to/some.json
, and that file has relative$ref
entries in it, resolution will fail.Repro:
Note that it works fine if you don't have
..
in your path