Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't handle .. paths + ref path resolution properly #850

Open
dbushong opened this issue Feb 5, 2024 · 0 comments
Open

Can't handle .. paths + ref path resolution properly #850

dbushong opened this issue Feb 5, 2024 · 0 comments
Labels
pull request welcome A pull request is welcome to fix this issue

Comments

@dbushong
Copy link

dbushong commented Feb 5, 2024

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:

$ cat base.json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$ref": "sub.json"
}
$ cat sub.json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type":"object",
  "properties": { "x": { "type": "string" } }
}
$ jsonschema-gentypes --json=base.json --python=out.py
Processing base.json
$ cd subdir
$ jsonschema-gentypes --json=../base.json --python=out.py
Processing ../base.json
Traceback (most recent call last):
  File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 417, in get_or_retrieve
    resource = registry._retrieve(uri)
  File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/jsonschema_gentypes/resolver.py", line 83, in _open_uri_resolver
    my_resource = referencing.Resource.from_contents(_open_uri(uri))
  File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/jsonschema_gentypes/resolver.py", line 63, in _open_uri
    with open(uri, encoding="utf-8") as open_file:
FileNotFoundError: [Errno 2] No such file or directory: 'sub.json'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 667, in lookup
    retrieved = self._registry.get_or_retrieve(uri)
  File "/Users/dbushong/.pyenv/versions/3.8.14/lib/python3.8/site-packages/referencing/_core.py", line 424, in get_or_retrieve
    raise exceptions.Unretrievable(ref=uri) from error
referencing.exceptions.Unretrievable: 'sub.json'

Note that it works fine if you don't have .. in your path

@sbrunner sbrunner added the pull request welcome A pull request is welcome to fix this issue label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pull request welcome A pull request is welcome to fix this issue
Projects
None yet
Development

No branches or pull requests

2 participants