-
-
Notifications
You must be signed in to change notification settings - Fork 309
"requiredProperties" keyword #846
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
Is this really the right direction? I started working with JSON Schema at draft 4, so I don't have any details, but does anyone know why Some insight into that decision would probably be helpful here. |
@gregsdennis Boolean "required" didn't work the same way that other keywords worked; it only had meaning in a subschema in certain keywords, mostly "properties". It was nonsensical if used inside e.g. "patternProperties" or "additionalItems", and there's even more considerations, like what if you use it inside "oneOf" or "not"? It also made it more difficult to create composable schemas; referencing a schema that had I actually argued against the change at the time because it was a nice authoring convenience compared to the array form; but I think this is superior to boolean "required" by far. (rewritten from #734 (comment) ) |
While I'd be strongly against changing I want to keep the keyword taxonomy clear, in terms of which keywords behave as applicators, assertions, or annotations. @awwright Adding an object syntax to But My practical concern with the taxonomy has to do with how truly generic implementations could manage plugins for unknown vocabularies. It's too involved to go into at the moment, I just mention it so people know that there's a point other than "Henry likes his own theoretical ideas a lot." (although that is also true). |
@gregsdennis I think Superficially similar keywords like But assertions are intended to assert things about the instance location to which they are applied. Boolean {
"type": "object",
"properties": {
"foo": {
"type": "integer",
"required": true
},
"bar": {
"type": "string"
}
}
} with instance {
"foo": 1,
"bar": "something"
} The root schema gets applied to the whole instance. We look at Now, because of how But let's say we couldn't assume that. We would have to pass the parent object to the child assertion in order to determine the result. Nothing in JSON Schema assertion processing looks up into a parent. Applying a schema to an instance location only involves that location and its children, never the parent. That is not a behavior we should change. |
@awwright are you proposing also that we deprecate |
I think this could be the first of keyword in a vocabulary of helper keywords that address concerns similar to this. It could even be officially supported by the JSON Schema team, but I don't think it belongs in the official specification. |
I imagine @gregsdennis I don't think it would make sense to deprecate |
@awwright There are a number of syntactic sugar proposals, and as @jdesrosiers notes maybe making them an additional vocabulary outside of the Core and Validation specification documents would be a good approach. We would then keep the six vocabularies in those two specifications as minimal as possible. They do have some keywords that are technically unnecessary ( |
Regarding the purity issue, what I'm thinking of (not proposing here- I'll file a separate issue if and when it seems appropriate) is the ability for a vocabulary to indicate which keywords fall into which classifications, and how they interact. Then extensions and generic implementations could be designed around those behaviors. Run in-place applicators first, because some keywords depend on the results of adjacent in-place applicators (at the moment, they specifically name keywords and because there's no generic way to do this with extension applicators). Run assertions when validating. If you're not collecting annotations then you can just ignore those keywords entirely. etc. This is a half-formed idea which is why I haven't filed it, but that's where I'm keeping an eye on purity. A keyword that would need both an applicator hook and an assertion hook seems reasonable when those two behaviors can be modeled separately. Which is the case with So that's why I'm tentatively open to |
Marking this to resolve for draft-09. I've seen this requested enough times to want to make it possible. I'm OK with Edit: I prefer #1144. I've outlined why on the PR in a comment. (Thumbs up were pre-edit) |
My 2 Cents: It is such a common requirement so it would reduce the boilerplate significantly. For example, we generate our schemas in js and so most of our schemas have this at the bottom to work around it: |
Any status on this? |
@racquetmaster It is in the draft-09 milestone for consideration in the next draft. Or as a supplemental vocabulary which would not necessarily need to wait for a whole new draft, and might motivate more people to implement support for supplemental vocabularies. |
Actually it looks like draft-09 was renamed draft-next, presumably because we're not really using the old-style draft numbers anymore. Anyway, I'm increasingly inclined to support doing this somewhere. |
Bump. Any news on this? |
@hheavener-kyd Given it's in the draft-next milestone, we aim to resolve this issue as part of that work. Stay tuned =] |
@hheavener-kyd See #1112 and it's PR #1144. It's an alternative to this keyword that solves the same problem in a better way and it's on track for inclusion in the next release of JSON Schema. It's currently on hold while we focus on getting the patch release finished, but I'm hoping to get it merged once the patch release is out of the way. |
I much prefer #1144 to this proposal. See #1144 (comment) |
When accepting JSON documents for submission, it is frequently the case the documents are objects that have at least one property that is required, such as an ID or name field.
As an authoring convenience, JSON Schema should have a "requiredProperties" keyword that is similar to
"properties"
in that it defines a sub-schema to apply to the respective properties; but in addition, each of those properties must exist, similar to the"required"
keyword.This:
Would be the same as this:
Alternatively, this functionality could be built into the "required" keyword (so that "required" accepts an array or an object). This may even be preferable, since older validators will (usually) bail if they see an object where an array is expected:
Examples of confused users:
This issue is intended to restate and close #659 #681 #734
The text was updated successfully, but these errors were encountered: