Skip to content

Commit ebb359d

Browse files
karenetheridgeJulian
authored andcommitted
squash: add $recursiveRef tests from #391
1 parent 90bd7fb commit ebb359d

File tree

3 files changed

+396
-1
lines changed

3 files changed

+396
-1
lines changed

tests/draft4/future-keywords.json

+132
Original file line numberDiff line numberDiff line change
@@ -342,5 +342,137 @@
342342
"valid": true
343343
}
344344
]
345+
},
346+
{
347+
"description": "$recursiveRef without $recursiveAnchor works like $ref",
348+
"schema": {
349+
"properties": {
350+
"foo": { "$recursiveRef": "#" }
351+
},
352+
"additionalProperties": false
353+
},
354+
"tests": [
355+
{
356+
"description": "match",
357+
"data": {"foo": false},
358+
"valid": true
359+
},
360+
{
361+
"description": "recursive match",
362+
"data": { "foo": { "foo": false } },
363+
"valid": true
364+
},
365+
{
366+
"description": "mismatch",
367+
"data": { "bar": false },
368+
"valid": false
369+
},
370+
{
371+
"description": "recursive mismatch",
372+
"data": { "foo": { "bar": false } },
373+
"valid": true
374+
}
375+
]
376+
},
377+
{
378+
"description": "$recursiveRef without using nesting",
379+
"schema": {
380+
"$id": "http://localhost:4242",
381+
"$defs": {
382+
"myobject": {
383+
"$id": "myobject.json",
384+
"$recursiveAnchor": true,
385+
"anyOf": [
386+
{ "type": "string" },
387+
{
388+
"type": "object",
389+
"additionalProperties": { "$recursiveRef": "#" }
390+
}
391+
]
392+
}
393+
},
394+
"anyOf": [
395+
{ "type": "integer" },
396+
{ "$ref": "#/$defs/myobject" }
397+
]
398+
},
399+
"tests": [
400+
{
401+
"description": "integer matches at the outer level",
402+
"data": 1,
403+
"valid": true
404+
},
405+
{
406+
"description": "single level match",
407+
"data": { "foo": "hi" },
408+
"valid": true
409+
},
410+
{
411+
"description": "integer does not match as a property value",
412+
"data": { "foo": 1 },
413+
"valid": true
414+
},
415+
{
416+
"description": "two levels, properties match with inner definition",
417+
"data": { "foo": { "bar": "hi" } },
418+
"valid": true
419+
},
420+
{
421+
"description": "two levels, no match",
422+
"data": { "foo": { "bar": 1 } },
423+
"valid": true
424+
}
425+
]
426+
},
427+
{
428+
"description": "$recursiveRef with nesting",
429+
"schema": {
430+
"$id": "http://localhost:4242",
431+
"$recursiveAnchor": true,
432+
"$defs": {
433+
"myobject": {
434+
"$id": "myobject.json",
435+
"$recursiveAnchor": true,
436+
"anyOf": [
437+
{ "type": "string" },
438+
{
439+
"type": "object",
440+
"additionalProperties": { "$recursiveRef": "#" }
441+
}
442+
]
443+
}
444+
},
445+
"anyOf": [
446+
{ "type": "integer" },
447+
{ "$ref": "#/$defs/myobject" }
448+
]
449+
},
450+
"tests": [
451+
{
452+
"description": "integer matches at the outer level",
453+
"data": 1,
454+
"valid": true
455+
},
456+
{
457+
"description": "single level match",
458+
"data": { "foo": "hi" },
459+
"valid": true
460+
},
461+
{
462+
"description": "integer now matches as a property value",
463+
"data": { "foo": 1 },
464+
"valid": true
465+
},
466+
{
467+
"description": "two levels, properties match with inner definition",
468+
"data": { "foo": { "bar": "hi" } },
469+
"valid": true
470+
},
471+
{
472+
"description": "two levels, properties match with $recursiveRef",
473+
"data": { "foo": { "bar": 1 } },
474+
"valid": true
475+
}
476+
]
345477
}
346478
]

