Skip to content

How to add dependency #485

Closed Answered by CarstenWickner
vicky-blr asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @vicky-blr,

This sounds more like a general question regarding JSON Schema than how to produce that with the generator library. 😃
For that, I suggest you have a look at: https://tour.json-schema.org/content/05-Conditional-Validation/04-if-then-keyword
By swapping the if and then subschema in their lesson's example you'd get pretty close to what you're describing as your use case:

{
  "type": "object",
  "properties": {
    "A": {"type": "boolean"}
  },
  "if": { "required": ["B"] },
  "then": { "properties": { "A": { "const": true } }, "required": ["A"] },
}

I favor this alternative though: https://tour.json-schema.org/content/05-Conditional-Validation/03-Conditionally-Apply-a-Subschema

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by CarstenWickner
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