title: JSON schema anyOf validation based on one of properties
body: <p>I'm having difficulty figuring out how to validate an array of objects based on the value of one of the properties. So where I have a JSON object like:</p>
  
  <pre><code>{
      "items": [
          {
              "name": "foo",
              "otherProperty": "bar"
          },
          {
              "name": "foo2",
              "otherProperty2": "baz",
              "otherProperty3": "baz2"
          },
          {
              "name": "imInvalid"
          }
      ]
  }
  </code></pre>
  
  <p>I would like to say that </p>
  
  <ol>
  <li>items can contain anyOf objects where name can be "foo" or "foo2"</li>
  <li>if it's "foo" then the only valid other property (required) is
  "otherProperty"</li>
  <li>if the name is "foo2" then the only valid other
  properties are "otherProperty2" and "otherProperty3" both required</li>
  <li>No other value for "name" than "foo" and "foo2" is valid</li>
  <li>The objects themselves are optional in the items array, and some might be repeated.</li>
  </ol>
  
  <p>I've tried all kinds of things but I can't seem to get a failure when I validate. For example, the name "imInvalid" should be causing a validation error. This is my latest iteration of the schema. What am I missing?</p>
  
  <pre><code>{
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "required": ["items"],
      "properties": {
          "items": {
              "type": "array",
              "minItems": 1,
              "additionalProperties": false,
              "properties": {
                  "name": {
                      "anyOf": [
                          {
                              "type": "object",
                              "required": ["name", "otherProperty"],
                              "additionalProperties": false,
                              "properties": {
                                  "otherProperty": { "type": "string" },
                                  "name": { "enum": [ "foo" ] }
                              }
                          },{
                              "type": "object",
                              "required": ["name", "otherProperty2", "otherProperty3" ],
                              "additionalProperties": false,
                              "properties": {
                                  "otherProperty2": { "type": "string" },
                                  "otherProperty3": { "type": "string" },
                                  "name": { "enum": [ "foo2" ] }
                              }
                          }
                      ]
                  }
              }
          }
      }
  }
  </code></pre>