Using chainingBehaviour to check whether schemas are valid
348762
function() {
    let schemas = utils.parseArg(arguments);
    schemas.forEach(function(schema) {
      utils.assert(schema.isOvt, `${utils.obj2Str(schema)} is not a valid ovt schema`);
    });
  }
26011
function checkProp(value, schema, path, i, errors) {
	if (!errors) { errors = []; }

	path +=
		path ? typeof i == 'number' ? '[' + i + ']'
			 : typeof i == 'undefined' ? '' : '.' + i : i;

	function addError(message) {
		errors.push({
			property: path,
			message:message
		});
	}

	var schemaType = typeof schema,
		isObject = schemaType == 'object',
		isFunction = schemaType == 'function';

	if ((!isObject || Array.isArray(schema)) && (path || !isFunction)) {
		if (isFunction) {
			if (!(value instanceof schema)) {
				addError("is not an instance of the class/constructor " + schema.name);
			}
		} else if (schema) {
			addError("Invalid schema/property definition " + schema);
		}

		return errors;
	}

	if (gCheckPropChange && schema.readonly) { addError("is a readonly field, it can not be changed"); }

	// if it extends another schema, it must pass that schema as well
	if (schema['extends']) { checkProp(value, schema['extends'], path, i, errors); }

	if (value === undefined) {
		if (!schema.optional) { addError("is missing and it is not optional"); }
	} else {
		errors = errors.concat(checkType(schema.type,value));
		if (schema.disallow && !checkType(schema.disallow,value).length) { addError(" disallowed value was matched"); }

		if (value !== null) {
			if (Array.isArray(value)) {
				if (schema.items) {
					if (Array.isArray(schema.items)) {
						for (i=0,l=value.length; i<l; i++) {
							errors.concat(checkProp(value[i],schema.items[i],path,i, errors));
						}
					} else {
						for (i=0,l=value.length; i<l; i++) {
							errors.concat(checkProp(value[i],schema.items,path,i, errors));
						}
					}
				}
				if (schema.minItems && value.length < schema.minItems) {
					addError("There must be a minimum of " + schema.minItems + " in the array");
				}
				if (schema.maxItems && value.length > schema.maxItems) {
					addError("There must be a maximum of " + schema.maxItems + " in the array");
				}
			} else if (schema.properties) {
				errors.concat(checkObj(value, schema.properties, path, schema.additionalProperties, errors));
			}
			if (schema.pattern && typeof value == 'string' && !value.match(schema.pattern)) {
				addError("does not match the regex pattern " + schema.pattern);
			}
			if (schema.maxLength && typeof value == 'string' && value.length > schema.maxLength) {
				addError("may only be " + schema.maxLength + " characters long");
			}
			if (schema.minLength && typeof value == 'string' && value.length < schema.minLength) {
				addError("must be at least " + schema.minLength + " characters long");
			}
			if (typeof schema.minimum !== undefined
					&& typeof value == typeof schema.minimum
					&& schema.minimum > value)
			{
				addError("must have a minimum value of " + schema.minimum);
			}
			if (typeof schema.maximum !== undefined
					&& typeof value == typeof schema.maximum
					&& schema.maximum < value)
			{
				addError("must have a maximum value of " + schema.maximum);
			}

			if (schema['enum']) {

				var enumer = schema['enum'],
					found;

				var l = enumer.length;
				for(var j = 0; j < l; j++) {
					if (enumer[j]===value) {
						found=1;
						break;
					}
				}

				if (!found) { addError("does not have a value in the enumeration " + enumer.join(", ")); }
			}
			if (typeof schema.maxDecimal == 'number' &&
			(value.toString().match(new RegExp("\\.[0-9]{" + (schema.maxDecimal + 1) + ",}")))) {
				addError("may only have " + schema.maxDecimal + " digits of decimal places");
			}
		}
	}

	return errors;
}
1214725
function validateSchema(schema, throwOrLogError) {
  var $schema = schema.$schema;
  if ($schema !== undefined && typeof $schema != 'string')
    throw new Error('$schema must be a string');
  $schema = $schema || this._opts.defaultMeta || defaultMeta(this);
  if (!$schema) {
    this.logger.warn('meta-schema not available');
    this.errors = null;
    return true;
  }
  var valid = this.validate($schema, schema);
  if (!valid && throwOrLogError) {
    var message = 'schema is invalid: ' + this.errorsText();
    if (this._opts.validateSchema == 'log') this.logger.error(message);
    else throw new Error(message);
  }
  return valid;
}
152240
def _validate_schema(self):
        
        try:
            log.debug("validating provider schema")
            self.validator.check_schema(self.schema)
        except jsonschema.SchemaError as e:
            raise SchemaError(
                schema_error=e.message, provider=self.name, data=self.schema
            )
