xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft2019-09/additionalItems.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "additionalItems as schema",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/2019-09/schema",
6            "items": [{}],
7            "additionalItems": {"type": "integer"}
8        },
9        "tests": [
10            {
11                "description": "additional items match schema",
12                "data": [ null, 2, 3, 4 ],
13                "valid": true
14            },
15            {
16                "description": "additional items do not match schema",
17                "data": [ null, 2, 3, "foo" ],
18                "valid": false
19            }
20        ]
21    },
22    {
23        "description": "when items is schema, additionalItems does nothing",
24        "schema": {
25            "$schema":"https://json-schema.org/draft/2019-09/schema",
26            "items": {
27                "type": "integer"
28            },
29            "additionalItems": {
30                "type": "string"
31            }
32        },
33        "tests": [
34            {
35                "description": "valid with a array of type integers",
36                "data": [1,2,3],
37                "valid": true
38            },
39            {
40                "description": "invalid with a array of mixed types",
41                "data": [1,"2","3"],
42                "valid": false
43            }
44        ]
45    },
46    {
47        "description": "when items is schema, boolean additionalItems does nothing",
48        "schema": {
49            "$schema": "https://json-schema.org/draft/2019-09/schema",
50            "items": {},
51            "additionalItems": false
52        },
53        "tests": [
54            {
55                "description": "all items match schema",
56                "data": [ 1, 2, 3, 4, 5 ],
57                "valid": true
58            }
59        ]
60    },
61    {
62        "description": "array of items with no additionalItems permitted",
63        "schema": {
64            "$schema": "https://json-schema.org/draft/2019-09/schema",
65            "items": [{}, {}, {}],
66            "additionalItems": false
67        },
68        "tests": [
69            {
70                "description": "empty array",
71                "data": [ ],
72                "valid": true
73            },
74            {
75                "description": "fewer number of items present (1)",
76                "data": [ 1 ],
77                "valid": true
78            },
79            {
80                "description": "fewer number of items present (2)",
81                "data": [ 1, 2 ],
82                "valid": true
83            },
84            {
85                "description": "equal number of items present",
86                "data": [ 1, 2, 3 ],
87                "valid": true
88            },
89            {
90                "description": "additional items are not permitted",
91                "data": [ 1, 2, 3, 4 ],
92                "valid": false
93            }
94        ]
95    },
96    {
97        "description": "additionalItems as false without items",
98        "schema": {
99            "$schema": "https://json-schema.org/draft/2019-09/schema",
100            "additionalItems": false
101        },
102        "tests": [
103            {
104                "description":
105                    "items defaults to empty schema so everything is valid",
106                "data": [ 1, 2, 3, 4, 5 ],
107                "valid": true
108            },
109            {
110                "description": "ignores non-arrays",
111                "data": {"foo" : "bar"},
112                "valid": true
113            }
114        ]
115    },
116    {
117        "description": "additionalItems are allowed by default",
118        "schema": {
119            "$schema": "https://json-schema.org/draft/2019-09/schema",
120            "items": [{"type": "integer"}]
121        },
122        "tests": [
123            {
124                "description": "only the first item is validated",
125                "data": [1, "foo", false],
126                "valid": true
127            }
128        ]
129    },
130    {
131        "description": "additionalItems does not look in applicators, valid case",
132        "schema": {
133            "$schema": "https://json-schema.org/draft/2019-09/schema",
134            "allOf": [
135                { "items": [ { "type": "integer" } ] }
136            ],
137            "additionalItems": { "type": "boolean" }
138        },
139        "tests": [
140            {
141                "description": "items defined in allOf are not examined",
142                "data": [ 1, null ],
143                "valid": true
144            }
145        ]
146    },
147    {
148        "description": "additionalItems does not look in applicators, invalid case",
149        "schema": {
150            "$schema": "https://json-schema.org/draft/2019-09/schema",
151            "allOf": [
152                { "items": [ { "type": "integer" }, { "type": "string" } ] }
153            ],
154            "items": [ {"type": "integer" } ],
155            "additionalItems": { "type": "boolean" }
156        },
157        "tests": [
158            {
159                "description": "items defined in allOf are not examined",
160                "data": [ 1, "hello" ],
161                "valid": false
162            }
163        ]
164    },
165    {
166        "description": "items validation adjusts the starting index for additionalItems",
167        "schema": {
168            "$schema": "https://json-schema.org/draft/2019-09/schema",
169            "items": [ { "type": "string" } ],
170            "additionalItems": { "type": "integer" }
171        },
172        "tests": [
173            {
174                "description": "valid items",
175                "data": [ "x", 2, 3 ],
176                "valid": true
177            },
178            {
179                "description": "wrong type of second item",
180                "data": [ "x", "y" ],
181                "valid": false
182            }
183        ]
184    },
185    {
186        "description": "additionalItems with heterogeneous array",
187        "schema": {
188            "$schema": "https://json-schema.org/draft/2019-09/schema",
189            "items": [{}],
190            "additionalItems": false
191        },
192        "tests": [
193            {
194                "description": "heterogeneous invalid instance",
195                "data": [ "foo", "bar", 37 ],
196                "valid": false
197            },
198            {
199                "description": "valid instance",
200                "data": [ null ],
201                "valid": true
202            }
203        ]
204    },
205    {
206        "description": "additionalItems with null instance elements",
207        "schema": {
208            "$schema": "https://json-schema.org/draft/2019-09/schema",
209            "additionalItems": {
210                "type": "null"
211            }
212        },
213        "tests": [
214            {
215                "description": "allows null elements",
216                "data": [ null ],
217                "valid": true
218            }
219        ]
220    }
221]
222