-
-
Notifications
You must be signed in to change notification settings - Fork 590
Unable to use subschemas for validation (fragment/anchor) #931
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
Comments
This comment was marked as off-topic.
This comment was marked as off-topic.
@MatthewNielsen27 I still fail to see how can I use an anchored url to validate an instance. Everywhere I see a schema being used, is just a JSON data, without and reference. |
This comment was marked as off-topic.
This comment was marked as off-topic.
I managed to unblock myself by writing a script the splits our combined schema in separated files, ones that are compatible with this library. See https://github.com/ansible/schemas/blob/main/src/update-schemas.py#L65-L86 So basically now users have two options: either use the combined schema with anchors or use standalone ones. I was lucky because I used a relatively flat design. All reused definitions are at the root level I still need to add some code that strips definitions that are not needed for current file, but that is just and optimization for reducing the file-size. |
I still honestly don't really feel I have enough to look into this, and @MatthewNielsen27 I'm not really sure you're talking about the same issue, but it's hard to tell. Whether All the rest here is tied up with things not related to the specification or this library, so while I want to help, I can't do that yet until I know what thing is using this library and how -- right now the ansible schemas are not really schemas, they're the VSCode thing. How can I reproduce what you're seeing @ssbarnea, even if the only instructions you have right now involve VSCode or whatever tool is using the files you're talking about? |
@Julian Hi and thanks for the reply. All the files from https://github.com/ansible/schemas/tree/main/f are valid JSON Schemas. If you spotted something that makes them not be such, please let me know, I am quite curious. All of them have an What I was trying to explain that is not working with current validator is the ability to use an anchored URL to validate a document. That is something that works with other validators but it does not with our python library. To give a specific example, This first one is an URL without an anchor and that works with jsonschema, but the other one does not. I will try to write a longer article about how to use various tools when developing schemas that should explain it better. I hope the weekend will allow me to do it. I really need to do this because that info is useful for others too. Still, if you want a hands-on experience I would also be happy to show you how I do various stuff on a meet/zoom session, we might both learn new tricks. |
Yes, all of these certainly seem valid at a glance -- what I'm saying is what do you mean by:
What code are you running to do this, or what tool are you using to do it? |
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 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 off-topic.
This comment was marked as off-topic.
Happy to look at this if/when you've got something I can use to reproduce whatever behavior you're referring to! |
Most JSON Schema validators allow use of a subschema to validate a file but I was not able to find a way to do that using python-jsonschema.
To example it, a subschema reference is something like
http://example.com/app.schema.json#/definitions/foo
. That URI tells the loader that the schema to be used is not at root of the JSON object, and instead is as a sublevel.You can see a live example at https://github.com/SchemaStore/schemastore/blob/master/src/api/json/catalog.json#L222 or https://github.com/ansible/schemas#schema-bundle where you can see two subschema urls.
Keep in mind that that the subschema is not just a sub-json document as it self in can reference definitions from the entire file, so you cannot just handle the subdocument as a full schema.
Is there a way to do this with python-jsonschema?
PS. I know for sure that ajv works fine with subschemas, and also vscode json and yaml extensions. All of these can load and use schemas using the fragment URIs.
The text was updated successfully, but these errors were encountered: