-
-
Notifications
You must be signed in to change notification settings - Fork 12
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
Provide a helper to fully resolve $refs in a schema #2
Comments
jsonref https://pypi.org/project/jsonref/ resolves references so that you can have fully expanded schemas. |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as outdated.
This comment was marked as outdated.
I think this would be very valuable! To load a schema in from pathlib import Path
from urllib.parse import urljoin
path = Path(path)
# pathlib does not append trailing slashes, but jsonref needs that.
base_dir_url = path.parent.absolute().as_uri() + "/"
base_file_url = urljoin(base_dir_url, path.name)
with path.open("r") as f:
return jsonref.loads(f.read(), base_uri=base_file_url, lazy_load=False) It works fine, but it has some limitations: see gazpachoking/jsonref#60 |
The thing is, this is actually both impossible to do in general (when considering |
Hi @Julian, In our case, we are using this functionality for the same use case as the OP. We are centralising the documentation about some fields in a schema. This helps maintenance a lot, since we are surfacing field descriptions and other things in multiple places:
I am still working on it, and the code is quite complex, but I am loading the schema in this script, and later using it to render the help, title and other aspects of the form's input fields. We happen to use |
Thanks, that helps a little, but I still don't fully follow (I don't think OP shared their own use case originally, they simply asked for the feature). Just to poke further, are the tools you're using otherwise broken with regards to
Is the point that the tool you're using for form generation doesn't properly support following references? And/or VSCode? |
Thanks again.
I could be wrong though. On our end, the tool that we are using to create the form (streamlit) is just a framework to create an arbitrary form. Then it is up to us to define the (i) number of fields in the form, (ii) titles of the input boxes, etc. We want to create as many fields in the form as the schema suggests there are. Hence we rely on the schema to create these input boxes in the form. We want to access the descriptions from the fields in the schema, to be able to label the input boxes accordingly. Since some fields in the schema use So far so good with Not urgent, just suggesting that this feature from Thanks once again. |
I want to generate some documentation/description (probably some input forms) from a json schema that contains
$ref
s. Is there a way in jsonschema to retrieve a json schema with$ref
s resolved and inlined, so I can iterate through the schema?So from a schema like this:
I want to have this structure in my Python object (notice that the
{$ref:...}
section is replaced by the actual definition):I am aware that with self-referencing schemas this will lead to an infinite structure, but hopefully this is feasible with reasonable limitations (eg. excluding self-refs).
The text was updated successfully, but these errors were encountered: