1[
2    {
3        "description": "root pointer ref",
4        "schema": {
5            "properties": {
6                "foo": {"$ref": "#"}
7            },
8            "additionalProperties": false
9        },
10        "tests": [
11            {
12                "description": "match",
13                "data": {"foo": false},
14                "valid": true
15            },
16            {
17                "description": "recursive match",
18                "data": {"foo": {"foo": false}},
19                "valid": true
20            },
21            {
22                "description": "mismatch",
23                "data": {"bar": false},
24                "valid": false
25            },
26            {
27                "description": "recursive mismatch",
28                "data": {"foo": {"bar": false}},
29                "valid": false
30            }
31        ]
32    },
33    {
34        "description": "relative pointer ref to object",
35        "schema": {
36            "properties": {
37                "foo": {"type": "integer"},
38                "bar": {"$ref": "#/properties/foo"}
39            }
40        },
41        "tests": [
42            {
43                "description": "match",
44                "data": {"bar": 3},
45                "valid": true
46            },
47            {
48                "description": "mismatch",
49                "data": {"bar": true},
50                "valid": false
51            }
52        ]
53    },
54    {
55        "description": "relative pointer ref to array",
56        "schema": {
57            "items": [
58                {"type": "integer"},
59                {"$ref": "#/items/0"}
60            ]
61        },
62        "tests": [
63            {
64                "description": "match array",
65                "data": [1, 2],
66                "valid": true
67            },
68            {
69                "description": "mismatch array",
70                "data": [1, "foo"],
71                "valid": false
72            }
73        ]
74    },
75    {
76        "description": "escaped pointer ref",
77        "schema": {
78            "tilda~field": {"type": "integer"},
79            "slash/field": {"type": "integer"},
80            "percent%field": {"type": "integer"},
81            "properties": {
82                "tilda": {"$ref": "#/tilda~0field"},
83                "slash": {"$ref": "#/slash~1field"},
84                "percent": {"$ref": "#/percent%25field"}
85            }
86        },
87        "tests": [
88            {
89                "description": "slash invalid",
90                "data": {"slash": "aoeu"},
91                "valid": false
92            },
93            {
94                "description": "tilda invalid",
95                "data": {"tilda": "aoeu"},
96                "valid": false
97            },
98            {
99                "description": "percent invalid",
100                "data": {"percent": "aoeu"},
101                "valid": false
102            },
103            {
104                "description": "slash valid",
105                "data": {"slash": 123},
106                "valid": true
107            },
108            {
109                "description": "tilda valid",
110                "data": {"tilda": 123},
111                "valid": true
112            },
113            {
114                "description": "percent valid",
115                "data": {"percent": 123},
116                "valid": true
117            }
118        ]
119    },
120    {
121        "description": "nested refs",
122        "schema": {
123            "$defs": {
124                "a": {"type": "integer"},
125                "b": {"$ref": "#/$defs/a"},
126                "c": {"$ref": "#/$defs/b"}
127            },
128            "$ref": "#/$defs/c"
129        },
130        "tests": [
131            {
132                "description": "nested ref valid",
133                "data": 5,
134                "valid": true
135            },
136            {
137                "description": "nested ref invalid",
138                "data": "a",
139                "valid": false
140            }
141        ]
142    },
143    {
144        "description": "ref overrides any sibling keywords",
145        "schema": {
146            "$defs": {
147                "reffed": {
148                    "type": "array"
149                }
150            },
151            "properties": {
152                "foo": {
153                    "$ref": "#/$defs/reffed",
154                    "maxItems": 2
155                }
156            }
157        },
158        "tests": [
159            {
160                "description": "ref valid",
161                "data": { "foo": [] },
162                "valid": true
163            },
164            {
165                "description": "ref valid, maxItems ignored",
166                "data": { "foo": [ 1, 2, 3] },
167                "valid": true
168            },
169            {
170                "description": "ref invalid",
171                "data": { "foo": "string" },
172                "valid": false
173            }
174        ]
175    },
176    {
177        "description": "remote ref, containing refs itself",
178        "schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
179        "tests": [
180            {
181                "description": "remote ref valid",
182                "data": {"minLength": 1},
183                "valid": true
184            },
185            {
186                "description": "remote ref invalid",
187                "data": {"minLength": -1},
188                "valid": false
189            }
190        ]
191    },
192    {
193        "description": "property named $ref that is not a reference",
194        "schema": {
195            "properties": {
196                "$ref": {"type": "string"}
197            }
198        },
199        "tests": [
200            {
201                "description": "property named $ref valid",
202                "data": {"$ref": "a"},
203                "valid": true
204            },
205            {
206                "description": "property named $ref invalid",
207                "data": {"$ref": 2},
208                "valid": false
209            }
210        ]
211    },
212    {
213        "description": "$ref to boolean schema true",
214        "schema": {
215            "$ref": "#/$defs/bool",
216            "$defs": {
217                "bool": true
218            }
219        },
220        "tests": [
221            {
222                "description": "any value is valid",
223                "data": "foo",
224                "valid": true
225            }
226        ]
227    },
228    {
229        "description": "$ref to boolean schema false",
230        "schema": {
231            "$ref": "#/$defs/bool",
232            "$defs": {
233                "bool": false
234            }
235        },
236        "tests": [
237            {
238                "description": "any value is invalid",
239                "data": "foo",
240                "valid": false
241            }
242        ]
243    },
244    {
245        "description": "Recursive references between schemas",
246        "schema": {
247            "$id": "http://localhost:1234/tree",
248            "description": "tree of nodes",
249            "type": "object",
250            "properties": {
251                "meta": {"type": "string"},
252                "nodes": {
253                    "type": "array",
254                    "items": {"$ref": "node"}
255                }
256            },
257            "required": ["meta", "nodes"],
258            "$defs": {
259                "node": {
260                    "$id": "http://localhost:1234/node",
261                    "description": "node",
262                    "type": "object",
263                    "properties": {
264                        "value": {"type": "number"},
265                        "subtree": {"$ref": "tree"}
266                    },
267                    "required": ["value"]
268                }
269            }
270        },
271        "tests": [
272            {
273                "description": "valid tree",
274                "data": {
275                    "meta": "root",
276                    "nodes": [
277                        {
278                            "value": 1,
279                            "subtree": {
280                                "meta": "child",
281                                "nodes": [
282                                    {"value": 1.1},
283                                    {"value": 1.2}
284                                ]
285                            }
286                        },
287                        {
288                            "value": 2,
289                            "subtree": {
290                                "meta": "child",
291                                "nodes": [
292                                    {"value": 2.1},
293                                    {"value": 2.2}
294                                ]
295                            }
296                        }
297                    ]
298                },
299                "valid": true
300            },
301            {
302                "description": "invalid tree",
303                "data": {
304                    "meta": "root",
305                    "nodes": [
306                        {
307                            "value": 1,
308                            "subtree": {
309                                "meta": "child",
310                                "nodes": [
311                                    {"value": "string is invalid"},
312                                    {"value": 1.2}
313                                ]
314                            }
315                        },
316                        {
317                            "value": 2,
318                            "subtree": {
319                                "meta": "child",
320                                "nodes": [
321                                    {"value": 2.1},
322                                    {"value": 2.2}
323                                ]
324                            }
325                        }
326                    ]
327                },
328                "valid": false
329            }
330        ]
331    },
332    {
333        "description": "refs with quote",
334        "schema": {
335            "properties": {
336                "foo\"bar": {"$ref": "#/$defs/foo%22bar"}
337            },
338            "$defs": {
339                "foo\"bar": {"type": "number"}
340            }
341        },
342        "tests": [
343            {
344                "description": "object with numbers is valid",
345                "data": {
346                    "foo\"bar": 1
347                },
348                "valid": true
349            },
350            {
351                "description": "object with strings is invalid",
352                "data": {
353                    "foo\"bar": "1"
354                },
355                "valid": false
356            }
357        ]
358    }
359]
360