Skip to content

[Request] Hard to provide error message on JavaScript port #752

@climba03003

Description

@climba03003

I am trying to use the JavaScript port and try to replace the ajv implementation.
The current difficultly is hard to form error message even with the tracing callback.

const instance = { name: "John", age: 30 };
const result = evaluator.validate(instance, (type, valid, instruction, evaluatePath, instanceLocation, annotation) => {
  // type - the pre / post information is useless for error message
  // instruction - information for the validator, hard to use
  // valid - information to know which instanceLocation is invalid
  // evaluatePath - schema pointer
  // instanceLocation - property pointer
  // annotation - not discovered how to use
});
console.log(result); // true or false

From the evaluation callback, the only useful information are

  1. valid - Used to identify which schema location is not valid.
  2. evaluatePath - Used to form the error message where is not valid.
  3. instanceLocation - Used to form the error message where is not valid.

It is still missing the information of why it is not valid on the location.

For example, a simple type validation.

{
  "type": "boolean"
}

We can only use the information on evaluatePath to tell the type is not match.
But we can never tell which type it should be.

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