Skip to content

Commit 0eeed11

Browse files
committed
Add tests combining relative refs and defs
For ref and recursiveRef, both for absolute and relative ids.
1 parent fcae732 commit 0eeed11

File tree

3 files changed

+312
-0
lines changed

3 files changed

+312
-0
lines changed

tests/draft2019-09/recursiveRef.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,109 @@
352352
"valid": false
353353
}
354354
]
355+
},
356+
{
357+
"description": "recursive refs with relative uris and defs",
358+
"schema": {
359+
"$id": "schema1.json",
360+
"properties": {
361+
"foo": {
362+
"$id": "schema2.json",
363+
"$defs": {
364+
"inner": {
365+
"properties": {
366+
"bar": { "type": "string" }
367+
}
368+
}
369+
},
370+
"$recursiveRef": "#/$defs/inner"
371+
}
372+
},
373+
"$recursiveRef": "schema2.json"
374+
},
375+
"tests": [
376+
{
377+
"description": "invalid on inner field",
378+
"data": {
379+
"foo": {
380+
"bar": 1
381+
},
382+
"bar": "a"
383+
},
384+
"valid": false
385+
},
386+
{
387+
"description": "invalid on outer field",
388+
"data": {
389+
"foo": {
390+
"bar": "a"
391+
},
392+
"bar": 1
393+
},
394+
"valid": false
395+
},
396+
{
397+
"description": "valid on both fields",
398+
"data": {
399+
"foo": {
400+
"bar": "a"
401+
},
402+
"bar": "a"
403+
},
404+
"valid": true
405+
}
406+
]
407+
},
408+
{
409+
"description": "relative recursive refs with absolute uris and defs",
410+
"schema": {
411+
"$id": "http://example.com/schema1.json",
412+
"properties": {
413+
"foo": {
414+
"$id": "http://example.com/schema2.json",
415+
"$defs": {
416+
"inner": {
417+
"properties": {
418+
"bar": { "type": "string" }
419+
}
420+
}
421+
},
422+
"$recursiveRef": "#/$defs/inner"
423+
}
424+
},
425+
"$recursiveRef": "schema2.json"
426+
},
427+
"tests": [
428+
{
429+
"description": "invalid on inner field",
430+
"data": {
431+
"foo": {
432+
"bar": 1
433+
},
434+
"bar": "a"
435+
},
436+
"valid": false
437+
},
438+
{
439+
"description": "invalid on outer field",
440+
"data": {
441+
"foo": {
442+
"bar": "a"
443+
},
444+
"bar": 1
445+
},
446+
"valid": false
447+
},
448+
{
449+
"description": "valid on both fields",
450+
"data": {
451+
"foo": {
452+
"bar": "a"
453+
},
454+
"bar": "a"
455+
},
456+
"valid": true
457+
}
458+
]
355459
}
356460
]

