我可以在验证自定义关键字时检查以前生成的验证错误吗?
这是迄今为止我能想到的最好的:
ajv.addKeyword('fromInput',{
modifying:true,
compile: function (schema, parentSchema, it){
return function () {
// console.log(it)
return true;
}
},
errors: true
});
请注意,我使用该选项定义“compile:”fn 只是因为该选项允许“it”上下文,因此我可以从那里访问“it”或“it.self”。
为了清楚起见,并确认我正确解释了此功能(?),我将自定义关键字放在架构中的最后,因此我假设在验证时所有先前的关键字都将被验证并生成错误。
因此,在验证这个自定义关键字的过程中,我需要访问这些验证错误并据此做出一些决定。
但是,我不知道从这里去哪里(见上面的代码),因为在调试器中我没有看到任何错误。
it.self
确实有一个“错误”属性,但它是=null
.