Skip to content

Erroneous reference values yield unhelpful error messages #86

Description

@eliaspaulpeschke

Hi!

I was trying to validate JSON data against the URI "#/definitions/Patient" of a schema ( this one ) by creating my validator like this:

function(data, schema, cache_env) {
  if (is.null(cache_env)) {
    ref <- get_json_schema_reference(the_var)
    cache_env$json_validator <-
      jsonvalidate::json_schema$new(
        schema = schema,
        engine = ajv,
        strict = TRUE,
        reference = ref
      )
  }
  cache_env$json_validator$validate(
    json = data,
    verbose = TRUE,
    greedy = TRUE
  )

And had my reference set to wrong values. The error I got was:

Error: TypeError: validator is not a function

Because in this line in js/in.js,
ret = ret.addSchema(drop_id(schema), filename).getSchema(reference);
just turns ret to undefined if the reference is wrong. I think it would be very helpful to add some test here or even return an optional type to R for checking.

Also I think it would be helpful to add info about the use of drop_id and that the base of the URI you need to use is the basename of the file to the function reference. For me, that was a little misleading.

Thanks for your work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions