-
-
Notifications
You must be signed in to change notification settings - Fork 314
Field required based on condition #539
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
@brunodymios this seems to be combining two things:
The first part can be implemented today with {
"properties": {"A": {...}, ...},
"if": {"$comment": "some schema expressing the condition", ...},
"then": {"required": ["A"]}
} The second part is the {
"title": "test",
"type": "object",
"properties": {
"A": { "type": "number" },
"B": { "type": "number" },
"C": { "type": "number" },
},
"if": {
"properties": {
"B": {
"exclusiveMinimum": {
"$data": "1/C"
}
}
}
},
"then": {
"required": [ "A" ],
}
} The That's just an example based on the current I expect If it's OK with you I'd prefer to close this and keep the discussion of So really this just boils down to |
@handrews I know that the roadmap is somehow set and I don't want to open parallel discussions so I'm ok with closing this issue. I've just another question that I think it is related to point 2. What about having a requirement saying that field A must be always equal to field B divided by field C? Is this currently being addressed? Could you in case redirect me to an already existing issue in order to let me follow the discussion? Thank You |
@brunodymios I think that in addition to the basic I don't think there is an issue for expressions built on I'm skeptical about implementing general expressions, but that doesn't mean you shouldn't file it and see what other ideas pop up. BTW, the roadmap isn't very "set". The reason I'm saying it's draft-09 is just that the issues that we're already deep into debating and about to write up into PRs are plenty sufficient for publishing a draft-08 so I don't want to throw another huge topic into that draft. If something else came up to make better to pursue things in a different order, we'll do that. Or if more people are able to manage the debates that will let us work on more things (up to a point, anyway). |
I agree with you @handrews, thanks. I'm going to file the question about general expression as a separated issue, as you suggested. |
Created issue #541 |
I have scenario: Corrrently: it's validating irrespective of addressType value 'Home" and "Mailing", it should validate required fields only if addressType="Home" and should ignore for addressType="Mailing" |
@sreedhar85 This repository is for discussing changes to the specification, if you need assistance with authoring schemas try the mailing list, Slack, IRC, or StackOverflow . Check out the JSON Schema website for more information. |
It is very common to have data structures in which a field becomes required only if a particular condition holds. For example, having a field A being required only if field B has been specified is something easily achievable with draft-07 specification using
dependencies
orif-then-else
constructs.However, very commonly, a field is required only if a particular boolean condition is true. More in general, let's suppose to have numeric fields A, B and C and that field A is required only if B > C.
How to accomplish that? My understanding about draft-07 specification is that this is not possible, however it could be very useful.
I think that the best solution could be to change the current specification of the
required
property:"required": { "$ref": "#/definitions/stringArray" }
to something more complex, supporting the specification of objects instead of a stringArray, giving the possibility to specify boolean conditions. Something like the following:Do you think this makes sufficiently sense to work on it and open a dedicated PR?
Thank You
The text was updated successfully, but these errors were encountered: