Validates that the schema is ok. Checking that the top level is pages
and recursing down from there, ending up with an array of everything that
isn't up to standards 👮
480372
function validateSchema(schema) {
  let errors = [];

  schema.forEach((page, index) => {
    if (!['Page', 'Result'].includes(page.type)) {
      errors = [
        ...errors,
        {
          path: ['schema', index],
          error: 'Top-level element is of invalid type. Must be Page or Result',
        },
      ];
    }

    errors = [
      ...errors,
      ...validatePage(page, ['schema', index]),
    ];
  });

  return errors;
}
599477
function validate(candidate) {
  if (candidate.doc_type) {
    var schema = schemasDeepCopy()[candidate.doc_type];
    validator.validate(candidate, schema);
    var errors = validator.getLastErrors();
    return errors;
  }

  return [{
    dataModel: 'the object to be validated is missing a `doc_type` property'
  }];
}
963775
def valid?
      REQUIRED_FIELDS[type].all? do |f|
        f.is_a?(Array) ? !(f & fields.keys).empty? : !fields[f].nil?
      end
    end
1140672
def valid?
      return false if @first_page.nil?
      return false if @last_page.nil?
      return false if @odd_pages.nil?
      return false if @even_pages.nil?
      return true
    end
157796
def choose
      validate_path
      search_paths_list = search_paths
      if search_paths_list.empty?
        puts "\nThere is no /schema[^\/]*.rb$/ in the directory #{@path}"
        exit
      end

      search_paths_list.each_with_index {|path,indx|  puts "#{indx}. #{path}" }

      begin
        print "\nSelect a path to the target schema: "
      end while search_paths_list[(id = STDIN.gets.to_i)].nil?

      search_paths_list[id]
    end
440952
def validate(self, data):
        
        for s in [self._schema(s, error=self._error, ignore_extra_keys=self._ignore_extra_keys) for s in self._args]:
            data = s.validate(data)
        return data
1036683
function validateNode(node, path, ancestors) {
  let errors = [];

  if (!node.type) {
    return [{ path, error: 'Node is missing the type property' }];
  }

  if (ancestors.length && node.type === 'Page') {
    errors = [...errors, { path, error: 'Encountered a nested page. Page is only allowed at the top level' }];
  }

  errors = [
    ...errors,
    ...assertProperties(node, path, requiredProperties[node.type]),
    ...assertDeprecations(node, path, deprecatedProperties[node.type]),
  ];

  // Parse logical expressions
  ['hidden', 'disabled', 'test'].forEach((field) => {
    if (!node[field]) {
      return;
    }

    try {
      parseExpression(node[field]);
    } catch (e) {
      errors = [...errors, { path: [...path, field], error: e.message }];
    }
  });

  // Recurse through children
  if (node.children) {
    node.children.forEach((child, index) => {
      errors = [
        ...errors,
        ...validateNode(child, [...path, 'children', index], [...ancestors, node]),
      ];
    });
  }

  // Check and recurse through branches
  if (node.branches) {
    node.branches.forEach((branch, branchIndex) => {
      errors = [
        ...errors,
        ...assertProperties(
          branch,
          [...path, 'branches', branchIndex],
          ['test', 'children'],
        ),
      ];

      // Validate the text expression
      if (branch.test) {
        try {
          parseExpression(branch.test);
        } catch (e) {
          errors = [...errors, { path: [...path, 'branches', branchIndex, 'test'], error: e.message }];
        }
      }

      // Recurse through the branch children
      if (branch.children) {
        branch.children.forEach((child, index) => {
          errors = [
            ...errors,
            ...validateNode(child, [...path, 'branches', branchIndex, 'children', index], [...ancestors, node]),
          ];
        });
      }
    });
  }

  // Recurse over the options
  if (node.options) {
    node.options.forEach((option, index) => {
      errors = [
        ...errors,
        ...validateNode(option, [...path, 'options', index], [...ancestors, node]),
      ];
    });
  }

  // Check image
  if (node.image) {
    if (typeof node.image !== 'object') {
      errors = [
        ...errors,
        { path, error: `an object was expected for the image property. Got ${typeof node.image}` },
      ];
    }

    errors = [
      ...errors,
      ...assertProperties(
        { ...node.image, type: 'Image' },
        [...path, 'image'],
        ['url', 'alt'],
      ),
    ];
  }

  return errors;
}
27359
private function validate()
    {
        if ($this->hasValidated) {
            return;
        }

        $this->checkDepth();

        foreach ($this->schema as $rule => $parameter) {
            $this->currentKeyword   = $rule;
            $this->currentParameter = $parameter;
            $this->mergeErrors($this->validateRule($rule, $parameter));
            $this->currentKeyword = $this->currentParameter = null;
        }

        $this->hasValidated = true;
    }
