xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft6/items.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "a schema given for items",
4        "schema": {
5            "items": {"type": "integer"}
6        },
7        "tests": [
8            {
9                "description": "valid items",
10                "data": [ 1, 2, 3 ],
11                "valid": true
12            },
13            {
14                "description": "wrong type of items",
15                "data": [1, "x"],
16                "valid": false
17            },
18            {
19                "description": "ignores non-arrays",
20                "data": {"foo" : "bar"},
21                "valid": true
22            },
23            {
24                "description": "JavaScript pseudo-array is valid",
25                "data": {
26                    "0": "invalid",
27                    "length": 1
28                },
29                "valid": true
30            }
31        ]
32    },
33    {
34        "description": "an array of schemas for items",
35        "schema": {
36            "items": [
37                {"type": "integer"},
38                {"type": "string"}
39            ]
40        },
41        "tests": [
42            {
43                "description": "correct types",
44                "data": [ 1, "foo" ],
45                "valid": true
46            },
47            {
48                "description": "wrong types",
49                "data": [ "foo", 1 ],
50                "valid": false
51            },
52            {
53                "description": "incomplete array of items",
54                "data": [ 1 ],
55                "valid": true
56            },
57            {
58                "description": "array with additional items",
59                "data": [ 1, "foo", true ],
60                "valid": true
61            },
62            {
63                "description": "empty array",
64                "data": [ ],
65                "valid": true
66            },
67            {
68                "description": "JavaScript pseudo-array is valid",
69                "data": {
70                    "0": "invalid",
71                    "1": "valid",
72                    "length": 2
73                },
74                "valid": true
75            }
76        ]
77    },
78    {
79        "description": "items with boolean schema (true)",
80        "schema": {"items": true},
81        "tests": [
82            {
83                "description": "any array is valid",
84                "data": [ 1, "foo", true ],
85                "valid": true
86            },
87            {
88                "description": "empty array is valid",
89                "data": [],
90                "valid": true
91            }
92        ]
93    },
94    {
95        "description": "items with boolean schema (false)",
96        "schema": {"items": false},
97        "tests": [
98            {
99                "description": "any non-empty array is invalid",
100                "data": [ 1, "foo", true ],
101                "valid": false
102            },
103            {
104                "description": "empty array is valid",
105                "data": [],
106                "valid": true
107            }
108        ]
109    },
110    {
111        "description": "items with boolean schemas",
112        "schema": {
113            "items": [true, false]
114        },
115        "tests": [
116            {
117                "description": "array with one item is valid",
118                "data": [ 1 ],
119                "valid": true
120            },
121            {
122                "description": "array with two items is invalid",
123                "data": [ 1, "foo" ],
124                "valid": false
125            },
126            {
127                "description": "empty array is valid",
128                "data": [],
129                "valid": true
130            }
131        ]
132    },
133    {
134        "description": "items and subitems",
135        "schema": {
136            "definitions": {
137                "item": {
138                    "type": "array",
139                    "additionalItems": false,
140                    "items": [
141                        { "$ref": "#/definitions/sub-item" },
142                        { "$ref": "#/definitions/sub-item" }
143                    ]
144                },
145                "sub-item": {
146                    "type": "object",
147                    "required": ["foo"]
148                }
149            },
150            "type": "array",
151            "additionalItems": false,
152            "items": [
153                { "$ref": "#/definitions/item" },
154                { "$ref": "#/definitions/item" },
155                { "$ref": "#/definitions/item" }
156            ]
157        },
158        "tests": [
159            {
160                "description": "valid items",
161                "data": [
162                    [ {"foo": null}, {"foo": null} ],
163                    [ {"foo": null}, {"foo": null} ],
164                    [ {"foo": null}, {"foo": null} ]
165                ],
166                "valid": true
167            },
168            {
169                "description": "too many items",
170                "data": [
171                    [ {"foo": null}, {"foo": null} ],
172                    [ {"foo": null}, {"foo": null} ],
173                    [ {"foo": null}, {"foo": null} ],
174                    [ {"foo": null}, {"foo": null} ]
175                ],
176                "valid": false
177            },
178            {
179                "description": "too many sub-items",
180                "data": [
181                    [ {"foo": null}, {"foo": null}, {"foo": null} ],
182                    [ {"foo": null}, {"foo": null} ],
183                    [ {"foo": null}, {"foo": null} ]
184                ],
185                "valid": false
186            },
187            {
188                "description": "wrong item",
189                "data": [
190                    {"foo": null},
191                    [ {"foo": null}, {"foo": null} ],
192                    [ {"foo": null}, {"foo": null} ]
193                ],
194                "valid": false
195            },
196            {
197                "description": "wrong sub-item",
198                "data": [
199                    [ {}, {"foo": null} ],
200                    [ {"foo": null}, {"foo": null} ],
201                    [ {"foo": null}, {"foo": null} ]
202                ],
203                "valid": false
204            },
205            {
206                "description": "fewer items is valid",
207                "data": [
208                    [ {"foo": null} ],
209                    [ {"foo": null} ]
210                ],
211                "valid": true
212            }
213        ]
214    },
215    {
216        "description": "nested items",
217        "schema": {
218            "type": "array",
219            "items": {
220                "type": "array",
221                "items": {
222                    "type": "array",
223                    "items": {
224                        "type": "array",
225                        "items": {
226                            "type": "number"
227                        }
228                    }
229                }
230            }
231        },
232        "tests": [
233            {
234                "description": "valid nested array",
235                "data": [[[[1]], [[2],[3]]], [[[4], [5], [6]]]],
236                "valid": true
237            },
238            {
239                "description": "nested array with invalid type",
240                "data": [[[["1"]], [[2],[3]]], [[[4], [5], [6]]]],
241                "valid": false
242            },
243            {
244                "description": "not deep enough",
245                "data": [[[1], [2],[3]], [[4], [5], [6]]],
246                "valid": false
247            }
248        ]
249    },
250    {
251        "description": "single-form items with null instance elements",
252        "schema": {
253            "items": {
254                "type": "null"
255            }
256        },
257        "tests": [
258            {
259                "description": "allows null elements",
260                "data": [ null ],
261                "valid": true
262            }
263        ]
264    },
265    {
266        "description": "array-form items with null instance elements",
267        "schema": {
268            "items": [
269                {
270                    "type": "null"
271                }
272            ]
273        },
274        "tests": [
275            {
276                "description": "allows null elements",
277                "data": [ null ],
278                "valid": true
279            }
280        ]
281    }
282]
283