Skip to content

Keywords minContains/maxContains #441

Closed
@epoberezkin

Description

@epoberezkin

These keywords will complement the existing keyword contains to define minimum and/or maximum number of items that are valid against the schema in contains keyword (in the same schema object).

Example:

{
  "$comment": "validate that the array contains >= 2 and <= 4 boolean true values",
  "type": "array",
  "items": {"type": "boolean"},
  "contains": {"const": true},
  "minContains": 2,
  "maxContains": 4
}

Meta-schema:

{
  "properties": {
    "minContains": {"type": "number", "minimum": 0, "default": 1},
    "maxContains": {"type": "number"}
  },
  "dependencies": {
    "minContains": ["contains"],
    "maxContains": ["contains"]
  }
}

"minContains": 0 would allow limiting the maximum number of matching elements without requiring one matching element.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions