R/ir_validate.R

Defines functions ir_validate_create_validator ir_validate_against_schema ir_validate

ir_validate <- function(x, error = FALSE) {
  ir_validate_against_schema(x, error)
}


ir_validate_against_schema <- function(x, error) {
  if (is.null(.odin$validator)) {
    .odin$validator <- ir_validate_create_validator()
  }
  .odin$validator(x, verbose = TRUE, greedy = TRUE, error = error)
}


ir_validate_create_validator <- function() {
  path <- odin_file("schema.json")
  schema <- read_string(path)

  ## We get somewhat better errors from jsonlite's parsers than hoping
  ## that the json is valid.
  jsonlite::fromJSON(schema)

  jsonvalidate::json_validator(schema, engine = "ajv")
}
richfitz/odin documentation built on Feb. 23, 2024, 1:11 p.m.