title: JSON schema to enforce array contents
body: <p>Hi all and thanks in advance.</p>
  
  <p>I am attempting to create a JSON schema to enforce an array to contain one A and B object and N C objects, where A and B are C objects and N is an integer inclusively between 0 and infinity. </p>
  
  <p>Therefor : </p>
  
  <p><code>[A, B]</code>
  <code>[A, B, C1]</code>
  <code>[A, B, C1, .., CN]</code></p>
  
  <p>Are all <strong>valid</strong>, though :</p>
  
  <p><code>[A]</code>
  <code>[A, C1]</code>
  <code>[A, C1, .., CN]</code></p>
  
  <p>Are <strong>not valid</strong>.</p>
  
  <p>To make clear, A and B must be present. C objects are optional, though you may have as many as you would like. </p>
  
  <p><strong>C object schemas :</strong></p>
  
  <pre><code>
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "C Object",
  
    "type": "object",
    "required": ["id", "name"],
  
    "properties": {
      "id": {
        "type": "integer"
      },
      "name": {
        "type": "string"
      }
    },
    "additionalProperties": false
  }
  </code></pre>
  
  <p>So a C object is any valid JSON object containing only the properties "id" and "name" where "id" is an integer and "name" is a string. </p>
  
  <p><strong>A and B object schemas :</strong> </p>
  
  <pre><code>
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "A Object",
  
    "type": "object",
    "required": ["id", "name"],
  
    "properties": {
      "id": {
        "type": "integer"
      },
      "name": {
        "type": "string",
        "enum": ["A"]
      }
    },
    "additionalProperties": false
  }
  </code></pre>
  
  <pre><code>
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "B Object",
  
    "type": "object",
    "required": ["id", "name"],
  
    "properties": {
      "id": {
        "type": "integer"
      },
      "name": {
        "type": "string",
        "enum": ["B"]
      }
    },
    "additionalProperties": false
  }
  </code></pre>
  
  <p>A and B objects differ from C objects in that there name value is enforced. The name value of an A object must be a value contained in the field enum, where enum contains a single value.</p>
  
  <p><strong>My most complete schema to date is :</strong> </p>
  
  <pre><code>
  {
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "To Date Solution",
    "description": "So far this is the most complete attempt at enforcing values to be contained within a JSON structure using JSON schemas.",
  
    "type": "array"
    "items": {
      "allOf": [
        {
          "$schema": "http://json-schema.org/draft-04/schema#",
          "title": "C Object",
  
          "type": "object",
          "required": ["id", "name"],
  
          "properties": {
            "id": {
              "type": "integer"
            },
            "name": {
              "type": "string"
            }
          },
          "additionalProperties": false
        }
      ]
    }
  }
  </code></pre>
  
  <p>This enforces that all objects contained within must be of type C, which A and B are, though I am unsure how to enforce that at least single instance of A and B are contained within my array.</p>