-
-
Notifications
You must be signed in to change notification settings - Fork 313
Dynamic enum values based on other values in document #331
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 is related to At some point, it is better to handle more complex relationships in application logic, perhaps keyed to extension keywords of your own, than to get schema validation to do it. At first glance, I would put this proposal in that category. But that's just an initial impression. |
I was going back-and-forth on if this scenario qualified as such. I'm not sure which way it should land. On one hand, this is a flat file and dynamic stuff kind of goes out the scope of a flat file. But on the other hand, in this scenario, all the validation will come from the file itself. In the above example, validation doesn't require any app-specific state or anything like that. All the inputs to the validation are in the file itself. So why not allow the file to validate itself so to speak? I don't know the right answer to that. The fact that there is contemplation of the |
Actually that is a hotly contested decision. It's one of the two big decisions we need to sort out for draft-07:
Once we've made those decisions, figuring out how to implement them and how far to go (e.g. do we add this or not) becomes much simpler. |
|
@handrews from looking at current (?) draft, Our use-case is that we need to perform enum validation in the schema. Every time an instance is validated against a schema, we pull the enum values from database, and then compile the schema. We compile the schema for every request, which is a huge overhead (of course this can be worked around by caching, but it is sub-optimal). |
@gmile |
@handrews noted on |
This sort of request is being comprehensively tracked at #855, where we have consolidated several related ideas. |
Consider the following correct JSON:
And consider the following JSON that one might want to be incorrect:
As far as I can tell - and I very well may just not be seeing it - but I don't think the current spec allows me to define that all items of the
schedule
property must be also present inthings[*].name
. The"C"
in the second JSON should be invalid since it doesn't appear inthings[*].name
. I don't think you can useoneOf
orenum
in this scenario since you don't know beforehand whatthings[*].name
are. They can be anything the user decides, in this case any string.To further illustrate the point, the following schema validates both JSONs.
Assuming I'm not missing anything and the current spec doesn't support this, would this be a worthwhile addition? Or is it outside the scope of this? Is this related to the
$data
discussion that appears to be happening?For the sake of brainstorming what that would look like using
$ref
&oneOf
(which might not be the best option):The text was updated successfully, but these errors were encountered: