【发布时间】:2017-03-11 10:10:17
【问题描述】:
以下是我尝试编译并用于验证的 JSON 模式示例。为此,我使用'ajv' npm module。
这是我正在运行的代码...
var ajv = require('ajv')();
var contactSchema = {
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Contact",
"type": "object",
"additionalProperties": false,
"properties": {
"work": { "$ref": "#definitions/phone" },
"home": { "$ref": "#definitions/phone" },
},
"definitions": {
"phone": {
"type": "object",
"required": ["number"],
"properties": {
"number": { "type": "string" },
"extension": { "type": "string" }
}
}
}
};
var validator = ajv.compile(contactSchema);
当我运行这段代码时,我得到了以下异常..
Error: can't resolve reference #definitions/phone from id #
还有其他人遇到过这种问题吗?知道我可能做错了什么吗?
【问题讨论】:
标签: node.js jsonschema ajv