title: How to do JSON Schema multi level conditional Validation with Array Elements
body: <p>I'm working on a JSON schema and I'm stuck on array validations. I have this example input JSON</p>
  <pre><code>{
    &quot;paths_1&quot;: {
      &quot;path_1&quot;: [
        {
          &quot;abc&quot;: &quot;valid_abc&quot;
        },
        {
          &quot;abc&quot;: &quot;invalid_abc&quot;
        }
      ]
    },
    &quot;paths_2&quot;: {
      &quot;path_2&quot;: [
        {
          &quot;ghi&quot;: &quot;valid_ghi&quot;
        }
      ]
    }
  }
  </code></pre>
  <p>My rule for this JSON data is, if <code>paths_2.path_2[].ghi</code> is &quot;valid_ghi&quot; and <code>paths_1.path_1[].abc</code> is &quot;valid_abc&quot;, then require &quot;def&quot; key for the object that has &quot;valid_abc&quot;.</p>
  <p>I created this JSON schema for this rule, but it doesn't work as expected.</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;paths_1&quot;: {
        &quot;type&quot;: &quot;object&quot;,
        &quot;properties&quot;: {
          &quot;items&quot;: {
            &quot;properties&quot;: {
              &quot;path_1&quot;: {
                &quot;properties&quot;: {
                  &quot;abc&quot;: {
                    &quot;type&quot;: &quot;string&quot;
                  },
                  &quot;def&quot;: {
                    &quot;type&quot;: &quot;string&quot;
                  }
                }
              }
            }
          }
        }
      },
      &quot;paths_2&quot;: {
        &quot;type&quot;: &quot;object&quot;,
        &quot;properties&quot;: {
          &quot;items&quot;: {
            &quot;properties&quot;: {
              &quot;path_2&quot;: {
                &quot;properties&quot;: {
                  &quot;ghi&quot;: {
                    &quot;type&quot;: &quot;string&quot;
                  }
                }
              }
            }
          }
        }
      }
    },
    &quot;allOf&quot;: [
      {
        &quot;if&quot;: {
          &quot;allOf&quot;: [
            {
              &quot;properties&quot;: {
                &quot;paths_1&quot;: {
                  &quot;properties&quot;: {
                    &quot;path_1&quot;: {
                      &quot;contains&quot;: {
                        &quot;properties&quot;: {
                          &quot;abc&quot;: {
                            &quot;const&quot;: &quot;valid_abc&quot;
                          }
                        },
                        &quot;required&quot;: [
                          &quot;abc&quot;
                        ]
                      }
                    }
                  }
                }
              }
            },
            {
              &quot;properties&quot;: {
                &quot;paths_2&quot;: {
                  &quot;properties&quot;: {
                    &quot;path_2&quot;: {
                      &quot;contains&quot;: {
                        &quot;properties&quot;: {
                          &quot;ghi&quot;: {
                            &quot;const&quot;: &quot;valid_ghi&quot;
                          }
                        },
                        &quot;required&quot;: [
                          &quot;ghi&quot;
                        ]
                      }
                    }
                  }
                }
              }
            }
          ]
        },
        &quot;then&quot;: {
          &quot;properties&quot;: {
            &quot;paths_1&quot;: {
              &quot;properties&quot;: {
                &quot;path_1&quot;: {
                  &quot;items&quot;: {
                    &quot;required&quot;: [
                      &quot;def&quot;
                    ]
                  }
                }
              }
            }
          }
        }
      }
    ]
  }
  </code></pre>
  <p>When I tested this schema, it returns 'def' is a required property for the object with &quot;invalid_abc&quot;, when it should not.</p>
  <p>I tried changing <em>contains</em> keys to <em>items</em> in JSON schema but in this case, if part becomes false and validator returns that input is valid.</p>
  <p>Is there a way to validate this input with the given rule?</p>