-
-
Notifications
You must be signed in to change notification settings - Fork 266
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
Require all described properties. #562
Comments
@lordcheeto thanks! That's an interesting use case. We're currenlty hashing out a new keyword which almost does what you want: #556, except it sees through any applicability keywords, which a common issue when using This is a use case we hadn't considered. Pretty clear I think. |
@lordcheeto as @Relequestual notes, #556's Let's have this issue focus on the Would you be OK with us changing the title to something like "require all described properties"? I'm guessing you got |
Agreed re what to call the keyword if we move forward with this. Could be something like |
Actually let's get confirmation from @lordcheeto as we may be assuming something more complex than they meant to request! Given this schema: {
"properties": {
"a": {...},
"b": {...}
},
"oneOf": [
{
"properties": {
"c": {"const": true},
"d": {...}
}
},
{
"properties": {
"c": {"const": false},
"e": {...}
}
}
],
"newKeywordHere": true
} Does this only cause "a" and "b" to be required, or does it also cause "c" and either "d" or "e" (depending on the value of "c") to be required? |
Just looked through the proposal on So, while I was imagining a combination keyword, I like @handrews' suggestion of focussing on just the My original language for the proposal said something to the effect that it would apply to all objects in its "scope". Slightly modifying your example: {
"properties": {
"a": {...},
"b": {...}
},
"oneOf": [
{
"properties": {
"c": {"const": true},
"d": {...}
}
},
{
"properties": {
"c": {"const": false},
"e": {...}
},
"newKeywordHere": false
}
],
"newKeywordHere": true
} Added an additional I removed the "scope" language from my proposal because I'm not aware of any current keywords that operate on the scope like this. Perhaps the annotation collection mechanism described in #530 could be used for this? I haven't really wrapped my mind around that yet. I'm also not sure how or if it should operate across As for what to call the keyword, I'll change the title, and I'll further describe my use case in another comment. |
@lordcheeto thanks! Yeah, for the scope thing #530 annotations might work. I haven't entirely wrapped my head around it either and I came up with the idea :-) I want to be a bit cautious about using such a new and different mechanism, but at the same time, finding real problems that are also solved by it (other than Thanks for explaining the scopes more, that's an interesting idea. One of the things we're trying to clarify is where to put the boundary between things that really need to be in a standard vocabulary, and things that can go in extensions. So we're doing some work (#561, #563, #564) to figure out a better story around extensions and interoperability. Right now no one really wants to do extensions because they're not interoperable at all. Once that's settled, we may decided that a concept like scopes fits into the general keyword model, but is better done as an extension. Maybe even a "feature" extension of some sort. Let's keep kicking the ideas around here, although this probably won't go into the immediate next draft. Although if we settle on a clear consensus we can move it up, certainly. |
As a comment, I think that Also, the SO link included a comment: https://stackoverflow.com/questions/30868023/json-schema-require-all-properties#comment79419830_30868023
Sounds reasonable to me! I thought of this but don't think I mentioned it. |
My use of JSON Schema may be different than what has been considered before, so I thought I'd detail it. I'm working on a library to consume a third party JSON WebAPI. Since I don't control the API, I want to be able to ensure that the JSON returned does not change. If properties are removed, that could be a breaking change. If properties are added, that would be a non-breaking change, but I'd want to know about the newly exposed functionality. I've been writing schemas for the endpoints to describe exactly the responses I'm receiving from the API, with the plan being to set up a cron job to validate the responses against the schema occasionally and alert me to any changes. Some of these endpoints return a lot of properties, so something like this would make the resulting schema much more compact. |
Looks like this was proposed some time ago: https://github.com/java-json-tools/json-schema-validator/wiki/v5%3A-strictProperties |
@lordcheeto there have been several proposals at least somewhat like this, and @awwright consolidated them all in #846. I'm going to close this issue in favor of that one, if you notice anything that isn't covered by the ideas in that issue, please comment over there. |
This keyword indicates that the object must adhere strictly to the defined schema. That is, all defined properties required, and no additional properties allowed.
Example:
Which would be equivalent to the following schema.
While not a huge issue in this trivial example, it would allow objects with many required properties to be expressed less verbosely, and allow for clearer communication of the author's intention.
The text was updated successfully, but these errors were encountered: