Skip to content

Implementing a constraint inside $def using the field value from a higher level schema #598

Discussion options

You must be logged in to vote

There's no way to write constraints that make use of values "above" it in the JSON tree. You have to put your if/then at a level high enough that every value involved is below the if/then.

"if": {
  "properties": {
    "fieldA": { "const": true }
  },
  "required": ["fieldA"]
},
"then": {
  "properties": {
    "fieldB": {
      "properties": {
        "fieldD": { "minItems": 1 }
      }
    }
  }
}

Notice the nested subschemas in then to drill down from the top level to fieldD.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@girish-tharwani
Comment options

Answer selected by girish-tharwani
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants