Skip to content

How to apply constraint on the basis of count of properties? #586

Discussion options

You must be logged in to vote

It works. It expresses the constraint, "if there is at least one property (minProperties: 1), then the '0' property is required".

If this doesn't work for you, the validator you're using probably doesn't support the if/then keywords.

"Steps": {
  "type": "object",
  "patternProperties": {
    "^[0-9]$|^[1-9][0-9]$": { "type": "object" }
  },
  "additionalProperties": false,

  "if": { "minProperties": 1 },
  "then": { "required": [ "0" ] }
}

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
2 replies
@gregsdennis
Comment options

@girish-tharwani
Comment options

Comment options

You must be logged in to vote
3 replies
@girish-tharwani
Comment options

@jdesrosiers
Comment options

Answer selected by girish-tharwani
@girish-tharwani
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants