简体   繁体   中英

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"

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM