ajv/spec/tests/rules/items.json

141 lines
3.3 KiB
JSON

[
{
"description": "items with empty schema",
"schema": {
"items": [{}],
"additionalItems": { "type": "string" }
},
"tests": [
{
"description": "array with second string is valid",
"data": [1, "a"],
"valid": true
},
{
"description": "array with second number is invalid",
"data": [1, 2],
"valid": false
}
]
},
{
"description": "items with subitems",
"schema": {
"definitions": {
"child": {
"type": "array",
"additionalItems": false,
"items": [
{ "$ref": "#/definitions/sub-child" },
{ "$ref": "#/definitions/sub-child" }
]
},
"sub-child": {
"type": "object",
"properties": { "foo": {} },
"required": ["foo"],
"additionalProperties": false
}
},
"type": "array",
"additionalItems": false,
"items": [
{ "$ref": "#/definitions/child" },
{ "$ref": "#/definitions/child" },
{ "$ref": "#/definitions/child" }
]
},
"tests": [
{
"description": "valid items",
"data": [
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": true
},
{
"description": "too many children",
"data": [
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "too many sub-children",
"data": [
[ {"foo": null}, {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "wrong child",
"data": [
{"foo": null},
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "wrong sub-child",
"data": [
[ {"bar": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ],
[ {"foo": null}, {"foo": null} ]
],
"valid": false
},
{
"description": "fewer children is valid",
"data": [
[ {"foo": null} ],
[ {"foo": null} ]
],
"valid": true
}
]
},
{
"description": "deeply nested items",
"schema": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "array",
"items": {
"type": "number"
}
}
}
}
},
"tests": [
{
"description": "valid nested array",
"data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]],
"valid": true
},
{
"description": "nested array with invalid type",
"data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]],
"valid": false
},
{
"description": "not deep enough",
"data": [[[1], [2],[3]], [[4], [5], [6]]],
"valid": false
}
]
}
]