title: Use json-schema to require or disallow properties based on another property value?
body: <p>What I'm trying to accomplish in json-schema: when the property <code>enabled</code> is <code>true</code>, certain other properties should be required. When <code>false</code>, those properties should be disallowed. </p>
  
  <p>Here's my json-schema:</p>
  
  <pre><code>{
    "type": "object",
    "properties": {
      "enabled": { "type": "boolean" }
    },
    "required" : ["enabled"],
    "additionalProperties" : false,
    "if": {
      "properties": {
        "enabled": true
      }
    },
    "then": { 
      "properties": {
        "description" : { "type" : "string" },
        "count": { "type": "number" }
      },
      "required" : ["description", "count"]
    }
  }
  </code></pre>
  
  <p>Validating using <code>ajv</code> version 6.5, this had the result of requiring <code>count</code>, etc. regardless of the value of <code>enabled</code>. For instance, for data:</p>
  
  <pre><code>{ "enabled": false }
  </code></pre>
  
  <p>My validation errors are:</p>
  
  <pre><code>[ { keyword: 'required',
      dataPath: '',
      schemaPath: '#/then/required',
      params: { missingProperty: 'description' },
      message: 'should have required property \'description\'' },
    { keyword: 'required',
      dataPath: '',
      schemaPath: '#/then/required',
      params: { missingProperty: 'count' },
      message: 'should have required property \'count\'' },
    { keyword: 'if',
      dataPath: '',
      schemaPath: '#/if',
      params: { failingKeyword: 'then' },
      message: 'should match "then" schema' } ]
  </code></pre>
  
  <p>How can I accomplish this using json-schema <code>draft-7</code>?</p>
  
  <p>Note that this question is similar to, but has more stringent requirements than: <br>
  <a href="https://stackoverflow.com/q/38717933/45813">jsonSchema attribute conditionally required</a>.</p>