JSON Schema get anyOf in a complex object with multiple arrays

Viewed 20

I'm unable to find a solution for the following problem:

Given this input

{
  "grandParent": {
    "parent1": {
      "kids": [{
        "name": "David"
      }, {
        "name": "Josh"
      }]
    },
    "parent2": {
      "kids": [{
        "name": "Michael"
      }]
    },
  }
}

I'm trying to write a schema that will succeed if at least one of the kids' names (regardless of the parent) is "David" or "Kevin"

Here's the schema I tried:

{
  "properties": {
    "grandParent": {
      "additionalProperties": {
        "properties": {
          "kids": {
            "type": "array",
            "contains": {
              "properties": {
                "name": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "David"
                    },
                    {
                      "type": "string",
                      "pattern": "Kevin"
                    }
                  ]
                }
              }
            }
          }
        }
      }
    }
  }
}

For some reason it still errors on the second parent, even though the first one qualifies under that rule.

https://www.jsonschemavalidator.net/s/QoSf6uIl

0 Answers
Related