tests/draft2019-09/ref.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,109 @@
430430
"valid": true
431431
}
432432
]
433+
},
434+
{
435+
"description": "refs with relative uris and defs",
436+
"schema": {
437+
"$id": "schema1.json",
438+
"properties": {
439+
"foo": {
440+
"$id": "schema2.json",
441+
"$defs": {
442+
"inner": {
443+
"properties": {
444+
"bar": { "type": "string" }
445+
}
446+
}
447+
},
448+
"$ref": "#/$defs/inner"
449+
}
450+
},
451+
"$ref": "schema2.json"
452+
},
453+
"tests": [
454+
{
455+
"description": "invalid on inner field",
456+
"data": {
457+
"foo": {
458+
"bar": 1
459+
},
460+
"bar": "a"
461+
},
462+
"valid": false
463+
},
464+
{
465+
"description": "invalid on outer field",
466+
"data": {
467+
"foo": {
468+
"bar": "a"
469+
},
470+
"bar": 1
471+
},
472+
"valid": false
473+
},
474+
{
475+
"description": "valid on both fields",
476+
"data": {
477+
"foo": {
478+
"bar": "a"
479+
},
480+
"bar": "a"
481+
},
482+
"valid": true
483+
}
484+
]
485+
},
486+
{
487+
"description": "relative refs with absolute uris and defs",
488+
"schema": {
489+
"$id": "http://example.com/schema1.json",
490+
"properties": {
491+
"foo": {
492+
"$id": "http://example.com/schema2.json",
493+
"$defs": {
494+
"inner": {
495+
"properties": {
496+
"bar": { "type": "string" }
497+
}
498+
}
499+
},
500+
"$ref": "#/$defs/inner"
501+
}
502+
},
503+
"$ref": "schema2.json"
504+
},
505+
"tests": [
506+
{
507+
"description": "invalid on inner field",
508+
"data": {
509+
"foo": {
510+
"bar": 1
511+
},
512+
"bar": "a"
513+
},
514+
"valid": false
515+
},
516+
{
517+
"description": "invalid on outer field",
518+
"data": {
519+
"foo": {
520+
"bar": "a"
521+
},
522+
"bar": 1
523+
},
524+
"valid": false
525+
},
526+
{
527+
"description": "valid on both fields",
528+
"data": {
529+
"foo": {
530+
"bar": "a"
531+
},
532+
"bar": "a"
533+
},
534+
"valid": true
535+
}
536+
]
433537
}
434538
]

tests/draft2020-12/ref.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,5 +430,109 @@
430430
"valid": true
431431
}
432432
]
433+
},
434+
{
435+
"description": "refs with relative uris and defs",
436+
"schema": {
437+
"$id": "schema1.json",
438+
"properties": {
439+
"foo": {
440+
"$id": "schema2.json",
441+
"$defs": {
442+
"inner": {
443+
"properties": {
444+
"bar": { "type": "string" }
445+
}
446+
}
447+
},
448+
"$ref": "#/$defs/inner"
449+
}
450+
},
451+
"$ref": "schema2.json"
452+
},
453+
"tests": [
454+
{
455+
"description": "invalid on inner field",
456+
"data": {
457+
"foo": {
458+
"bar": 1
459+
},
460+
"bar": "a"
461+
},
462+
"valid": false
463+
},
464+
{
465+
"description": "invalid on outer field",
466+
"data": {
467+
"foo": {
468+
"bar": "a"
469+
},
470+
"bar": 1
471+
},
472+
"valid": false
473+
},
474+
{
475+
"description": "valid on both fields",
476+
"data": {
477+
"foo": {
478+
"bar": "a"
479+
},
480+
"bar": "a"
481+
},
482+
"valid": true
483+
}
484+
]
485+
},
486+
{
487+
"description": "relative refs with absolute uris and defs",
488+
"schema": {
489+
"$id": "http://example.com/schema1.json",
490+
"properties": {
491+
"foo": {
492+
"$id": "http://example.com/schema2.json",
493+
"$defs": {
494+
"inner": {
495+
"properties": {
496+
"bar": { "type": "string" }
497+
}
498+
}
499+
},
500+
"$ref": "#/$defs/inner"
501+
}
502+
},
503+
"$ref": "schema2.json"
504+
},
505+
"tests": [
506+
{
507+
"description": "invalid on inner field",
508+
"data": {
509+
"foo": {
510+
"bar": 1
511+
},
512+
"bar": "a"
513+
},
514+
"valid": false
515+
},
516+
{
517+
"description": "invalid on outer field",
518+
"data": {
519+
"foo": {
520+
"bar": "a"
521+
},
522+
"bar": 1
523+
},
524+
"valid": false
525+
},
526+
{
527+
"description": "valid on both fields",
528+
"data": {
529+
"foo": {
530+
"bar": "a"
531+
},
532+
"bar": "a"
533+
},
534+
"valid": true
535+
}
536+
]
433537
}
434538
]

0 commit comments

Comments
 (0)