xref: /aosp_15_r20/external/json-schema-validator/src/test/resources/draft7/issue491.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2  {
3    "description": "issue491 Schema 1",
4    "schema": {
5      "$schema": "http://json-schema.org/draft-07/schema#",
6      "$id": "https://example.com/issue-470.json",
7      "title": "OneOf validation message",
8      "description": "Test description",
9      "type": "object",
10      "properties": {
11        "search": {
12          "type": "object",
13          "oneOf": [
14            {
15              "type": "object",
16              "properties": {
17                "searchAge": {
18                  "type": "object",
19                  "properties": {
20                    "age": {
21                      "type": "integer",
22                      "maximum": 150,
23                      "minimum": 1
24                    }
25                  },
26                  "required": [
27                    "age"
28                  ]
29                }
30              },
31              "required": [
32                "searchAge"
33              ]
34            },
35            {
36              "type": "object",
37              "properties": {
38                "name": {
39                  "type": "string",
40                  "maxLength": 20,
41                  "minLength": 1
42                }
43              },
44              "required": [
45                "name"
46              ]
47            }
48          ]
49        }
50      },
51      "additionalProperties": false
52    },
53    "tests": [
54      {
55        "description": "Test valid oneOf option 1",
56        "data": {
57          "search": {
58            "searchAge": {
59              "age": 50
60            }
61          }
62        },
63        "valid": true
64      },
65      {
66        "description": "Test valid oneOf option 2",
67        "data": {
68          "search": {
69            "name": "Steve"
70          }
71        },
72        "valid": true
73      },
74      {
75        "description": "Test invalid oneOf option 1 - wrong type",
76        "data": {
77          "search": {
78            "searchAge": {
79              "age": "Steve"
80            }
81          }
82        },
83        "valid": false,
84        "validationMessages": [
85          "$.search: required property 'name' not found",
86          "$.search.searchAge.age: string found, integer expected",
87          "$.search: must be valid to one and only one schema, but 0 are valid"
88        ]
89      },
90      {
91        "description": "Test invalid oneOf option 2 - wrong type",
92        "data": {
93          "search": {
94            "name": 123
95          }
96        },
97        "valid": false,
98        "validationMessages": [
99          "$.search.name: integer found, string expected",
100          "$.search: required property 'searchAge' not found",
101          "$.search: must be valid to one and only one schema, but 0 are valid"
102        ]
103      }
104    ]
105  },
106  {
107    "description": "issue491 Schema 2",
108    "schema": {
109      "$schema": "http://json-schema.org/draft-07/schema#",
110      "$id": "https://example.com/issue-470.json",
111      "title": "OneOf validation message",
112      "description": "Test description",
113      "type": "object",
114      "properties": {
115        "search": {
116          "type": "object",
117          "oneOf": [
118            {
119              "type": "object",
120              "properties": {
121                "byAge": {
122                  "type": "object",
123                  "properties": {
124                    "age": {
125                      "type": "integer",
126                      "maximum": 150,
127                      "minimum": 1
128                    }
129                  },
130                  "required": [
131                    "age"
132                  ]
133                }
134              },
135              "required": [
136                "byAge"
137              ]
138            },
139            {
140              "type": "object",
141              "properties": {
142                "name": {
143                  "type": "string",
144                  "maxLength": 20,
145                  "minLength": 1
146                }
147              },
148              "required": [
149                "name"
150              ]
151            }
152          ]
153        }
154      },
155      "additionalProperties": false
156    },
157    "tests": [
158      {
159        "description": "Test valid oneOf option 1",
160        "data": {
161          "search": {
162            "name": "Steve"
163          }
164        },
165        "valid": true
166      },
167      {
168        "description": "Test valid oneOf option 2",
169        "data": {
170          "search": {
171            "name": "Steve"
172          }
173        },
174        "valid": true
175      },
176      {
177        "description": "Test invalid oneOf option 1 - wrong type",
178        "data": {
179          "search": {
180            "byAge": {
181              "age": "Steve"
182            }
183          }
184        },
185        "valid": false,
186        "validationMessages": [
187          "$.search: required property 'name' not found",
188          "$.search.byAge.age: string found, integer expected",
189          "$.search: must be valid to one and only one schema, but 0 are valid"
190        ]
191      },
192      {
193        "description": "Test invalid oneOf option 2 - wrong type",
194        "data": {
195          "search": {
196            "name": 123
197          }
198        },
199        "valid": false,
200        "validationMessages": [
201          "$.search.name: integer found, string expected",
202          "$.search: required property 'byAge' not found",
203          "$.search: must be valid to one and only one schema, but 0 are valid"
204        ]
205      }
206    ]
207  },
208  {
209    "description": "issue491 Schema 3",
210    "schema": {
211      "$schema": "http://json-schema.org/draft-07/schema#",
212      "$id": "https://example.com/issue-470.json",
213      "title": "OneOf validation message",
214      "description": "Test description",
215      "type": "object",
216      "properties": {
217        "search": {
218          "type": "object",
219          "oneOf": [
220            {
221              "type": "object",
222              "properties": {
223                "age": {
224                  "type": "integer",
225                  "maximum": 150,
226                  "minimum": 1
227                }
228              },
229              "required": [
230                "age"
231              ]
232            },
233            {
234              "type": "object",
235              "properties": {
236                "name": {
237                  "type": "string",
238                  "maxLength": 20,
239                  "minLength": 1
240                }
241              },
242              "required": [
243                "name"
244              ]
245            }
246          ]
247        }
248      },
249      "additionalProperties": false
250    },
251    "tests": [
252      {
253        "description": "Test valid oneOf option 1",
254        "data": {
255          "search": {
256            "age": 50
257          }
258        },
259        "valid": true
260      },
261      {
262        "description": "Test valid oneOf option 2",
263        "data": {
264          "search": {
265            "name": "Steve"
266          }
267        },
268        "valid": true
269      },
270      {
271        "description": "Test invalid oneOf option - wrong types or values 1",
272        "data": {
273          "search": {
274            "age": "Steve"
275          }
276        },
277        "valid": false,
278        "validationMessages": [
279          "$.search: required property 'name' not found",
280          "$.search.age: string found, integer expected",
281          "$.search: must be valid to one and only one schema, but 0 are valid"
282        ]
283      },
284      {
285        "description": "Test invalid oneOf option - wrong types or values 2",
286        "data": {
287          "search": {
288            "name": 123
289          }
290        },
291        "valid": false,
292        "validationMessages": [
293          "$.search.name: integer found, string expected",
294          "$.search: required property 'age' not found",
295          "$.search: must be valid to one and only one schema, but 0 are valid"
296        ]
297      },
298      {
299        "description": "Test invalid oneOf option - wrong types or values 3",
300        "data": {
301          "search": {
302            "age": 200
303          }
304        },
305        "valid": false,
306        "validationMessages": [
307          "$.search: required property 'name' not found",
308          "$.search.age: must have a maximum value of 150",
309          "$.search: must be valid to one and only one schema, but 0 are valid"
310        ]
311      },
312      {
313        "description": "Test invalid oneOf option - wrong types or values 4",
314        "data": {
315          "search": {
316            "name": "TooLoooooooooooooooooooooooooooooooooongName"
317          }
318        },
319        "valid": false,
320        "validationMessages": [
321          "$.search.name: must be at most 20 characters long",
322          "$.search: required property 'age' not found",
323          "$.search: must be valid to one and only one schema, but 0 are valid"
324        ]
325      }
326    ]
327  }
328]