xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft2019-09/unevaluatedItems.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "unevaluatedItems true",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/2019-09/schema",
6            "unevaluatedItems": true
7        },
8        "tests": [
9            {
10                "description": "with no unevaluated items",
11                "data": [],
12                "valid": true
13            },
14            {
15                "description": "with unevaluated items",
16                "data": ["foo"],
17                "valid": true
18            }
19        ]
20    },
21    {
22        "description": "unevaluatedItems false",
23        "schema": {
24            "$schema": "https://json-schema.org/draft/2019-09/schema",
25            "unevaluatedItems": false
26        },
27        "tests": [
28            {
29                "description": "with no unevaluated items",
30                "data": [],
31                "valid": true
32            },
33            {
34                "description": "with unevaluated items",
35                "data": ["foo"],
36                "valid": false
37            }
38        ]
39    },
40    {
41        "description": "unevaluatedItems as schema",
42        "schema": {
43            "$schema": "https://json-schema.org/draft/2019-09/schema",
44            "unevaluatedItems": { "type": "string" }
45        },
46        "tests": [
47            {
48                "description": "with no unevaluated items",
49                "data": [],
50                "valid": true
51            },
52            {
53                "description": "with valid unevaluated items",
54                "data": ["foo"],
55                "valid": true
56            },
57            {
58                "description": "with invalid unevaluated items",
59                "data": [42],
60                "valid": false
61            }
62        ]
63    },
64    {
65        "description": "unevaluatedItems with uniform items",
66        "schema": {
67            "$schema": "https://json-schema.org/draft/2019-09/schema",
68            "items": { "type": "string" },
69            "unevaluatedItems": false
70        },
71        "tests": [
72            {
73                "description": "unevaluatedItems doesn't apply",
74                "data": ["foo", "bar"],
75                "valid": true
76            }
77        ]
78    },
79    {
80        "description": "unevaluatedItems with tuple",
81        "schema": {
82            "$schema": "https://json-schema.org/draft/2019-09/schema",
83            "items": [
84                { "type": "string" }
85            ],
86            "unevaluatedItems": false
87        },
88        "tests": [
89            {
90                "description": "with no unevaluated items",
91                "data": ["foo"],
92                "valid": true
93            },
94            {
95                "description": "with unevaluated items",
96                "data": ["foo", "bar"],
97                "valid": false
98            }
99        ]
100    },
101    {
102        "description": "unevaluatedItems with items and additionalItems",
103        "schema": {
104            "$schema": "https://json-schema.org/draft/2019-09/schema",
105            "items": [
106                { "type": "string" }
107            ],
108            "additionalItems": true,
109            "unevaluatedItems": false
110        },
111        "tests": [
112            {
113                "description": "unevaluatedItems doesn't apply",
114                "data": ["foo", 42],
115                "valid": true
116            }
117        ]
118    },
119    {
120        "description": "unevaluatedItems with ignored additionalItems",
121        "schema": {
122            "$schema": "https://json-schema.org/draft/2019-09/schema",
123            "additionalItems": {"type": "number"},
124            "unevaluatedItems": {"type": "string"}
125        },
126        "tests": [
127            {
128                "description": "invalid under unevaluatedItems",
129                "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema",
130                "data": ["foo", 1],
131                "valid": false
132            },
133            {
134                "description": "all valid under unevaluatedItems",
135                "data": ["foo", "bar", "baz"],
136                "valid": true
137            }
138        ]
139    },
140    {
141        "description": "unevaluatedItems with ignored applicator additionalItems",
142        "schema": {
143            "$schema": "https://json-schema.org/draft/2019-09/schema",
144            "allOf": [ { "additionalItems": { "type": "number" } } ],
145            "unevaluatedItems": {"type": "string"}
146        },
147        "tests": [
148            {
149                "description": "invalid under unevaluatedItems",
150                "comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema",
151                "data": ["foo", 1],
152                "valid": false
153            },
154            {
155                "description": "all valid under unevaluatedItems",
156                "data": ["foo", "bar", "baz"],
157                "valid": true
158            }
159        ]
160    },
161    {
162        "description": "unevaluatedItems with nested tuple",
163        "schema": {
164            "$schema": "https://json-schema.org/draft/2019-09/schema",
165            "items": [
166                { "type": "string" }
167            ],
168            "allOf": [
169                {
170                    "items": [
171                        true,
172                        { "type": "number" }
173                    ]
174                }
175            ],
176            "unevaluatedItems": false
177        },
178        "tests": [
179            {
180                "description": "with no unevaluated items",
181                "data": ["foo", 42],
182                "valid": true
183            },
184            {
185                "description": "with unevaluated items",
186                "data": ["foo", 42, true],
187                "valid": false
188            }
189        ]
190    },
191    {
192        "description": "unevaluatedItems with nested items",
193        "schema": {
194            "$schema": "https://json-schema.org/draft/2019-09/schema",
195            "unevaluatedItems": {"type": "boolean"},
196            "anyOf": [
197                { "items": {"type": "string"} },
198                true
199            ]
200        },
201        "tests": [
202            {
203                "description": "with only (valid) additional items",
204                "data": [true, false],
205                "valid": true
206            },
207            {
208                "description": "with no additional items",
209                "data": ["yes", "no"],
210                "valid": true
211            },
212            {
213                "description": "with invalid additional item",
214                "data": ["yes", false],
215                "valid": false
216            }
217        ]
218    },
219    {
220        "description": "unevaluatedItems with nested items and additionalItems",
221        "schema": {
222            "$schema": "https://json-schema.org/draft/2019-09/schema",
223            "allOf": [
224                {
225                    "items": [
226                        { "type": "string" }
227                    ],
228                    "additionalItems": true
229                }
230            ],
231            "unevaluatedItems": false
232        },
233        "tests": [
234            {
235                "description": "with no additional items",
236                "data": ["foo"],
237                "valid": true
238            },
239            {
240                "description": "with additional items",
241                "data": ["foo", 42, true],
242                "valid": true
243            }
244        ]
245    },
246    {
247        "description": "unevaluatedItems with nested unevaluatedItems",
248        "schema": {
249            "$schema": "https://json-schema.org/draft/2019-09/schema",
250            "allOf": [
251                {
252                    "items": [
253                        { "type": "string" }
254                    ]
255                },
256                { "unevaluatedItems": true }
257            ],
258            "unevaluatedItems": false
259        },
260        "tests": [
261            {
262                "description": "with no additional items",
263                "data": ["foo"],
264                "valid": true
265            },
266            {
267                "description": "with additional items",
268                "data": ["foo", 42, true],
269                "valid": true
270            }
271        ]
272    },
273    {
274        "description": "unevaluatedItems with anyOf",
275        "schema": {
276            "$schema": "https://json-schema.org/draft/2019-09/schema",
277            "items": [
278                { "const": "foo" }
279            ],
280            "anyOf": [
281                {
282                    "items": [
283                        true,
284                        { "const": "bar" }
285                    ]
286                },
287                {
288                    "items": [
289                        true,
290                        true,
291                        { "const": "baz" }
292                    ]
293                }
294            ],
295            "unevaluatedItems": false
296        },
297        "tests": [
298            {
299                "description": "when one schema matches and has no unevaluated items",
300                "data": ["foo", "bar"],
301                "valid": true
302            },
303            {
304                "description": "when one schema matches and has unevaluated items",
305                "data": ["foo", "bar", 42],
306                "valid": false
307            },
308            {
309                "description": "when two schemas match and has no unevaluated items",
310                "data": ["foo", "bar", "baz"],
311                "valid": true
312            },
313            {
314                "description": "when two schemas match and has unevaluated items",
315                "data": ["foo", "bar", "baz", 42],
316                "valid": false
317            }
318        ]
319    },
320    {
321        "description": "unevaluatedItems with oneOf",
322        "schema": {
323            "$schema": "https://json-schema.org/draft/2019-09/schema",
324            "items": [
325                { "const": "foo" }
326            ],
327            "oneOf": [
328                {
329                    "items": [
330                        true,
331                        { "const": "bar" }
332                    ]
333                },
334                {
335                    "items": [
336                        true,
337                        { "const": "baz" }
338                    ]
339                }
340            ],
341            "unevaluatedItems": false
342        },
343        "tests": [
344            {
345                "description": "with no unevaluated items",
346                "data": ["foo", "bar"],
347                "valid": true
348            },
349            {
350                "description": "with unevaluated items",
351                "data": ["foo", "bar", 42],
352                "valid": false
353            }
354        ]
355    },
356    {
357        "description": "unevaluatedItems with not",
358        "schema": {
359            "$schema": "https://json-schema.org/draft/2019-09/schema",
360            "items": [
361                { "const": "foo" }
362            ],
363            "not": {
364                "not": {
365                    "items": [
366                        true,
367                        { "const": "bar" }
368                    ]
369                }
370            },
371            "unevaluatedItems": false
372        },
373        "tests": [
374            {
375                "description": "with unevaluated items",
376                "data": ["foo", "bar"],
377                "valid": false
378            }
379        ]
380    },
381    {
382        "description": "unevaluatedItems with if/then/else",
383        "schema": {
384            "$schema": "https://json-schema.org/draft/2019-09/schema",
385            "items": [ { "const": "foo" } ],
386            "if": {
387                "items": [
388                    true,
389                    { "const": "bar" }
390                ]
391            },
392            "then": {
393                "items": [
394                    true,
395                    true,
396                    { "const": "then" }
397                ]
398            },
399            "else": {
400                "items": [
401                    true,
402                    true,
403                    true,
404                    { "const": "else" }
405                ]
406            },
407            "unevaluatedItems": false
408        },
409        "tests": [
410            {
411                "description": "when if matches and it has no unevaluated items",
412                "data": ["foo", "bar", "then"],
413                "valid": true
414            },
415            {
416                "description": "when if matches and it has unevaluated items",
417                "data": ["foo", "bar", "then", "else"],
418                "valid": false
419            },
420            {
421                "description": "when if doesn't match and it has no unevaluated items",
422                "data": ["foo", 42, 42, "else"],
423                "valid": true
424            },
425            {
426                "description": "when if doesn't match and it has unevaluated items",
427                "data": ["foo", 42, 42, "else", 42],
428                "valid": false
429            }
430        ]
431    },
432    {
433        "description": "unevaluatedItems with boolean schemas",
434        "schema": {
435            "$schema": "https://json-schema.org/draft/2019-09/schema",
436            "allOf": [true],
437            "unevaluatedItems": false
438        },
439        "tests": [
440            {
441                "description": "with no unevaluated items",
442                "data": [],
443                "valid": true
444            },
445            {
446                "description": "with unevaluated items",
447                "data": ["foo"],
448                "valid": false
449            }
450        ]
451    },
452    {
453        "description": "unevaluatedItems with $ref",
454        "schema": {
455            "$schema": "https://json-schema.org/draft/2019-09/schema",
456            "$ref": "#/$defs/bar",
457            "items": [
458                { "type": "string" }
459            ],
460            "unevaluatedItems": false,
461            "$defs": {
462              "bar": {
463                  "items": [
464                      true,
465                      { "type": "string" }
466                  ]
467              }
468            }
469        },
470        "tests": [
471            {
472                "description": "with no unevaluated items",
473                "data": ["foo", "bar"],
474                "valid": true
475            },
476            {
477                "description": "with unevaluated items",
478                "data": ["foo", "bar", "baz"],
479                "valid": false
480            }
481        ]
482    },
483    {
484        "description": "unevaluatedItems before $ref",
485        "schema": {
486            "$schema": "https://json-schema.org/draft/2019-09/schema",
487            "unevaluatedItems": false,
488            "items": [
489                { "type": "string" }
490            ],
491            "$ref": "#/$defs/bar",
492            "$defs": {
493              "bar": {
494                  "items": [
495                      true,
496                      { "type": "string" }
497                  ]
498              }
499            }
500        },
501        "tests": [
502            {
503                "description": "with no unevaluated items",
504                "data": ["foo", "bar"],
505                "valid": true
506            },
507            {
508                "description": "with unevaluated items",
509                "data": ["foo", "bar", "baz"],
510                "valid": false
511            }
512        ]
513    },
514    {
515        "description": "unevaluatedItems with $recursiveRef",
516        "schema": {
517            "$schema": "https://json-schema.org/draft/2019-09/schema",
518            "$id": "https://example.com/unevaluated-items-with-recursive-ref/extended-tree",
519
520            "$recursiveAnchor": true,
521
522            "$ref": "./tree",
523            "items": [
524                true,
525                true,
526                { "type": "string" }
527            ],
528
529            "$defs": {
530                "tree": {
531                    "$id": "./tree",
532                    "$recursiveAnchor": true,
533
534                    "type": "array",
535                    "items": [
536                        { "type": "number" },
537                        {
538                            "$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
539                            "unevaluatedItems": false,
540                            "$recursiveRef": "#"
541                        }
542                    ]
543                }
544            }
545        },
546        "tests": [
547            {
548                "description": "with no unevaluated items",
549                "data": [1, [2, [], "b"], "a"],
550                "valid": true
551            },
552            {
553                "description": "with unevaluated items",
554                "data": [1, [2, [], "b", "too many"], "a"],
555                "valid": false
556            }
557        ]
558    },
559    {
560        "description": "unevaluatedItems can't see inside cousins",
561        "schema": {
562            "$schema": "https://json-schema.org/draft/2019-09/schema",
563            "allOf": [
564                {
565                    "items": [ true ]
566                },
567                { "unevaluatedItems": false }
568            ]
569        },
570        "tests": [
571            {
572                "description": "always fails",
573                "data": [ 1 ],
574                "valid": false
575            }
576        ]
577    },
578    {
579        "description": "item is evaluated in an uncle schema to unevaluatedItems",
580        "schema": {
581            "$schema": "https://json-schema.org/draft/2019-09/schema",
582            "properties": {
583                "foo": {
584                    "items": [
585                        { "type": "string" }
586                    ],
587                    "unevaluatedItems": false
588                  }
589            },
590            "anyOf": [
591                {
592                    "properties": {
593                        "foo": {
594                            "items": [
595                                true,
596                                { "type": "string" }
597                            ]
598                        }
599                    }
600                }
601            ]
602        },
603        "tests": [
604            {
605                "description": "no extra items",
606                "data": {
607                    "foo": [
608                        "test"
609                    ]
610                },
611                "valid": true
612            },
613            {
614                "description": "uncle keyword evaluation is not significant",
615                "data": {
616                    "foo": [
617                        "test",
618                        "test"
619                    ]
620                },
621                "valid": false
622            }
623        ]
624    },
625    {
626        "description": "non-array instances are valid",
627        "schema": {
628            "$schema": "https://json-schema.org/draft/2019-09/schema",
629            "unevaluatedItems": false
630        },
631        "tests": [
632            {
633                "description": "ignores booleans",
634                "data": true,
635                "valid": true
636            },
637            {
638                "description": "ignores integers",
639                "data": 123,
640                "valid": true
641            },
642            {
643                "description": "ignores floats",
644                "data": 1.0,
645                "valid": true
646            },
647            {
648                "description": "ignores objects",
649                "data": {},
650                "valid": true
651            },
652            {
653                "description": "ignores strings",
654                "data": "foo",
655                "valid": true
656            },
657            {
658                "description": "ignores null",
659                "data": null,
660                "valid": true
661            }
662        ]
663    },
664    {
665        "description": "unevaluatedItems with null instance elements",
666        "schema": {
667            "$schema": "https://json-schema.org/draft/2019-09/schema",
668            "unevaluatedItems": {
669                "type": "null"
670            }
671        },
672        "tests": [
673            {
674                "description": "allows null elements",
675                "data": [ null ],
676                "valid": true
677            }
678        ]
679    },
680    {
681        "description": "unevaluatedItems can see annotations from if without then and else",
682        "schema": {
683            "$schema": "https://json-schema.org/draft/2019-09/schema",
684            "if": {
685                "items": [{"const": "a"}]
686            },
687            "unevaluatedItems": false
688        },
689        "tests": [
690            {
691                "description": "valid in case if is evaluated",
692                "data": [ "a" ],
693                "valid": true
694            },
695            {
696                "description": "invalid in case if is evaluated",
697                "data": [ "b" ],
698                "valid": false
699            }
700
701        ]
702    }
703]
704