xref: /aosp_15_r20/external/json-schema-validator/src/test/suite/tests/draft2019-09/dependentSchemas.json (revision 78c4dd6aa35290980cdcd1623a7e337e8d021c7c)
1[
2    {
3        "description": "single dependency",
4        "schema": {
5            "$schema": "https://json-schema.org/draft/2019-09/schema",
6            "dependentSchemas": {
7                "bar": {
8                    "properties": {
9                        "foo": {"type": "integer"},
10                        "bar": {"type": "integer"}
11                    }
12                }
13            }
14        },
15        "tests": [
16            {
17                "description": "valid",
18                "data": {"foo": 1, "bar": 2},
19                "valid": true
20            },
21            {
22                "description": "no dependency",
23                "data": {"foo": "quux"},
24                "valid": true
25            },
26            {
27                "description": "wrong type",
28                "data": {"foo": "quux", "bar": 2},
29                "valid": false
30            },
31            {
32                "description": "wrong type other",
33                "data": {"foo": 2, "bar": "quux"},
34                "valid": false
35            },
36            {
37                "description": "wrong type both",
38                "data": {"foo": "quux", "bar": "quux"},
39                "valid": false
40            },
41            {
42                "description": "ignores arrays",
43                "data": ["bar"],
44                "valid": true
45            },
46            {
47                "description": "ignores strings",
48                "data": "foobar",
49                "valid": true
50            },
51            {
52                "description": "ignores other non-objects",
53                "data": 12,
54                "valid": true
55            }
56        ]
57    },
58    {
59        "description": "boolean subschemas",
60        "schema": {
61            "$schema": "https://json-schema.org/draft/2019-09/schema",
62            "dependentSchemas": {
63                "foo": true,
64                "bar": false
65            }
66        },
67        "tests": [
68            {
69                "description": "object with property having schema true is valid",
70                "data": {"foo": 1},
71                "valid": true
72            },
73            {
74                "description": "object with property having schema false is invalid",
75                "data": {"bar": 2},
76                "valid": false
77            },
78            {
79                "description": "object with both properties is invalid",
80                "data": {"foo": 1, "bar": 2},
81                "valid": false
82            },
83            {
84                "description": "empty object is valid",
85                "data": {},
86                "valid": true
87            }
88        ]
89    },
90    {
91        "description": "dependencies with escaped characters",
92        "schema": {
93            "$schema": "https://json-schema.org/draft/2019-09/schema",
94            "dependentSchemas": {
95                "foo\tbar": {"minProperties": 4},
96                "foo'bar": {"required": ["foo\"bar"]}
97            }
98        },
99        "tests": [
100            {
101                "description": "quoted tab",
102                "data": {
103                    "foo\tbar": 1,
104                    "a": 2,
105                    "b": 3,
106                    "c": 4
107                },
108                "valid": true
109            },
110            {
111                "description": "quoted quote",
112                "data": {
113                    "foo'bar": {"foo\"bar": 1}
114                },
115                "valid": false
116            },
117            {
118                "description": "quoted tab invalid under dependent schema",
119                "data": {
120                    "foo\tbar": 1,
121                    "a": 2
122                },
123                "valid": false
124            },
125            {
126                "description": "quoted quote invalid under dependent schema",
127                "data": {"foo'bar": 1},
128                "valid": false
129            }
130        ]
131    },
132    {
133        "description": "dependent subschema incompatible with root",
134        "schema": {
135            "$schema": "https://json-schema.org/draft/2019-09/schema",
136            "properties": {
137                "foo": {}
138            },
139            "dependentSchemas": {
140                "foo": {
141                    "properties": {
142                        "bar": {}
143                    },
144                    "additionalProperties": false
145                }
146            }
147        },
148        "tests": [
149            {
150                "description": "matches root",
151                "data": {"foo": 1},
152                "valid": false
153            },
154            {
155                "description": "matches dependency",
156                "data": {"bar": 1},
157                "valid": true
158            },
159            {
160                "description": "matches both",
161                "data": {"foo": 1, "bar": 2},
162                "valid": false
163            },
164            {
165                "description": "no dependency",
166                "data": {"baz": 1},
167                "valid": true
168            }
169        ]
170    }
171]
172