{"size": 1143, "ext": "js", "max_stars_repo_path": "src/utils/validationService.js", "max_stars_repo_name": "SergeiSemenkov/SchemaEditor", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/utils/validationService.js", "max_issues_repo_name": "SergeiSemenkov/SchemaEditor", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/utils/validationService.js", "max_forks_repo_name": "SergeiSemenkov/SchemaEditor", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.5813953488, "max_line_length": 93, "alphanum_fraction": 0.6666666667}
export default function validate(schema, doc) {
  const errorList = []

  validateAttibutes(schema, doc)

  return errorList 
}

export function validateAttibutes (element, description) {
  const errorList = []

  description.attributes.forEach(attribute => {
    const attrValue = element.getAttribute(attribute.name)
    const required = attribute.required === 'true'
    if (required && !attrValue) {
      errorList.push({
        error: `Required attribute (${attribute.name}) is missing`,
        element: element,
        attribute: attribute.name
      })
    }
  });
  return errorList
}

export function validateObjects (element, description, getPossibleElementsFn) {
  const errorList = []

  description.objects.forEach(object => {
    const possibleElements = getPossibleElementsFn(object.type)
    const objectEl = element.querySelector(`:scope > ${possibleElements.join(', :scope >')}`)
    const required = object.required === 'true'

    if (required && !objectEl) {
      errorList.push({
        error: `Required child object (${object.name}) is missing`,
        element: element
      })
    }
  });
  return errorList
}
 