276613
def validate(schema):
    """"""
    try:
        tableschema.validate(schema)
        click.echo("Schema is valid")
        sys.exit(0)
    except tableschema.exceptions.ValidationError as exception:
        click.echo("Schema is not valid")
        click.echo(exception.errors)
        sys.exit(1)
206244
def _validated(self, data):
        """"""
        errors = []
        for sub in self.schemas:
            try:
                return sub(data)
            except NotValid as ex:
                errors.extend(ex.args)

        raise NotValid(' and '.join(errors))
812437
def validate(self, data, schema):
        '''
        '''
        try:
            return schema(data)
        except MultipleInvalid as ie:
            errors = []
            for error in ie.errors:
                if error.path:
                    field = '.'.join(str(p) for p in error.path)
                    path = error.path
                    value = data
                    while path:
                        attr = path.pop(0)
                        try:
                            if isinstance(value, (list, tuple)):
                                attr = int(attr)
                            value = value[attr]
                        except Exception:
                            value = None

                    txt = safe_unicode(error).replace('for dictionary value', '')
                    txt = txt.strip()
                    if isinstance(error, RequiredFieldInvalid):
                        msg = '[{0}] {1}'
                    else:
                        msg = '[{0}] {1}: {2}'
                    try:
                        msg = msg.format(field, txt, str(value))
                    except Exception:
                        msg = '[{0}] {1}'.format(field, txt)

                else:
                    msg = str(error)
                errors.append(msg)
            msg = '\n- '.join(['Validation error:'] + errors)
            raise HarvestValidationError(msg)
1106652
function validate(doc, schema, prefix, options) {
  schema.validate(doc, prefix, options);
}
334712
def _validate(data, schema, ac_schema_safe=True, **options):
    
    try:
        jsonschema.validate(data, schema, **options)

    except (jsonschema.ValidationError, jsonschema.SchemaError,
            Exception) as exc:
        if ac_schema_safe:
            return (False, str(exc))  # Validation was failed.
        raise

    return (True, '')
311567
def validate(self):
        
        log.info("{}\nValidating against {}"
                 .format("-" * 100, self.schema_def.__class__.__name__))

        if not self.schema_def:
            raise ValueError("No schema definition supplied.")

        self.checked_attributes = []

        # TODO - this should maybe choose the actually used namespace, not just
        # the first one in the list
        result = ValidationResult(self.allowed_namespaces[0],
                                  self.schema_def.__class__.__name__)
        for subject, predicate, object_ in self.graph:
            log.info("\nsubj: {subj}\npred: {pred}\n obj: {obj}"
                     .format(subj=subject, pred=predicate,
                             obj=object_.encode('utf-8')))
            result.add_error(self._check_triple((subject, predicate, object_)))
        return result
7979
def recursive_valid?(target, context, state)
      valid = state
      target.each do |key, prop|
        if prop.is_a?(Array)
          prop.each do |item|
            if item.validatable?
              valid = recursive_valid?(item, context, valid) && valid
            end
          end
        elsif prop.validatable?
          valid = recursive_valid?(prop, context, valid) && valid
        end
      end
      target._run_validate_callbacks do
        target.class.validators.execute(context, target) && valid
      end
    end
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());
        }
      }
    }
  }
1038968
protected void validate(List<TableInfo> tableInfos)
    {
        db = mongo.getDB(databaseName);
        if (db == null)
        {
            logger.error("Database " + databaseName + "does not exist");
            throw new SchemaGenerationException("database " + databaseName + "does not exist", "mongoDb", databaseName);
        }
        else
        {
            for (TableInfo tableInfo : tableInfos)
            {
                if (tableInfo.getLobColumnInfo().isEmpty())
                {
                    if (!db.collectionExists(tableInfo.getTableName()))
                    {
                        logger.error("Collection " + tableInfo.getTableName() + "does not exist in db " + db.getName());
                        throw new SchemaGenerationException("Collection " + tableInfo.getTableName()
                                + " does not exist in db " + db.getName(), "mongoDb", databaseName,
                                tableInfo.getTableName());
                    }
                }
                else
                {
                    checkMultipleLobs(tableInfo);
                    if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.FILES))
                    {
                        logger.error("Collection " + tableInfo.getTableName() + MongoDBUtils.FILES
                                + "does not exist in db " + db.getName());
                        throw new SchemaGenerationException("Collection " + tableInfo.getTableName()
                                + " does not exist in db " + db.getName(), "mongoDb", databaseName,
                                tableInfo.getTableName());
                    }
                    if (!db.collectionExists(tableInfo.getTableName() + MongoDBUtils.CHUNKS))
                    {
                        logger.error("Collection " + tableInfo.getTableName() + MongoDBUtils.CHUNKS
                                + "does not exist in db " + db.getName());
                        throw new SchemaGenerationException("Collection " + tableInfo.getTableName()
                                + " does not exist in db " + db.getName(), "mongoDb", databaseName,
                                tableInfo.getTableName());
                    }

                }
            }
        }
    }