我希望在文件中捕获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" }
}
}
}
Run Code Online (Sandbox Code Playgroud)
以下解决方案为我工作:
"results": {
"$ref": "file:src/test/resources/schemas/results.json"
}
Run Code Online (Sandbox Code Playgroud)
以上解决方案满足我的要求:
| 归档时间: |
|
| 查看次数: |
6283 次 |
| 最近记录: |