Skip to content

Commit 7445d6a

Browse files
committed
Add tests combining relative refs and defs
Both for absolute and relative refs.
1 parent 3c45b81 commit 7445d6a

File tree

4 files changed

+416
-0
lines changed

4 files changed

+416
-0
lines changed

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

tests/draft6/ref.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,5 +489,109 @@
489489
"valid": true
490490
}
491491
]
492+
},
493+
{
494+
"description": "refs with relative uris and defs",
495+
"schema": {
496+
"$id": "http://example.com/schema1.json",
497+
"properties": {
498+
"foo": {
499+
"$id": "schema2.json",
500+
"definitions": {
501+
"inner": {
502+
"properties": {
503+
"bar": { "type": "string" }
504+
}
505+
}
506+
},
507+
"allOf": [ { "$ref": "#/definitions/inner" } ]
508+
}
509+
},
510+
"allOf": [ { "$ref": "schema2.json" } ]
511+
},
512+
"tests": [
513+
{
514+
"description": "invalid on inner field",
515+
"data": {
516+
"foo": {
517+
"bar": 1
518+
},
519+
"bar": "a"
520+
},
521+
"valid": false
522+
},
523+
{
524+
"description": "invalid on outer field",
525+
"data": {
526+
"foo": {
527+
"bar": "a"
528+
},
529+
"bar": 1
530+
},
531+
"valid": false
532+
},
533+
{
534+
"description": "valid on both fields",
535+
"data": {
536+
"foo": {
537+
"bar": "a"
538+
},
539+
"bar": "a"
540+
},
541+
"valid": true
542+
}
543+
]
544+
},
545+
{
546+
"description": "relative refs with absolute uris and defs",
547+
"schema": {
548+
"$id": "http://example.com/schema1.json",
549+
"properties": {
550+
"foo": {
551+
"$id": "http://example.com/schema2.json",
552+
"definitions": {
553+
"inner": {
554+
"properties": {
555+
"bar": { "type": "string" }
556+
}
557+
}
558+
},
559+
"allOf": [ { "$ref": "#/definitions/inner" } ]
560+
}
561+
},
562+
"allOf": [ { "$ref": "schema2.json" } ]
563+
},
564+
"tests": [
565+
{
566+
"description": "invalid on inner field",
567+
"data": {
568+
"foo": {
569+
"bar": 1
570+
},
571+
"bar": "a"
572+
},
573+
"valid": false
574+
},
575+
{
576+
"description": "invalid on outer field",
577+
"data": {
578+
"foo": {
579+
"bar": "a"
580+
},
581+
"bar": 1
582+
},
583+
"valid": false
584+
},
585+
{
586+
"description": "valid on both fields",
587+
"data": {
588+
"foo": {
589+
"bar": "a"
590+
},
591+
"bar": "a"
592+
},
593+
"valid": true
594+
}
595+
]
492596
}
493597
]

0 commit comments

Comments
 (0)