我有一个如下所示的JSON模式,我正在使用AJV进行编译并进行验证:
const validate = ajv.compile({
type: "object",
properties: {
someone: {
type: "string"
},
something: {
type: "string",
dependsOnData: {
some: "keyword",
related: "things",
depends: {
$data: "/someone"
}
}
}
}
});
validate({
someone: "someone here",
something: "something here"
});
以及自定义关键字定义:
ajv.addKeyword("dependsOnData", {
$data: true,
validate: (keywordSchema, value) => {
console.log(keywordSchema.depends); // --> { $data: "/someone" }
return true;
}
});
我还确保了AJV实例已设置$data: true
。
$data
引用从未解决。这是AJV支持还是我只是缺少什么?