-
Notifications
You must be signed in to change notification settings - Fork 57
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
using validators with $ref #814
Comments
This looks like an asdf bug. We "resolve" references to other schemas by loading them up and replacing the node containing the
We're planning to make a 2.7 release sometime within the next couple of weeks. I'll see about getting this fixed in time to include in that release. Incidentally, we implement a custom validator for YAML tags that offers another way to sidestep this issue: type: object
properties:
quantity_prop:
description: |
a simple quantity with custom validator
tag: tag:stsci.edu:asdf/unit/quantity-1.1.0
my_validator: true Instead of including all the quantity schema material in your schema, this checks the tag of the object only, which confirms the object's type without descending into the details. Structuring the schema this way actually saves the quantity object from being validated twice, since it will always be validated against its own schema when asdf recognizes its tag. We don't make use of this technique in the core schemas yet, but lately I've been thinking we should, since validation is the slowest part of opening a file and it would improve performance to not repeat it. |
I was confused about what is going on here. The asdf library only "resolves" ... and the jsonschema code ignores other schema node properties when https://github.com/Julian/jsonschema/blob/v3.2.0/jsonschema/validators.py#L318 Going back to the language from the latest JSON schema draft:
That seems to imply that previous drafts did not allow other keywords in the same schema objects alongside So it seems that this is a Draft 4 behavior that we can't do anything about. @CagtayFabry do you agree with that assessment? This is motivation to bump up to Draft 8 / 2019-09 with ASDF Standard 2.0.0. The only issue is that software support doesn't yet exist for the latest draft, but maybe it will by the time we need it. |
What is the recommended approach to adding validation on properties that are only defined as
$ref
?To give an example:
Let's say I have a property that is supposed to be a
quantity
:Now I have written and registered a simple custom validator called
my_validator
that runs some kind of check (details not important). I want to "trigger" this validation on the above quantity property.My initial approach was rather naive:
Unfortunately the above does no trigger execution of
my_validator
. Does this have something to do with how$ref
is handled internally? Do other entries get dropped when$ref
is "resolved"?The workaround I ended up using was using
allOf
with a custom "empty" object that only triggers the validation. So this works:However I find the first approach more flexible and concise.
The text was updated successfully, but these errors were encountered: