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
$ref attribute #23
Comments
Hi there! I am ultimately, but we haven't had a personal need for it yet, and, even though the entire JSON Schema draft spec is quite confusingly written, |
Get it, |
Sure thing, hope it's otherwise useful to you. You can leave this open, maybe it will motivate this to happen :). |
Hmm, I started implementing $ref for local json-pointers (as that much support would allow at least the meta-schema to be fully validated,) but realized that validate_ref does not have access to the root schema to look up the reference. Any ideas on how that should be handled? |
Add unit tests for $ref as json-pointer. refs python-jsonschema#23
Well, got it working at least. I'm not so wild about the root schema hack though, let me know if you think of something better, or of any other issues before I issue a pull request. |
Another thing I was wondering while writing this: is ignoring a non-applicable property the correct behavior? If so, I also fixed a bug with the dependencies validator I wrote in this branch. What I mean: {
"dependencies": {
"foo": "bar"
}
} validate an instance that is not of type "object"? |
Oy, yes that is hairy. I'll have to checkout and play with it a little bit to see if anything comes to me. And yes, I agree that |
What if Validator objects got passed the schema on init and kept it? This would make it easy for validator methods to get at the root of the schema. This would also mean that metavalidation could be done once, and the Validator object would be safely reusable without repeating it. EDIT: A set_schema(self, meta_validate=True) method could also be added to change the schema after creation. EDIT2: This would also allow easy implementation of $ref support for inline addressing. |
That'd work, not sure how much I like it, but no matter what it'd constitute an API change and would require a deprecation, where we'd anyways need to implement things as-is to satisfy that. So I'd like to avoid that if possible unless it's unavoidable or overwhelmingly convincing. |
My main case for this is that it seems there are a few actions that should only be done once, at the first load of the schema. Meta validation would be one of them, and scanning the schema for |
That sounds reasonable (that there might be things that should be done when validation starts, and only once), but I take the first call to Right now, as you can tell, |
If we assume that the first call to Do you have any alternate ideas on how we can accomplish this only-once stuff? |
Maybe if we have a separate method for iter_errors to be called externally than used for internal recursive stuff. When the external one was called, it would do the once-only work. The next time it was called, the new schema could be compared to the last one validated, and once-only work skipped if they are the same. EDIT: like this def iter_errors(self, instance, schema, meta_validate=True):
if schema != self._schema:
self._once_only(schema, meta_validate=meta_validate)
self._iter_errors(instance, schema) |
Well I'm not totally disagreeing :). The problems are definitely related to The way the objects are, I see So, I think we should go ahead with what you have in mind – deprecating |
I updated my branch a bit with these ideas. I separated iter_errors and is_valid to two different methods, one for internal sub-schema validation, and one for external calls to the Validator. The internal one takes schema as an argument, the external doesn't. These could be combined again to make schema an optional argument if you think that is more appropriate. |
This looks OK more or less, but I think after a bit of thought now is as good a time as any to introduce a Oh and the reason why I'd like it to be an optional arg is because the "internal" |
I already made a |
Ok, I updated the draft 4 branch with recent changes, and added in $ref support. Not sure if we need to change anything else with regards to how the Draft3Validator class is used. |
I'd like to pull in just the addition of Draft3Validator without |
Yeah, the draft 4 stuff certainly isn't ready to be merged in yet, but it should be pretty clean to just cut that stuff out. |
Ok, I made another branch https://github.com/gazpachoking/jsonschema/tree/draft_3_noref without the ref or draft 4 changes (and your latest master changes). I also made https://github.com/gazpachoking/jsonschema/tree/draft_3 branch which includes ref, but not draft 4 stuff. Turns out I'm not super awesome at git branching yet, so I hope I did everything right. :P EDIT: Also, I didn't update the readme yet, and some docstrings may still need tweaking. |
Cool thanks :). As you might be able to tell, those small refactorings are gonna make the rename easier to test, so hopefully today or tomorrow I'll look at getting this merged. |
OK, I did a bit more than just merging ;), but what I've done should make things a bit easier to work with. Take a look at the current HEAD and see if you've got more ideas. |
Looks good to me, I like all your changes. Only thing I was wondering about was why Validator.init takes _args and *_kwargs. Why not just accept |
No particular reason. Mostly the args that you do see there are the ones I removed from |
Local refs, non local (url refs) and pre-cached url refs. Think that covers everything right? If so, think this is done. Try out HEAD and feel free to re-open if I missed something. |
Hello Julian,
Are you planning to implement support of $ref attribute in your library?
$ref attribute gives a lot of flexibility in building schemas for validating dynamic JSONs.
Thanks.
The text was updated successfully, but these errors were encountered: