【发布时间】:2021-06-06 13:57:44
【问题描述】:
我正在使用ajv,我只想验证一个特定的属性。我的架构是:
{
properties:{
dog:{type:"string"}
}
}
我想知道foo 是否是一只有效的狗。
我愿意:
const ajv = new AjvModule.default({ removeAdditional: "all", coerceTypes: true});
ajv.addSchema(require("./schemas/the_above_schema.json"))
ajv.validate(`#/dog`, 'foo');
但我得到了错误:Error: no schema with key or ref "#/dog"
我也试过:`ajv.addSchema(require("./schemas/the_above_schema.json"), 'dog_schema')
和ajv.validate(dog_schema#/dog`, 'foo')
我错过了什么?
【问题讨论】:
标签: json jsonschema ajv