340859
def validate(self, ymldata=None, messages=None):
        """"""
        schema_val = self.schema_val(messages)
        if len(messages) == 0:
            content_val = self.content_val(ymldata, messages)

        return schema_val and content_val
461387
def validate_schema(schema_name):
    """"""
    def decorator(f):
        @wraps(f)
        def wrapper(*args, **kw):
            instance = args[0]
            try:
                instance.validator(instance.schemas[schema_name]).validate(request.get_json())
            except ValidationError, e:
                ret_dict = instance._create_ret_object(instance.FAILURE,
                                                       None, True,
                                                       instance.BAD_SCHEMA,
                                                       e.message)
                instance.logger.error("Invalid Schema", ret_dict)
                return jsonify(ret_dict), 400
            instance.logger.debug("Schema is valid")
            return f(*args, **kw)
        return wrapper
    return decorator
907022
function Schema(options, descriptors) {

    if (!descriptors) {
        descriptors = options;
        options = null;
    }

    function opt(name, type) {
        var value = options[name];
        if (value !== undefined) {
            if (typeof value === type) return value;
            else throw new TypeError(current + 'options : ' + name + ': "' +
                value + '" is not of type [' + type + ']');
        }
        else return false;
    }

    var current = 'Schema: arguments: ',
        defaults = { required: false };

    if (hasValue(options)) {
        if (type(options) === 'object') {
            defaults.required = opt('required', 'boolean');
            if (opt('validator', 'function')) defaults.validator = options.validator;
        }
        else throw new TypeError(current + 'options: must be of type [object]');
    }

    current += 'descriptors: ';
    if (typeof descriptors !== 'object')
        throw new TypeError(current + 'must be of type [object]');
    if (!Array.isArray(descriptors)) {
        descriptors = this.toDescriptors(descriptors, defaults);
    }
    if (options && options.extends instanceof Schema) {
        descriptors = this.extendDescriptors(descriptors, options.extends.descriptors);
    }
    if (!descriptors.length)
        throw new TypeError(current + 'contains no values');
    else if (!(descriptors[0] instanceof Descriptor)) {
        throw new TypeError(current + 'must be instances of Descriptor class');
    }
    var instance = this;
    this.descriptors = descriptors;

}
709650
function isValidQuery(definition) {
  var requiredKeys = [
    'event_name',
    'resource_type',
    'tracker_id'
  ];

  return _.all(requiredKeys, function(key) {
    return _.has(definition, key);
  });
}
782619
function compareObjects(schema, version1, version2) {

      var changes = [];

      _.each(version1, function(val, key) {
        var change;
        var field = getField(schema, key, val);
        if (!field) {
          // Current schema can't describe this field
          return;
        }
        if (!_.has(version2, key)) {
          change = { action: 'remove', key: key, field: field, old: version1[key] };
        } else if (!_.isEqual(version2[key], version1[key])) {
          change = { action: 'change', key: key, field: field, old: version1[key], current: version2[key] };
        }
        if (change) {
          change.changes = compareField(field, change.old, change.current);
          changes.push(change);
        }
      });

      _.each(version2, function(val, key) {
        var change;
        var field = getField(schema, key, val);
        if (!field) {
          // Current schema can't describe this field
          return;
        }
        if (!_.has(version1, key)) {
          change = { action: 'add', key: key, field: field, current: val };
          change.changes = compareField(field, change.old, change.current);
          changes.push(change);
        }
      });

      return changes;

      function compareField(field, old, current) {

        if (current && (!old)) {
          old = synth(field.type, current);
        } else if (old && (!current)) {
          current = synth(field.type, old);
        }

        if (field.type === 'array') {

          return compareArrays(schemaIdentifier, schemaDecoratorGenerator(field.schema), old, current);

        } else if ((field.type === 'area') || (field.type === 'singleton')) {

          return compareAreas(old, current);

        } else if (field.type === 'joinByArray') {

          return compareArrays(joinByArrayIdentifier, joinByArrayDecoratorGenerator(field.withType), old, current);

        } else if (field.type === 'joinByOne') {

          return compareArrays(joinByArrayIdentifier, joinByArrayDecoratorGenerator(field.withType), old ? [ old ] : [], current ? [ current ] : []);

        } else {

          // Take advantage of Apostrophe's support for boiling fields
          // down to search text to generate a basis for a text diff.
          // If a special "diffable" function is available use it;
          // that allows us to compare things that don't make
          // good search text but are human readable, like URLs. -Tom

          var oldLines = [];
          var oldText = '';
          var currentLines = [];
          var currentText = '';
          var fieldType = self.apos.schemas.getFieldType(field.type);
          var diffable = fieldType.diffable;
          if (diffable) {
            oldText = diffable(old);
            currentText = diffable(current);
          } else {
            var indexer = fieldType.index;
            if (indexer) {
              indexer(old, field, oldLines);
              indexer(current, field, currentLines);
              oldText = _.filter(_.pluck(oldLines, 'text'), function(line) {
                return line !== undefined;
              }).join("\n");
              currentText = _.filter(_.pluck(currentLines, 'text'), function(line) {
                return line !== undefined;
              }).join("\n");
            }
          }

          var diff = [];
          if (oldText !== undefined && currentText !== undefined) {
            diff = jsDiff.diffSentences(oldText, currentText, { ignoreWhitespace: true });
          }

          var changes = _.map(_.filter(diff, function(diffChange) {
            return diffChange.added || diffChange.removed;
          }), function(diffChange) {
            // Convert a jsDiff change object to an
            // apos versions change object
            if (diffChange.removed) {
              return {
                action: 'remove',
                text: diffChange.value,
                field: {
                  type: 'string',
                  label: 'Content'
                }
              };
            } else {
              return {
                action: 'add',
                text: diffChange.value,
                field: {
                  type: 'string',
                  label: 'Content'
                }
              };
            }
          });
          return changes;
        }

        // If "old" or "current" doesn't exist, make sure
        // we compare the other one to a reasonable value.
        // This is currently only an issue for areas, arrays and objects.
        // TODO: should probably be something we ask schemas to
        // generate for us so it's extensible. -Tom

        function synth(type, existing) {
          var value;
          if (existing && (existing.type === 'area')) {
            value = { type: 'area', items: [] };
          } else if (Array.isArray(existing)) {
            value = [];
          } else if (typeof (existing) === 'object') {
            value = {};
          }
          return value;
        }

      }
    }
