xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft-next/contains.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "contains keyword validation",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/next/schema",
6            "contains": { "minimum": 5 }
7        },
8        "tests": [
9            {
10                "description": "array with item matching schema (5) is valid",
11                "data": [3, 4, 5],
12                "valid": true
13            },
14            {
15                "description": "array with item matching schema (6) is valid",
16                "data": [3, 4, 6],
17                "valid": true
18            },
19            {
20                "description": "array with two items matching schema (5, 6) is valid",
21                "data": [3, 4, 5, 6],
22                "valid": true
23            },
24            {
25                "description": "array without items matching schema is invalid",
26                "data": [2, 3, 4],
27                "valid": false
28            },
29            {
30                "description": "empty array is invalid",
31                "data": [],
32                "valid": false
33            },
34            {
35                "description": "not array or object is valid",
36                "data": 42,
37                "valid": true
38            }
39        ]
40    },
41    {
42        "description": "contains keyword with const keyword",
43        "schema": {
44            "$schema": "https://json-schema.org/draft/next/schema",
45            "contains": { "const": 5 }
46        },
47        "tests": [
48            {
49                "description": "array with item 5 is valid",
50                "data": [3, 4, 5],
51                "valid": true
52            },
53            {
54                "description": "array with two items 5 is valid",
55                "data": [3, 4, 5, 5],
56                "valid": true
57            },
58            {
59                "description": "array without item 5 is invalid",
60                "data": [1, 2, 3, 4],
61                "valid": false
62            }
63        ]
64    },
65    {
66        "description": "contains keyword with boolean schema true",
67        "schema": {
68            "$schema": "https://json-schema.org/draft/next/schema",
69            "contains": true
70        },
71        "tests": [
72            {
73                "description": "any non-empty array is valid",
74                "data": ["foo"],
75                "valid": true
76            },
77            {
78                "description": "empty array is invalid",
79                "data": [],
80                "valid": false
81            }
82        ]
83    },
84    {
85        "description": "contains keyword with boolean schema false",
86        "schema": {
87            "$schema": "https://json-schema.org/draft/next/schema",
88            "contains": false
89        },
90        "tests": [
91            {
92                "description": "any non-empty array is invalid",
93                "data": ["foo"],
94                "valid": false
95            },
96            {
97                "description": "empty array is invalid",
98                "data": [],
99                "valid": false
100            },
101            {
102                "description": "non-arrays are valid - string",
103                "data": "contains does not apply to strings",
104                "valid": true
105            },
106            {
107                "description": "non-arrays are valid - object",
108                "data": {},
109                "valid": true
110            },
111            {
112                "description": "non-arrays are valid - number",
113                "data": 42,
114                "valid": true
115            },
116            {
117                "description": "non-arrays are valid - boolean",
118                "data": false,
119                "valid": true
120            },
121            {
122                "description": "non-arrays are valid - null",
123                "data": null,
124                "valid": true
125            }
126        ]
127    },
128    {
129        "description": "items + contains",
130        "schema": {
131            "$schema": "https://json-schema.org/draft/next/schema",
132            "additionalProperties": { "multipleOf": 2 },
133            "items": { "multipleOf": 2 },
134            "contains": { "multipleOf": 3 }
135        },
136        "tests": [
137            {
138                "description": "matches items, does not match contains",
139                "data": [2, 4, 8],
140                "valid": false
141            },
142            {
143                "description": "does not match items, matches contains",
144                "data": [3, 6, 9],
145                "valid": false
146            },
147            {
148                "description": "matches both items and contains",
149                "data": [6, 12],
150                "valid": true
151            },
152            {
153                "description": "matches neither items nor contains",
154                "data": [1, 5],
155                "valid": false
156            }
157        ]
158    },
159    {
160        "description": "contains with false if subschema",
161        "schema": {
162            "$schema": "https://json-schema.org/draft/next/schema",
163            "contains": {
164                "if": false,
165                "else": true
166            }
167        },
168        "tests": [
169            {
170                "description": "any non-empty array is valid",
171                "data": ["foo"],
172                "valid": true
173            },
174            {
175                "description": "empty array is invalid",
176                "data": [],
177                "valid": false
178            }
179        ]
180    },
181    {
182        "description": "contains with null instance elements",
183        "schema": {
184            "$schema": "https://json-schema.org/draft/next/schema",
185            "contains": {
186                "type": "null"
187            }
188        },
189        "tests": [
190            {
191                "description": "allows null items",
192                "data": [ null ],
193                "valid": true
194            }
195        ]
196    }
197]
198