たとえば、ファイル システムのスキーマの場合、ディレクトリにはファイルのリストが含まれます。スキーマは、ファイルの指定、次のサブタイプ「イメージ」、もう 1 つの「テキスト」で構成されます。
下部には、メイン ディレクトリ スキーマがあります。ディレクトリには、ファイルのサブタイプであるアイテムの配列であるプロパティ content があります。
基本的に私が探しているのは、検証対象の json オブジェクトのプロパティから "$ref" の値を検索するようにバリデーターに指示する方法です。
json の例:
{
"name":"A directory",
"content":[
{
"fileType":"http://x.y.z/fs-schema.json#definitions/image",
"name":"an-image.png",
"width":1024,
"height":800
}
{
"fileType":"http://x.y.z/fs-schema.json#definitions/text",
"name":"readme.txt",
"lineCount":101
}
{
"fileType":"http://x.y.z/extended-fs-schema-video.json",
"name":"demo.mp4",
"hd":true
}
]
}
「疑似」スキーマでは、「画像」と「テキスト」の定義は同じスキーマに含まれていますが、別の場所で定義されている可能性があることに注意してください。
{
"id": "http://x.y.z/fs-schema.json",
"definitions": {
"file": {
"type": "object",
"properties": {
"name": { "type": "string" },
"fileType": {
"type": "string",
"format": "uri"
}
}
},
"image": {
"allOf": [
{ "$ref": "#definitions/file" },
{
"properties": {
"width": { "type": "integer" },
"height": { "type": "integer"}
}
}
]
},
"text": {
"allOf": [
{ "$ref": "#definitions/file" },
{ "properties": { "lineCount": { "type": "integer"}}}
]
}
},
"type": "object",
"properties": {
"name": { "type": "string"},
"content": {
"type": "array",
"items": {
"allOf": [
{ "$ref": "#definitions/file" },
{ *"$refFromProperty"*: "fileType" } // the magic thing
]
}
}
}
}