【发布时间】:2013-08-22 09:14:58
【问题描述】:
我希望将 json 架构的公共部分捕获到一个文件中,然后从主架构文件中引用该文件。所以基本上不是 1 个大的 json 模式文件,而是多个相互引用的文件。我正在使用json-schema-validator lib 进行验证。
例如:
$ ls schemas/
response_schema.json results_schema.json
$ cat schemas/response_schema.json
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "object",
"required": [ "results" ],
"properties": {
"results": "####Reference results_schema.json file here somehow####"
}
}
$ cat schemas/results_schema.json
{
"$schema": "http://json-schema.org/draft-04/schema",
"type": "array",
"items": {
"type": "object",
"required": ["type", "name"],
"properties": {
"name": { "type": "string" },
"dateOfBirth": { "type": "string" }
}
}
}
【问题讨论】:
-
感谢原子人。挖掘更多发现部分答案。
"results": { "$ref": "file://localhost/c:/eclipse-workspaces/myproject/src/test/resources/schemas/results.json" }仍然不知道如何给出相对路径! -
尝试将其推送到您的服务器,并使用
./resources/schemas/results.json作为参考。我不知道这是否可行,但您至少应该在控制台中看到完整的 url,因为库试图解决它。
标签: json jsonschema