在JSON模式中,您可以为每个文件放置一个模式,然后使用其URL(存储它们的位置)或带有
id标签的大模式来访问它们。
这是一个大文件:
{ "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" }


