title: Validate JSON Schema based on "type" property
body: <p>I have the following JSON which validates against my current schema:</p>
  
  <pre><code>    {
        "information": [
          {
            "value": "closed",
            "type": "power"
          },
          {
            "value": "on",
            "type": "door"
          }
        ]
      }
  
  </code></pre>
  
  <p>However, I want this validation to fail (since <code>open</code>/<code>closed</code> should relate to <code>door</code>, and <code>on</code>/<code>off</code> should only relate to <code>power</code>.</p>
  
  <p>How can I tie the two together?</p>
  
  <p>My current working schema:</p>
  
  <pre><code>  "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "definitions": {
      "Type": {
        "type": "string",
        "enum": ["power", "door"]
      },
      "Power": {
        "type": "string",
        "enum": ["on", "off"]
      },
      "Door": {
        "type": "string",
        "enum": ["open", "closed"]
      },
      "InformationField": {
        "type": "object",
        "required": [ "type", "value" ],
        "properties": {
          "label": { "type": "string" },
          "value": {
            "anyOf": [
              { "$ref": "#/definitions/Power"},
              { "$ref": "#/definitions/Door"}
            ]
          },
          "type": { "$ref": "#/definitions/Type" }
        }
      },
      "Information": {
        "type": "array",
        "items": { "$ref": "#/definitions/InformationField" }
      },
    },
    "properties": {
      "information": { "$ref": "#/definitions/Information" }
    },
  }
  </code></pre>
  
  <p>I have a lot of types, so I want to do this in the cleanest way possible.</p>
  
  <p>Here is one of my attempts, which fails to validate correctly:</p>
  
  <pre><code>{ 
    "$schema": "http://json-schema.org/draft-07/schema#",
    "type": "object",
    "definitions": {
      "Type": {
        "type": "string",
        "enum": ["power", "door"]
      },
      "Power": {
        "type": "string",
        "enum": ["on", "off"]
      },
      "Door": {
        "type": "string",
        "enum": ["open", "closed"]
      },
      "InformationField": {
        "type": "object",
        "required": [ "label", "value" ],
        "properties": {
          "label": { "type": "string" },
          "type": { "$ref": "#/definitions/Type" }
        },
        "anyOf": [
          {
            "if": {
             "properties": { "type": { "const": "power" } }
            },
            "then": {
              "properties": { "value": { "$ref": "#/definitions/Power" } }
            }
          },
          {
            "if": {
              "properties": { "type": { "const": "door" } }
            },
            "then": {
              "properties": { "value": { "$ref": "#/definitions/Door" } }
            }
          }
        ]
      },
      "Information": {
        "type": "array",
        "items": { "$ref": "#/definitions/InformationField" }
      },
    },
    "properties": {
      "information": { "$ref": "#/definitions/Information" }
    },
  }
  </code></pre>
  
  <p>(Validates, even though it shouldn't ...)</p>