title: Ajv: How to leverage $data reference with custom keyword?
body: <p>I am using <a href="http://epoberezkin.github.io/ajv/" rel="nofollow noreferrer">Ajv</a> in my project. I am trying to add a custom keyword by the help of <code>ajv.addKeyword</code> api. I am able to add keyword by doing this (borrowed from docs):</p>
  
  <pre><code>var ajv = new Ajv({
    $data: true
  });
  
  ajv.addKeyword('range', {
    type: 'number',
    compile: function(sch, parentSchema) {
      var min = sch[0];
      var max = sch[1];
      return parentSchema.exclusiveRange === true ? function(data) {
        return data &gt; min &amp;&amp; data &lt; max;
      } : function(data, dataPath, parentData, parentDataProperty) {
        return data &gt;= min &amp;&amp; data &lt;= max;
      }
    }
  });
  
  var schema = {
    "properties": {
      "smaller": {
        "type": "number"
      },
      "larger": {
        "type": "number",
        "range": [2, 10]
      }
    }
  };
  
  var validData = {
    smaller: 15,
    larger: 17
  };
  
  let validateData = ajv.compile(schema);
  validateData(validData);
  console.log('Errors after validations --&gt; ', validateData.errors)
  </code></pre>
  
  <p>Everything is working fine. Now I need to use <a href="http://epoberezkin.github.io/ajv/#data-reference" rel="nofollow noreferrer"><code>$data</code></a> cause data for my custom field will be the value of some other field. To achieve it this is what I tried with my schema:</p>
  
  <pre><code>var schema = {
    "properties": {
      "smaller": {
        "type": "number"
      },
      "larger": {
        "type": "number",
        // "range": [2, 10],
        "range": {
          "$data": "1/myRange" // referencing to myRange
        }
      },
      "myRange": {
        type: "array",
        items: {
          type: "number"
        }
      }
    }
  };
  </code></pre>
  
  <p>But it looks likes custom fields are not supported with <code>$data</code> ref yet. As mentioned in the docs, only following fields are supported for $data ref.</p>
  
  <blockquote>
    <p>$data reference is supported in the keywords: const, enum, format,
    maximum/minimum, exclusiveMaximum / exclusiveMinimum, maxLength /
    minLength, maxItems / minItems, maxProperties / minProperties,
    formatMaximum / formatMinimum, formatExclusiveMaximum /
    formatExclusiveMinimum, multipleOf, pattern, required, uniqueItems.</p>
  </blockquote>
  
  <p>One way to get the value is, I use parameters of validate function <code>data, dataPath, parentData, parentDataProperty</code> and write logic to extract value of field defined by <code>$data</code> ref. But I am not sure this is a right way to achieve it or not. Can anyone please help me on this? Here's the <a href="http://plnkr.co/edit/fNBeJzTOHMCC7g7tgSDP" rel="nofollow noreferrer">plunkr to play</a>. Thanks.</p>