В схемах JSON вы можете либо поместить схему для каждого файла, а затем получить к ним доступ, используя их URL (там, где вы их сохранили), либо большую схему с тегами id
.
Вот один большойfile:
{
"id": "#root",
"properties": {
"author": {
"id": "#author",
"properties": {
"first_name": {
"type": "string"
},
"last_name": {
"type": "string"
}
},
"type": "object"
},
// author
"author_api": {
"id": "#author_api",
"items": {
"$ref": "author"
},
"type": "array"
},
// authors API
"book": {
"id": "#book",
"properties": {
"author": {
"type": "string"
},
"title": {
"type": "string"
}
},
"type": "object"
},
// books API: list of books written by same author
"books_api": {
"id": "#books_api",
"properties": {
"author": {
"$ref": "author"
},
"books": {
"items": {
"$ref": "book"
},
"type": "array"
}
},
"type": "object"
}
}
}
Затем вы можете сослаться на свой валидатор на одну из этих подсхем (которые определены с помощью id
).
Снаружи вашей схемы это:
{ "$ref": "url://to/your/schema#root/properties/book" }
эквивалентно этому:
{ "$ref": "url://to/your/schema#book" }
… что эквивалентно изнутри этому:
{ "$ref": "#root/properties/book" }
или этому (еще изнутри):
{ "$ref": "#book" }
См. Мой ответ здесь для получения дополнительной информации.