title: JSON schema for validating list with different possible field values
body: <p>Within a JSON structure (“event bundle”), I am collecting several lists of events. These are called event lists. Each event in that list has at least a <code>type</code> field, whose value is dependent on which list it is stored in. Consider the following valid example:</p>
  
  <pre><code>{
      "event_bundle": {
          "alert_events": [
              { "type": "fooAlert1", "value": "bar" },
              { "type": "fooAlert2", "value": "bar" },
              { "type": "fooAlert3", "value": "bar" }
          ],
          "user_events": [
              { "type": "fooUser1", "value": "bar" },
              { "type": "fooUser2", "value": "bar" },
              { "type": "fooUser3", "value": "bar" }
          ]
      }
  }
  </code></pre>
  
  <p>Here, <code>alert_events</code> can only contain events whose types are <code>fooAlert1</code>, <code>fooAlert2</code> and <code>fooAlert3</code>, not others. The same goes for <code>user_events</code>. So, this JSON would <em>not</em> be valid:</p>
  
  <pre><code>{
      "event_bundle": {
          "alert_events": [
              { "type": "fooAlert1", "value": "bar" },
              { "type": "fooUser2", "value": "bar" },
              { "type": "foo", "value": "bar" }
          ],
          "user_events": [
              { "type": "fooAlert1", "value": "bar" },
              { "type": "fooUser2", "value": "bar" },
              { "type": "foo", "value": "bar" }
          ]
      }
  }
  </code></pre>
  
  <p>It's invalid, since <code>fooUser2</code> cannot appear in an event that is in an <code>alert_events</code> list, and <code>fooAlert1</code> cannot appear in the <code>user_events</code>. Also, the event <code>foo</code> is not valid at all.</p>
  
  <p>I currently have the following simple schema:</p>
  
  <pre><code>{
    "type": "object",
    "definitions": {
      "event_list": {
        "type": "array",
        "items": {
          "$ref": "#/definitions/event"
        }
      },
      "event": {
        "type": "object",
        "required": ["type", "value"],
        "properties": {
          "type": { "type": "string" },
          "value": { "type": ["string", "object"] },
          "source": { "type": ["string", "null"] }
        }
      }
    },
    "properties": {
      "event_bundle": {
        "type": "object",
        "properties": {
          "alert_events": {
            "$ref": "#/definitions/event_list"
          },
          "user_events": {
            "$ref": "#/definitions/event_list"
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>However, this does not fully validate the allowable <code>type</code>s.</p>
  
  <p>I know I could define different <code>event_list</code>s with different <code>event</code>s, but that would mean I'd have to define potentially dozens of lists and events.</p>
  
  <p>Is there an easier way to say, I want to validate that <code>event</code> objects in an <code>alert_events</code> list can have one set of <code>type</code>s, and for another list another set of types?</p>