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