title: JSON Schema Conditional Statements
body: <p>I am trying to validate what I thought was a simple JSON schema as a configuration file for my Python application, it's a list of header key/value pairs, the only complication is that if the 'Type' field is set to 'AnyValue' then the value key is not required.</p>
  
  <p>Here is the schema as it is:</p>
  
  <pre><code>{
      "definitions":
      {
          'KeyEntry':
          {
               "properties":
               {
                  'Type': {"type" : "string"},
                  'Key': {"type": "string"}
               },
               "required": ['Type', 'Key'],
              "anyOf":
              [
                  {
                      "if":
                      {
                          "properties": {'Type': {"const": 'ExactValue'}}
                      },
                      "then":
                      {
                          "properties":
                          {
                              'Value': {"type": "string"}
                          },
                          "required": ['Type', 'Key', 'Value'],
                          "additionalProperties": false
                      }
                  },
                  {
                      "if":
                      {
                          "properties": {'Type': {"const": 'AnyValue'}}
                      },
                      "then":
                      {
                          "required": ['Type', 'Key'],
                          "additionalProperties": false
                      }
                  }
              ]
          }
      },
  
      "type": "object",
      "properties":
      {
          'Keys':
          {
              "type": "array",
              "items": {"$ref": "#/definitions/KeyEntry"}
          }
      },
      "required": ['Keys']
  }
  </code></pre>
  
  <p>Most of the validation works, except if I add extra values, even though I have set "additionalProperties": false throughout the schema.</p>
  
  <p>Here is an example where extra values are accepted:</p>
  
  <pre><code>{
      "Keys": [
  
          {
              "Type": "AnyValue",
              "Key": "Version",
              "Y": "Yes",
              "N": "No",
          }
      ]
  }
  </code></pre>
  
  <p>Please can someone help explain where I have gone wrong and how I should correct it, please?</p>