1

スキーマに対してjsonを検証できません:

スキーマは次のとおりです。

{
"type":"object",
"$schema": "http://json-schema.org/draft-03/schema",
"required":true,
"properties":{
    "tagId": {
            "type":"string",
            "id": "tagId",
            "required":true
    },
    "data_library": {
        "type":"object",
        "id": "data_library",
        "properties":{
            "info": {
                "type":"object",
                "id": "info_library",
                "properties":{
                    "name": {
                        "type":"string",
                        "id": "name",
                        "required":true
                    },
                    "location": {
                        "type":"string",
                        "id": "location",
                        "required":true
                    },
                    "description": {
                        "type":"string",
                        "id": "description",
                        "required":true
                    },
                    "starttime": {
                        "type":"string",
                        "id": "starttime",
                        "required":true
                    },
                    "endtime": {
                        "type":"string",
                        "id": "endtime",
                        "required":true
                    },
                    "contact": {
                        "type":"string",
                        "id": "contact",
                        "required":true
                    }                           
                }
            },
            "videos": {
                "type":"array",
                "minitems": "0",
                "id": "videos",
                "items":
                {
                    "type":"string",
                    "required":true
                }
            },
            "images": {
                "type":"array",
                "minitems": "0",
                "id": "images",
                "items":
                {
                    "type":"string",
                    "required":true
                }
            }
        },
        "additionalProperties": false,
        "minProperties": 1
    },
    "data_book": {
        "type":"object",
        "id": "data_book",
        "properties":{
            "info": {
                "type":"object",
                "id": "info_book",
                "properties":{
                    "name": {
                        "type":"string",
                        "id": "name",
                        "required":true
                    },
                    "genre": {
                        "type":"string",
                        "id": "genre",
                        "required":true
                    },
                    "description": {
                        "type":"string",
                        "id": "description",
                        "required":true
                    },
                    "agegroup": {
                        "type":"string",
                        "id": "agegroup",
                        "required":true
                    },
                    "author": {
                        "type":"string",
                        "id": "author",
                        "required":true
                    },
                    "publisher": {
                        "type":"string",
                        "id": "publisher",
                        "required":true
                    }       
                }
            },
            "videos": {
                "type":"array",
                "minitems": "0",
                "id": "videos",
                "items":
                {
                    "type":"string",
                    "required":true
                }
            },
            "images": {
                "type":"array",
                "minitems": "0",
                "id": "images",
                "items":
                {
                    "type":"string",
                    "required":true
                }
            }
        },
        "additionalProperties": false,
        "minProperties": 1
    }
},
"oneOf": [
    {"required": ["data_library"]},
    {"required": ["data_book"]}
]

}

現在の要件は、json で data_library または data_book をサポートすることです。ただし、次のデータを検証しようとすると:

{
    "tagId" : "DFGDASERTGSDG",
    "data_book" : {
            "info" :        {
                    "name" : "Pagdandi",
                    "location" : "Kaccha",
                    "description" : "..",
                    "starttime" : "..",
                    "endtime" : "..",
                    "contact" : ".."
            },
            "videos" :      [
                    "https://..."
            ],
            "images" :      [
                    "https://..."
            ]
    }

}

次のエラーが表示されます。

Property: data_book.info.genre Msg:Is missing and it is requiredProperty: data_book.info.agegroup Msg:Is missing and it is requiredProperty: data_book.info.author Msg:Is missing and it is requiredProperty: data_book.info.publisher Msg:Is missing and it is required

私が間違っているのは何ですか?

4

1 に答える 1

0

JSON Schema Draft 3 を使用していると宣言していますが、ブロック内のoneOf使用法は Draft 4 です。requiredoneOf

すべてのrequiredキーワード ステートメントをドラフト 4 形式に変換すると、スキーマはドラフト 4 バリデーターを使用して検証されます。

ドラフト 3 ですべてを機能させるにはどうすればよいかわかりません。それが可能かどうかさえわかりません。このような場合を表現できるように、Draft 4でlike のキーワードの追加とoneOf新しい形式の ofが追加されたと思います。required

これが機能するドラフト4バージョンです。

{
    "$schema": "http://json-schema.org/draft-04/schema",
    "type": "object",
    "properties": {
        "tagId": { "type": "string" },
        "data_library": {
            "type": "object",
            "properties": {
                "info": {
                    "type": "object",
                    "properties": {
                        "name": { "type": "string" },
                        "location": { "type": "string" },
                        "description": { "type": "string" },
                        "starttime": { "type": "string" },
                        "endtime": { "type": "string" },
                        "contact": { "type": "string" }
                    },
                    "required": ["name", "location", "description", "starttime", "endtime", "contact"]
                },
                "videos": {
                    "type": "array",
                    "items": { "type": "string" }
                },
                "images": {
                    "type": "array",
                    "items": { "type": "string" }
                }
            },
            "additionalProperties": false,
            "minProperties": 1
        },
        "data_book": {
            "type": "object",
            "properties": {
                "info": {
                    "type": "object",
                    "properties": {
                        "name": { "type": "string" },
                        "genre": { "type": "string" },
                        "description": { "type": "string" },
                        "agegroup": { "type": "string" },
                        "author": { "type": "string" },
                        "publisher": { "type": "string" }
                    },
                    "required": ["name", "genre", "description", "agegroup", "author", "publisher"]
                },
                "videos": {
                    "type": "array",
                    "items": { "type": "string" }
                },
                "images": {
                    "type": "array",
                    "items": { "type": "string" }
                }
            },
            "additionalProperties": false,
            "minProperties": 1
        }
    },
    "required": ["tagId"],
    "anyOf": [
        { "required": ["data_library"] },
        { "required": ["data_book"] }
    ]
}
于 2015-08-09T07:53:21.540 に答える