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