How to use the JSV.JSV.inherits function in jsv

To help you get started, we’ve selected a few jsv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eirikurn / contracts / lib / schema.js View on Github external
var environment = jsv.createEnvironment("json-schema-draft-03");

/**
 * Patch JSV so it always clones instances before validation
 * so filters don't affect the original object.
 */
environment.createInstance = function(data, uri) {
  data = jsv.clone(data, true);
  return jsv.Environment.prototype.createInstance.call(this, data, uri);
};

var schemaSchema = environment.getDefaultSchema()
  , oldValidator = schemaSchema.getAttribute("validator");

schemaSchemaJson = jsv.inherits(schemaSchema, {
  /**
   * Patch the number type validator to not report NaN's as numbers.
   */
  "properties": {
    "type": {
      "typeValidators": {
        "number": function(instance, report) {
          return instance.getType() === "number" && !isNaN(instance.getValue());
        }
      }
    }
  },

  /**
   * Patch it to run filters before running validators.
   */