xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft2020-12/properties.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "object properties validation",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/2020-12/schema",
6            "properties": {
7                "foo": {"type": "integer"},
8                "bar": {"type": "string"}
9            }
10        },
11        "tests": [
12            {
13                "description": "both properties present and valid is valid",
14                "data": {"foo": 1, "bar": "baz"},
15                "valid": true
16            },
17            {
18                "description": "one property invalid is invalid",
19                "data": {"foo": 1, "bar": {}},
20                "valid": false
21            },
22            {
23                "description": "both properties invalid is invalid",
24                "data": {"foo": [], "bar": {}},
25                "valid": false
26            },
27            {
28                "description": "doesn't invalidate other properties",
29                "data": {"quux": []},
30                "valid": true
31            },
32            {
33                "description": "ignores arrays",
34                "data": [],
35                "valid": true
36            },
37            {
38                "description": "ignores other non-objects",
39                "data": 12,
40                "valid": true
41            }
42        ]
43    },
44    {
45        "description":
46            "properties, patternProperties, additionalProperties interaction",
47        "schema": {
48            "$schema": "https://json-schema.org/draft/2020-12/schema",
49            "properties": {
50                "foo": {"type": "array", "maxItems": 3},
51                "bar": {"type": "array"}
52            },
53            "patternProperties": {"f.o": {"minItems": 2}},
54            "additionalProperties": {"type": "integer"}
55        },
56        "tests": [
57            {
58                "description": "property validates property",
59                "data": {"foo": [1, 2]},
60                "valid": true
61            },
62            {
63                "description": "property invalidates property",
64                "data": {"foo": [1, 2, 3, 4]},
65                "valid": false
66            },
67            {
68                "description": "patternProperty invalidates property",
69                "data": {"foo": []},
70                "valid": false
71            },
72            {
73                "description": "patternProperty validates nonproperty",
74                "data": {"fxo": [1, 2]},
75                "valid": true
76            },
77            {
78                "description": "patternProperty invalidates nonproperty",
79                "data": {"fxo": []},
80                "valid": false
81            },
82            {
83                "description": "additionalProperty ignores property",
84                "data": {"bar": []},
85                "valid": true
86            },
87            {
88                "description": "additionalProperty validates others",
89                "data": {"quux": 3},
90                "valid": true
91            },
92            {
93                "description": "additionalProperty invalidates others",
94                "data": {"quux": "foo"},
95                "valid": false
96            }
97        ]
98    },
99    {
100        "description": "properties with boolean schema",
101        "schema": {
102            "$schema": "https://json-schema.org/draft/2020-12/schema",
103            "properties": {
104                "foo": true,
105                "bar": false
106            }
107        },
108        "tests": [
109            {
110                "description": "no property present is valid",
111                "data": {},
112                "valid": true
113            },
114            {
115                "description": "only 'true' property present is valid",
116                "data": {"foo": 1},
117                "valid": true
118            },
119            {
120                "description": "only 'false' property present is invalid",
121                "data": {"bar": 2},
122                "valid": false
123            },
124            {
125                "description": "both properties present is invalid",
126                "data": {"foo": 1, "bar": 2},
127                "valid": false
128            }
129        ]
130    },
131    {
132        "description": "properties with escaped characters",
133        "schema": {
134            "$schema": "https://json-schema.org/draft/2020-12/schema",
135            "properties": {
136                "foo\nbar": {"type": "number"},
137                "foo\"bar": {"type": "number"},
138                "foo\\bar": {"type": "number"},
139                "foo\rbar": {"type": "number"},
140                "foo\tbar": {"type": "number"},
141                "foo\fbar": {"type": "number"}
142            }
143        },
144        "tests": [
145            {
146                "description": "object with all numbers is valid",
147                "data": {
148                    "foo\nbar": 1,
149                    "foo\"bar": 1,
150                    "foo\\bar": 1,
151                    "foo\rbar": 1,
152                    "foo\tbar": 1,
153                    "foo\fbar": 1
154                },
155                "valid": true
156            },
157            {
158                "description": "object with strings is invalid",
159                "data": {
160                    "foo\nbar": "1",
161                    "foo\"bar": "1",
162                    "foo\\bar": "1",
163                    "foo\rbar": "1",
164                    "foo\tbar": "1",
165                    "foo\fbar": "1"
166                },
167                "valid": false
168            }
169        ]
170    },
171    {
172        "description": "properties with null valued instance properties",
173        "schema": {
174            "$schema": "https://json-schema.org/draft/2020-12/schema",
175            "properties": {
176                "foo": {"type": "null"}
177            }
178        },
179        "tests": [
180            {
181                "description": "allows null values",
182                "data": {"foo": null},
183                "valid": true
184            }
185        ]
186    },
187    {
188        "description": "properties whose names are Javascript object property names",
189        "comment": "Ensure JS implementations don't universally consider e.g. __proto__ to always be present in an object.",
190        "schema": {
191            "$schema": "https://json-schema.org/draft/2020-12/schema",
192            "properties": {
193                "__proto__": {"type": "number"},
194                "toString": {
195                    "properties": { "length": { "type": "string" } }
196                },
197                "constructor": {"type": "number"}
198            }
199        },
200        "tests": [
201            {
202                "description": "ignores arrays",
203                "data": [],
204                "valid": true
205            },
206            {
207                "description": "ignores other non-objects",
208                "data": 12,
209                "valid": true
210            },
211            {
212                "description": "none of the properties mentioned",
213                "data": {},
214                "valid": true
215            },
216            {
217                "description": "__proto__ not valid",
218                "data": { "__proto__": "foo" },
219                "valid": false
220            },
221            {
222                "description": "toString not valid",
223                "data": { "toString": { "length": 37 } },
224                "valid": false
225            },
226            {
227                "description": "constructor not valid",
228                "data": { "constructor": { "length": 37 } },
229                "valid": false
230            },
231            {
232                "description": "all present and valid",
233                "data": {
234                    "__proto__": 12,
235                    "toString": { "length": "foo" },
236                    "constructor": 37
237                },
238                "valid": true
239            }
240        ]
241    }
242]
243