title: JSON-Schema: Conditional dependency (by value)
body: <p>This is the simplified JSON-Schema:</p>
  
  <pre class="lang-json prettyprint-override"><code>{
      "$schema": "http://json-schema.org/draft-04/schema#",
      "id": "user",
      "type": "object",
      "properties": {
          "account": {
              "type": "object",
              "properties": {
                  "type": {
                      "type": "string",
                      "enum": ["COMPANY", "PERSON"]
                  }
              },
              "required": ["type"]
          },
          "person": {
              "type": "object",
              "properties": {
                  "firstName": { "type": "string" },
                  "lastName": { "type": "string" }
              },
              "required": ["firstName", "lastName"]
          },
          "company": {
              "type": "object",
              "properties": {
                  "name": { "type": "string" },
                  "taxNumber": { "type": "string" }
              }
          }
      },
      "required": ["account", "person"]
  }
  </code></pre>
  
  <p>What I want to achieve is:</p>
  
  <ul>
  <li>If <code>account.type</code> is set to <code>"COMPANY"</code>:
  
  <ul>
  <li><code>company</code> object and its properties should be <strong>required</strong>.</li>
  </ul></li>
  <li>If <code>account.type</code> isset to <code>"PERSON"</code>: 
  
  <ul>
  <li><code>company</code> <strong>object</strong> should be <strong>optional</strong>.</li>
  <li>But if <code>company</code> object is present, <code>company.name</code> and <code>company.taxNumber</code> should be <strong>required</strong>. </li>
  </ul></li>
  </ul>
  
  <p>This can be achieved by defining two long sub-schemas under a <code>oneOf</code> but that would mean too many duplicates and a complex schema, since <code>account</code> and <code>company</code> has many more properties than this simplified version.</p>
  
  <p>AFAIK, the only way to define a specific value in a schema is by using the <code>enum</code> keyword with a single item. I tried this with the <code>dependencies</code> keyword but didn't help.</p>
  
  <p>Can you think of a way without altering the structure of the data object?</p>