R/validation.R

SCHEMA <- system.file("json", "manifest_schema.json", package = "fastgenomicsR")
#' Checks the manifest against the schema
validate_manifest <-
  function(manifest_path) {
    v <- jsonvalidate::json_validator(SCHEMA)
    validation <- v(manifest_path, verbose = TRUE, greedy = TRUE)
    
    if (!validation) {
      errors <- attr(validation, "errors")
      validation_errors <- paste(Map(function(x, y) {
        paste(x, y, sep = " ")
      }, errors$field, errors$message),
      collapse = "\n")
      
      stop(
        stringr::str_interp(
          "${manifest_path} failed validation with the following errors:\n${validation_errors}"
        )
      )
    }
  }
FASTGenomics/fastgenomicsR documentation built on June 26, 2019, 12:38 p.m.