xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft7/if-then-else.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "ignore if without then or else",
4        "schema": {
5            "if": {
6                "const": 0
7            }
8        },
9        "tests": [
10            {
11                "description": "valid when valid against lone if",
12                "data": 0,
13                "valid": true
14            },
15            {
16                "description": "valid when invalid against lone if",
17                "data": "hello",
18                "valid": true
19            }
20        ]
21    },
22    {
23        "description": "ignore then without if",
24        "schema": {
25            "then": {
26                "const": 0
27            }
28        },
29        "tests": [
30            {
31                "description": "valid when valid against lone then",
32                "data": 0,
33                "valid": true
34            },
35            {
36                "description": "valid when invalid against lone then",
37                "data": "hello",
38                "valid": true
39            }
40        ]
41    },
42    {
43        "description": "ignore else without if",
44        "schema": {
45            "else": {
46                "const": 0
47            }
48        },
49        "tests": [
50            {
51                "description": "valid when valid against lone else",
52                "data": 0,
53                "valid": true
54            },
55            {
56                "description": "valid when invalid against lone else",
57                "data": "hello",
58                "valid": true
59            }
60        ]
61    },
62    {
63        "description": "if and then without else",
64        "schema": {
65            "if": {
66                "exclusiveMaximum": 0
67            },
68            "then": {
69                "minimum": -10
70            }
71        },
72        "tests": [
73            {
74                "description": "valid through then",
75                "data": -1,
76                "valid": true
77            },
78            {
79                "description": "invalid through then",
80                "data": -100,
81                "valid": false
82            },
83            {
84                "description": "valid when if test fails",
85                "data": 3,
86                "valid": true
87            }
88        ]
89    },
90    {
91        "description": "if and else without then",
92        "schema": {
93            "if": {
94                "exclusiveMaximum": 0
95            },
96            "else": {
97                "multipleOf": 2
98            }
99        },
100        "tests": [
101            {
102                "description": "valid when if test passes",
103                "data": -1,
104                "valid": true
105            },
106            {
107                "description": "valid through else",
108                "data": 4,
109                "valid": true
110            },
111            {
112                "description": "invalid through else",
113                "data": 3,
114                "valid": false
115            }
116        ]
117    },
118    {
119        "description": "validate against correct branch, then vs else",
120        "schema": {
121            "if": {
122                "exclusiveMaximum": 0
123            },
124            "then": {
125                "minimum": -10
126            },
127            "else": {
128                "multipleOf": 2
129            }
130        },
131        "tests": [
132            {
133                "description": "valid through then",
134                "data": -1,
135                "valid": true
136            },
137            {
138                "description": "invalid through then",
139                "data": -100,
140                "valid": false
141            },
142            {
143                "description": "valid through else",
144                "data": 4,
145                "valid": true
146            },
147            {
148                "description": "invalid through else",
149                "data": 3,
150                "valid": false
151            }
152        ]
153    },
154    {
155        "description": "non-interference across combined schemas",
156        "schema": {
157            "allOf": [
158                {
159                    "if": {
160                        "exclusiveMaximum": 0
161                    }
162                },
163                {
164                    "then": {
165                        "minimum": -10
166                    }
167                },
168                {
169                    "else": {
170                        "multipleOf": 2
171                    }
172                }
173            ]
174        },
175        "tests": [
176            {
177                "description": "valid, but would have been invalid through then",
178                "data": -100,
179                "valid": true
180            },
181            {
182                "description": "valid, but would have been invalid through else",
183                "data": 3,
184                "valid": true
185            }
186        ]
187    },
188    {
189        "description": "if with boolean schema true",
190        "schema": {
191            "if": true,
192            "then": { "const": "then" },
193            "else": { "const": "else" }
194        },
195        "tests": [
196            {
197                "description": "boolean schema true in if always chooses the then path (valid)",
198                "data": "then",
199                "valid": true
200            },
201            {
202                "description": "boolean schema true in if always chooses the then path (invalid)",
203                "data": "else",
204                "valid": false
205            }
206        ]
207    },
208    {
209        "description": "if with boolean schema false",
210        "schema": {
211            "if": false,
212            "then": { "const": "then" },
213            "else": { "const": "else" }
214        },
215        "tests": [
216            {
217                "description": "boolean schema false in if always chooses the else path (invalid)",
218                "data": "then",
219                "valid": false
220            },
221            {
222                "description": "boolean schema false in if always chooses the else path (valid)",
223                "data": "else",
224                "valid": true
225            }
226        ]
227    },
228    {
229        "description": "if appears at the end when serialized (keyword processing sequence)",
230        "schema": {
231            "then": { "const": "yes" },
232            "else": { "const": "other" },
233            "if": { "maxLength": 4 }
234        },
235        "tests": [
236            {
237                "description": "yes redirects to then and passes",
238                "data": "yes",
239                "valid": true
240            },
241            {
242                "description": "other redirects to else and passes",
243                "data": "other",
244                "valid": true
245            },
246            {
247                "description": "no redirects to then and fails",
248                "data": "no",
249                "valid": false
250            },
251            {
252                "description": "invalid redirects to else and fails",
253                "data": "invalid",
254                "valid": false
255            }
256        ]
257    }
258]
259