javascriptnode.jstv4

TV4: to get more details of detected errors


I am using tv4 to detect schema errors. I tried getting all results using: tv4.validateMultiple call which detected multiple errors but did not say where or why.

Is there any way in tv4 to provide more elaborate information of failures?

var res = tv4.validateMultiple(data, schema,null,true);

errors:[]
0:{}
message:"Missing required property: coMMand"
name:"ValidationError"
type:"Error"
1:{}
message:"Unknown property (not in schema)"
name:"ValidationError"
type:"Error"
2:{}
message:"Unknown property (not in schema)"
name:"ValidationError"
type:"Error"

Solution

  • I guess this is not possible to do with tv4 and since there is not being any more enhancements to the module. The ajv on the other hand provides better results:

    var ajv = new Ajv({allErrors: true});
    //define some schema
    schema = {...};
    //validate with some invalid schema
    ajv.validate(schema,{s:'a'});
    console.log(ajv.errors);
    

    Following result is found:

    dataPath:""
    keyword:"additionalProperties"
    message:"should NOT have additional properties"
    params:{}
    additionalProperty:"s"
    schemaPath:"#/additionalProperties"