当自定义关键字在AJV中具有对象时,$ data引用无法解析

时间:2019-07-19 02:24:45

标签: javascript ajv

我有一个如下所示的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支持还是我只是缺少什么?

0 个答案:

没有答案