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:
"properties": {
"foo_bar": {
"$ref": "#/definitions/FooBar"
},
"Gender": {
"$ref": "#/definitions/Gender"
},
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(stream if type(stream) == 'str' else self.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.
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.dirnamecall 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: