-
-
Notifications
You must be signed in to change notification settings - Fork 333
Closed
Labels
Description
Problem
Although it's very simple, people find it very confusing to understand that the schema
{ "not": { "required": ["foo"] } }
means that if data is an object it should not have property foo.
It is quite common requirement and every time I get asked how to implement it. Somebody suggested to implement a synonym "present" for "required" which makes it easier to read.
If you want to require that multiple properties are absent, than it becomes even more complex, you need to do either
{
"allOf": [
{ "not": { "required": ["foo"] } },
{ "not": { "required": ["bar"] } }
]
}
or
{
"not": {
"anyOf": [
{ "required": ["foo"] },
{ "required": ["bar"] }
]
}
}
Both are verbose and confusing.
Suggestion
Keyword prohibited that is not just the negation of required, but that requires that each property in the list is not present in the object. So both big schemas above would be equivalent to
{ "prohibited": ["foo", "bar"] }