13317
function checkRegex(node, schema, key) {
    try {
      schema[SCHEMAREGEX].test(node);
    } catch (e) {
      throw new ValidationException(key + " doesn't match its regex.");
    }
  }
960491
def validate_schema(cls, tx):
        
        _validate_schema(TX_SCHEMA_COMMON, tx)
        _validate_schema(TX_SCHEMA_TRANSFER, tx)
        _validate_schema(cls.TX_SCHEMA_CUSTOM, tx)
816923
def validate(self, obj):
        """"""
        try:
            if self.resolver is not None:
                jsonschema.validate(obj, self.schema, resolver=self.resolver)
            else:
                jsonschema.validate(obj, self.schema)
        except jsonschema.ValidationError as exc:
            raise exceptions.ValidationError(str(exc))
1248400
def _try_validate(cnf, schema, **options):
    
    valid = True
    if schema:
        (valid, msg) = validate(cnf, schema, **options)
        if msg:
            LOGGER.warning(msg)

    if valid:
        return cnf

    return None
871141
def validate(obj, schema):
        
        if isinstance(obj, str):
            obj = json.loads(obj)
        return JsonValidator(schema)._validate(obj)
1132518
private void validateSchema(Schema schema) throws DDFException {
    Set<String> columnSet = new HashSet<String>();
    if(schema != null && schema.getColumns() != null) {
      for (Column column : schema.getColumns()) {
        if (columnSet.contains(column.getName())) {
          throw new DDFException(String.format("Duplicated column name %s", column.getName()));
        } else {
          columnSet.add(column.getName());
        }
      }
    }
  }
375042
def validate(raw_schema, target=None, **kwargs):
    
    schema = schema_validator(raw_schema, **kwargs)
    if target is not None:
        validate_object(target, schema=schema, **kwargs)
1160999
def assert_valid_schema(schema: GraphQLSchema) -> None:
    
    errors = validate_schema(schema)
    if errors:
        raise TypeError("\n\n".join(error.message for error in errors))