tests/draft6/future-keywords.json

+132-1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,137 @@
305305
"valid": true
306306
}
307307
]
308+
},
309+
{
310+
"description": "$recursiveRef without $recursiveAnchor works like $ref",
311+
"schema": {
312+
"properties": {
313+
"foo": { "$recursiveRef": "#" }
314+
},
315+
"additionalProperties": false
316+
},
317+
"tests": [
318+
{
319+
"description": "match",
320+
"data": {"foo": false},
321+
"valid": true
322+
},
323+
{
324+
"description": "recursive match",
325+
"data": { "foo": { "foo": false } },
326+
"valid": true
327+
},
328+
{
329+
"description": "mismatch",
330+
"data": { "bar": false },
331+
"valid": false
332+
},
333+
{
334+
"description": "recursive mismatch",
335+
"data": { "foo": { "bar": false } },
336+
"valid": true
337+
}
338+
]
339+
},
340+
{
341+
"description": "$recursiveRef without using nesting",
342+
"schema": {
343+
"$id": "http://localhost:4242",
344+
"$defs": {
345+
"myobject": {
346+
"$id": "myobject.json",
347+
"$recursiveAnchor": true,
348+
"anyOf": [
349+
{ "type": "string" },
350+
{
351+
"type": "object",
352+
"additionalProperties": { "$recursiveRef": "#" }
353+
}
354+
]
355+
}
356+
},
357+
"anyOf": [
358+
{ "type": "integer" },
359+
{ "$ref": "#/$defs/myobject" }
360+
]
361+
},
362+
"tests": [
363+
{
364+
"description": "integer matches at the outer level",
365+
"data": 1,
366+
"valid": true
367+
},
368+
{
369+
"description": "single level match",
370+
"data": { "foo": "hi" },
371+
"valid": true
372+
},
373+
{
374+
"description": "integer does not match as a property value",
375+
"data": { "foo": 1 },
376+
"valid": true
377+
},
378+
{
379+
"description": "two levels, properties match with inner definition",
380+
"data": { "foo": { "bar": "hi" } },
381+
"valid": true
382+
},
383+
{
384+
"description": "two levels, no match",
385+
"data": { "foo": { "bar": 1 } },
386+
"valid": true
387+
}
388+
]
389+
},
390+
{
391+
"description": "$recursiveRef with nesting",
392+
"schema": {
393+
"$id": "http://localhost:4242",
394+
"$recursiveAnchor": true,
395+
"$defs": {
396+
"myobject": {
397+
"$id": "myobject.json",
398+
"$recursiveAnchor": true,
399+
"anyOf": [
400+
{ "type": "string" },
401+
{
402+
"type": "object",
403+
"additionalProperties": { "$recursiveRef": "#" }
404+
}
405+
]
406+
}
407+
},
408+
"anyOf": [
409+
{ "type": "integer" },
410+
{ "$ref": "#/$defs/myobject" }
411+
]
412+
},
413+
"tests": [
414+
{
415+
"description": "integer matches at the outer level",
416+
"data": 1,
417+
"valid": true
418+
},
419+
{
420+
"description": "single level match",
421+
"data": { "foo": "hi" },
422+
"valid": true
423+
},
424+
{
425+
"description": "integer now matches as a property value",
426+
"data": { "foo": 1 },
427+
"valid": true
428+
},
429+
{
430+
"description": "two levels, properties match with inner definition",
431+
"data": { "foo": { "bar": "hi" } },
432+
"valid": true
433+
},
434+
{
435+
"description": "two levels, properties match with $recursiveRef",
436+
"data": { "foo": { "bar": 1 } },
437+
"valid": true
438+
}
439+
]
308440
}
309441
]
310-

0 commit comments

Comments
 (0)