How to use the jsonschema.ValidatorResult function in jsonschema

To help you get started, we’ve selected a few jsonschema 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 exratione / lambda-complex / lib / build / configValidator.js View on Github external
validator.attributes.noDuplicatePropertyValuesFor = function (instance, schema, options, ctx) {
  var result = new jsonschema.ValidatorResult(instance, schema, options, ctx);

  if (_.isString(schema.noDuplicatePropertyValuesFor)) {
    schema.noDuplicatePropertyValuesFor = [schema.noDuplicatePropertyValuesFor];
  }

  if (!_.isArray(schema.noDuplicatePropertyValuesFor) || !_.isArray(instance)) {
    return result;
  }

  _.each(schema.noDuplicatePropertyValuesFor, function (prop) {
    var duplicates = _.chain(instance).countBy(function (component) {
      return component[prop];
    }).map(function (count, value) {
      if (count > 1) {
        return value;
      }
github exratione / cloudformation-deploy / lib / configValidator.js View on Github external
validator.attributes.isFunction = function (instance, schema, options, ctx) {
  var result = new jsonschema.ValidatorResult(instance, schema, options, ctx);

  if (!_.isBoolean(schema.isFunction)) {
    return result;
  }

  if (schema.isFunction) {
    if ((instance !== undefined) && (typeof instance !== 'function')) {
      result.addError('Required to be a function.');
    }
  }
  else {
    if (typeof instance === 'function') {
      result.addError('Required to not be a function.');
    }
  }