You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a JSON schema generated by pydantic. It contains multiple object definitions all in one file. https://pydantic-docs.helpmanual.io/usage/schema/ contains a good example of the generated schema.
This schema references its own object definitions like this:
sphinx-json-schema doesn't handle this style of reference, and there are two bugs involved:
Relative links are resolved relative to the base directory of the file being loaded, rather than the file itself. This is because of the os.path.dirname call at
os.path.dirname(streamiftype(stream) =='str'elseself.file), value
If I correct this by changing the refs to be "$ref": "./MyFile.json#/definitions/FooBar" then the code causes infinite recursion. This is because it tries to keep parsing the same file over and over again.
I spent a few minutes trying to fix this, got a little stuck and I'm wondering about two things:
have you considered using URL infrastructure for all resolving? If you pass a base URL of file:///path/to/file then you can use standard URL infrastructure (urllib.parse.urljoin) to resolve URL references, without having to explicitly check for http:
Have you looked into using an existing ref-resolver library? At a quick glance, jsonschema.RefResolver appears to do a lot of what you need here relatively simply.
The text was updated successfully, but these errors were encountered:
First, thanks for the tool!
I have a JSON schema generated by pydantic. It contains multiple object definitions all in one file. https://pydantic-docs.helpmanual.io/usage/schema/ contains a good example of the generated schema.
This schema references its own object definitions like this:
sphinx-json-schema doesn't handle this style of reference, and there are two bugs involved:
os.path.dirname
call atsphinx-json-schema/sphinx_json_schema/loader.py
Line 74 in df5e10b
"$ref": "./MyFile.json#/definitions/FooBar"
then the code causes infinite recursion. This is because it tries to keep parsing the same file over and over again.I spent a few minutes trying to fix this, got a little stuck and I'm wondering about two things:
The text was updated successfully, but these errors were encountered: