Skip to content

Validation: Keyword to express not: required for multiple properties #213

@epoberezkin

Description

@epoberezkin

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"] }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions