【问题标题】:TV4: to get more details of detected errorsTV4:获取检测到的错误的更多详细信息
【发布时间】:2017-10-25 06:08:06
【问题描述】:

我正在使用 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"

【问题讨论】:

    标签: javascript node.js tv4


    【解决方案1】:

    我猜这不可能用 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"
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-27
      • 1970-01-01
      • 2011-01-31
      • 2012-12-26
      • 1970-01-01
      相关资源
      最近更新 更多