title: Json-schema required/non-required & allowed valeus for fields depend on the values of other fields
body: <p>I have three fields, foo, bar, baz. bar depends on foo, baz depends on bar:</p>
  <ol>
  <li>foo is bool</li>
  <li>if foo is not provided bar &amp; baz are forbidden</li>
  <li>foo = true: bar is required enum with values bar1 &amp; bar2</li>
  <li>foo = false: bar &amp; baz are forbidden</li>
  <li>foo = true &amp; bar = bar1: baz is a required object with required field baz1 and non-required field baz2 both string</li>
  <li>foo = true &amp; bar = bar2: baz is a required object with required field baz3 string</li>
  </ol>
  <p>So I started building this iteratively. So far, I've got</p>
  <pre><code>{
    &quot;$schema&quot;: &quot;http://json-schema.org/draft-07/schema#&quot;,  
    &quot;type&quot;: &quot;object&quot;,
    &quot;properties&quot;: {
      &quot;foo&quot;: {
        &quot;type&quot;: &quot;boolean&quot;
      }
    },
    &quot;allOf&quot;: [
      {
        &quot;if&quot;: {
          &quot;not&quot;: {
            &quot;required&quot;: [&quot;foo&quot;]
          }
        },
        &quot;then&quot;: {
          &quot;not&quot;: {
            &quot;required&quot;: [&quot;bar&quot;, &quot;baz&quot;]
          }
        }
      },
      {
        &quot;if&quot;: {
          &quot;properties&quot;: {
            &quot;foo&quot;: {
              &quot;const&quot;: true
            }
          },
          &quot;required&quot;: [&quot;foo&quot;]
        },
        &quot;then&quot;: {
          &quot;properties&quot;: {
            &quot;bar&quot;: {
              &quot;enum&quot;: [&quot;bar1&quot;, &quot;bar2&quot;]
            }
          },
          &quot;required&quot;: [&quot;bar&quot;]
        }
      },
      {
        &quot;if&quot;: {
          &quot;properties&quot;: {
            &quot;foo&quot;: {
              &quot;const&quot;: false
            }
          },
          &quot;required&quot;: [&quot;foo&quot;]
        },
        &quot;then&quot;: {
          &quot;not&quot;: {
            &quot;required&quot;: [&quot;bar&quot;, &quot;baz&quot;]
          }
        }
      },
      {
        &quot;if&quot;: {
          &quot;properties&quot;: {
            &quot;bar&quot;: {
              &quot;const&quot;: &quot;bar1&quot;
            }
          },
          &quot;required&quot;: [&quot;bar&quot;]
        },
        &quot;then&quot;: {
          &quot;properties&quot;: {
            &quot;baz&quot;: {
              &quot;type&quot;: &quot;object&quot;,
              &quot;properties&quot;: {
                &quot;baz1&quot;: { &quot;type&quot;: &quot;number&quot; },
                &quot;baz2&quot;: { &quot;type&quot;: &quot;string&quot; }
              },
              &quot;required&quot;: [&quot;baz1&quot;, &quot;baz2&quot;],
              &quot;additionalProperties&quot;: false
            }
          },
          &quot;required&quot;: [&quot;baz&quot;]
        }
      },
      {
        &quot;if&quot;: {
          &quot;properties&quot;: {
            &quot;bar&quot;: {
              &quot;const&quot;: &quot;bar2&quot;
            }
          },
          &quot;required&quot;: [&quot;bar&quot;]
        },
        &quot;then&quot;: {
          &quot;properties&quot;: {
            &quot;baz&quot;: {
              &quot;type&quot;: &quot;object&quot;,
              &quot;properties&quot;: {
                &quot;baz3&quot;: { &quot;type&quot;: &quot;number&quot; },
                &quot;baz4&quot;: { &quot;type&quot;: &quot;string&quot; }
              },
              &quot;required&quot;: [&quot;baz3&quot;, &quot;baz4&quot;],
              &quot;additionalProperties&quot;: false
            }
          },
          &quot;required&quot;: [&quot;baz&quot;]
        }
      }
    ]
  }
  </code></pre>
  <p>It correctly validates all combinations I've tried so far except when baz is present without foo &amp; bar or with foo = false &amp; no bar, which both validate to true even though I'd expect it to be false as both bar &amp; baz are set as not require if foo is not required &amp; if foo is false. What am I missing?</p>