TV4:获取检测到的错误的更多详细信息
TV4: to get more details of detected errors
我正在使用 tv4 检测模式错误。
我尝试使用以下方法获取所有结果:tv4.validateMultiple
检测到多个错误但未说明错误位置或原因的调用。
tv4 有没有办法提供更详尽的故障信息?
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"
我想这对 tv4 来说是不可能的,因为该模块没有更多的增强功能。另一方面,ajv 提供了更好的结果:
var ajv = new Ajv({allErrors: true});
//define some schema
schema = {...};
//validate with some invalid schema
ajv.validate(schema,{s:'a'});
console.log(ajv.errors);
找到以下结果:
dataPath:""
keyword:"additionalProperties"
message:"should NOT have additional properties"
params:{}
additionalProperty:"s"
schemaPath:"#/additionalProperties"
我正在使用 tv4 检测模式错误。
我尝试使用以下方法获取所有结果:tv4.validateMultiple
检测到多个错误但未说明错误位置或原因的调用。
tv4 有没有办法提供更详尽的故障信息?
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"
我想这对 tv4 来说是不可能的,因为该模块没有更多的增强功能。另一方面,ajv 提供了更好的结果:
var ajv = new Ajv({allErrors: true});
//define some schema
schema = {...};
//validate with some invalid schema
ajv.validate(schema,{s:'a'});
console.log(ajv.errors);
找到以下结果:
dataPath:""
keyword:"additionalProperties"
message:"should NOT have additional properties"
params:{}
additionalProperty:"s"
schemaPath:"#/additionalProperties"