xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft2020-12/anyOf.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "anyOf",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/2020-12/schema",
6            "anyOf": [
7                {
8                    "type": "integer"
9                },
10                {
11                    "minimum": 2
12                }
13            ]
14        },
15        "tests": [
16            {
17                "description": "first anyOf valid",
18                "data": 1,
19                "valid": true
20            },
21            {
22                "description": "second anyOf valid",
23                "data": 2.5,
24                "valid": true
25            },
26            {
27                "description": "both anyOf valid",
28                "data": 3,
29                "valid": true
30            },
31            {
32                "description": "neither anyOf valid",
33                "data": 1.5,
34                "valid": false
35            }
36        ]
37    },
38    {
39        "description": "anyOf with base schema",
40        "schema": {
41            "$schema": "https://json-schema.org/draft/2020-12/schema",
42            "type": "string",
43            "anyOf" : [
44                {
45                    "maxLength": 2
46                },
47                {
48                    "minLength": 4
49                }
50            ]
51        },
52        "tests": [
53            {
54                "description": "mismatch base schema",
55                "data": 3,
56                "valid": false
57            },
58            {
59                "description": "one anyOf valid",
60                "data": "foobar",
61                "valid": true
62            },
63            {
64                "description": "both anyOf invalid",
65                "data": "foo",
66                "valid": false
67            }
68        ]
69    },
70    {
71        "description": "anyOf with boolean schemas, all true",
72        "schema": {
73            "$schema": "https://json-schema.org/draft/2020-12/schema",
74            "anyOf": [true, true]
75        },
76        "tests": [
77            {
78                "description": "any value is valid",
79                "data": "foo",
80                "valid": true
81            }
82        ]
83    },
84    {
85        "description": "anyOf with boolean schemas, some true",
86        "schema": {
87            "$schema": "https://json-schema.org/draft/2020-12/schema",
88            "anyOf": [true, false]
89        },
90        "tests": [
91            {
92                "description": "any value is valid",
93                "data": "foo",
94                "valid": true
95            }
96        ]
97    },
98    {
99        "description": "anyOf with boolean schemas, all false",
100        "schema": {
101            "$schema": "https://json-schema.org/draft/2020-12/schema",
102            "anyOf": [false, false]
103        },
104        "tests": [
105            {
106                "description": "any value is invalid",
107                "data": "foo",
108                "valid": false
109            }
110        ]
111    },
112    {
113        "description": "anyOf complex types",
114        "schema": {
115            "$schema": "https://json-schema.org/draft/2020-12/schema",
116            "anyOf": [
117                {
118                    "properties": {
119                        "bar": {"type": "integer"}
120                    },
121                    "required": ["bar"]
122                },
123                {
124                    "properties": {
125                        "foo": {"type": "string"}
126                    },
127                    "required": ["foo"]
128                }
129            ]
130        },
131        "tests": [
132            {
133                "description": "first anyOf valid (complex)",
134                "data": {"bar": 2},
135                "valid": true
136            },
137            {
138                "description": "second anyOf valid (complex)",
139                "data": {"foo": "baz"},
140                "valid": true
141            },
142            {
143                "description": "both anyOf valid (complex)",
144                "data": {"foo": "baz", "bar": 2},
145                "valid": true
146            },
147            {
148                "description": "neither anyOf valid (complex)",
149                "data": {"foo": 2, "bar": "quux"},
150                "valid": false
151            }
152        ]
153    },
154    {
155        "description": "anyOf with one empty schema",
156        "schema": {
157            "$schema": "https://json-schema.org/draft/2020-12/schema",
158            "anyOf": [
159                { "type": "number" },
160                {}
161            ]
162        },
163        "tests": [
164            {
165                "description": "string is valid",
166                "data": "foo",
167                "valid": true
168            },
169            {
170                "description": "number is valid",
171                "data": 123,
172                "valid": true
173            }
174        ]
175    },
176    {
177        "description": "nested anyOf, to check validation semantics",
178        "schema": {
179            "$schema": "https://json-schema.org/draft/2020-12/schema",
180            "anyOf": [
181                {
182                    "anyOf": [
183                        {
184                            "type": "null"
185                        }
186                    ]
187                }
188            ]
189        },
190        "tests": [
191            {
192                "description": "null is valid",
193                "data": null,
194                "valid": true
195            },
196            {
197                "description": "anything non-null is invalid",
198                "data": 123,
199                "valid": false
200            }
201        ]
202    }
203]
204