我希望在文件中捕获json模式的公共部分,然后从主模式文件中引用此文件。所以基本上代替了1个大的json模式文件,多个文件相互引用。我使用json-schema-validator lib来验证。
E.g:
$ 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" }
}
}
}
答案 0 :(得分:7)
以下解决方案为我工作:
"results": {
"$ref": "file:src/test/resources/schemas/results.json"
}
上述解决方案满足我的要求:
答案 1 :(得分:0)
我就是这样做的:
从应用程序的根目录提供以下文件结构:
MPI_Reduce(local, global, 1, mpi_datatype, mpi_selectop, 0, MPI_COMM_WORLD);
response_schema.json:
/schemas/
response_schema.json
results_schema.json
results_schema.json:
{
"$schema": "http://json-schema.org/draft-04/schema",
"id": "resource:/schemas/response_schema#",
"type": "object",
"required": [ "results" ],
"properties": {
"results": {
"type": "object",
"$ref": "results_schema.json"
}
}
进行了验证