Skip to content

Commit 987a4c8

Browse files
authored
Merge pull request #666 from json-schema-org/gregsdennis/file-refs
Add tests for refs into schemas with `file://` URI `$id`
2 parents fb60ed1 + 90b2a58 commit 987a4c8

File tree

6 files changed

+340
-28
lines changed

6 files changed

+340
-28
lines changed

tests/draft-next/ref.json

Lines changed: 76 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -951,32 +951,80 @@
951951
]
952952
},
953953
{
954-
"description": "ref with absolute-path-reference",
955-
"schema": {
956-
"$id": "http://example.com/ref/absref.json",
957-
"$defs": {
958-
"a": {
959-
"$id": "http://example.com/ref/absref/foobar.json",
960-
"type": "number"
961-
},
962-
"b": {
963-
"$id": "http://example.com/absref/foobar.json",
964-
"type": "string"
965-
}
966-
},
967-
"$ref": "/absref/foobar.json"
968-
},
969-
"tests": [
970-
{
971-
"description": "a string is valid",
972-
"data": "foo",
973-
"valid": true
974-
},
975-
{
976-
"description": "an integer is invalid",
977-
"data": 12,
978-
"valid": false
979-
}
980-
]
981-
}
954+
"description": "ref with absolute-path-reference",
955+
"schema": {
956+
"$id": "http://example.com/ref/absref.json",
957+
"$defs": {
958+
"a": {
959+
"$id": "http://example.com/ref/absref/foobar.json",
960+
"type": "number"
961+
},
962+
"b": {
963+
"$id": "http://example.com/absref/foobar.json",
964+
"type": "string"
965+
}
966+
},
967+
"$ref": "/absref/foobar.json"
968+
},
969+
"tests": [
970+
{
971+
"description": "a string is valid",
972+
"data": "foo",
973+
"valid": true
974+
},
975+
{
976+
"description": "an integer is invalid",
977+
"data": 12,
978+
"valid": false
979+
}
980+
]
981+
},
982+
{
983+
"description": "$id with file URI still resolves pointers - *nix",
984+
"schema": {
985+
"$id": "file:///folder/file.json",
986+
"$defs": {
987+
"foo": {
988+
"type": "number"
989+
}
990+
},
991+
"$ref": "#/$defs/foo"
992+
},
993+
"tests": [
994+
{
995+
"description": "number is valid",
996+
"data": 1,
997+
"valid": true
998+
},
999+
{
1000+
"description": "non-number is invalid",
1001+
"data": "a",
1002+
"valid": false
1003+
}
1004+
]
1005+
},
1006+
{
1007+
"description": "$id with file URI still resolves pointers - windows",
1008+
"schema": {
1009+
"$id": "file:///c:/folder/file.json",
1010+
"$defs": {
1011+
"foo": {
1012+
"type": "number"
1013+
}
1014+
},
1015+
"$ref": "#/$defs/foo"
1016+
},
1017+
"tests": [
1018+
{
1019+
"description": "number is valid",
1020+
"data": 1,
1021+
"valid": true
1022+
},
1023+
{
1024+
"description": "non-number is invalid",
1025+
"data": "a",
1026+
"valid": false
1027+
}
1028+
]
1029+
}
9821030
]

tests/draft2019-09/ref.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,5 +978,53 @@
978978
"valid": false
979979
}
980980
]
981+
},
982+
{
983+
"description": "$id with file URI still resolves pointers - *nix",
984+
"schema": {
985+
"$id": "file:///folder/file.json",
986+
"$defs": {
987+
"foo": {
988+
"type": "number"
989+
}
990+
},
991+
"$ref": "#/$defs/foo"
992+
},
993+
"tests": [
994+
{
995+
"description": "number is valid",
996+
"data": 1,
997+
"valid": true
998+
},
999+
{
1000+
"description": "non-number is invalid",
1001+
"data": "a",
1002+
"valid": false
1003+
}
1004+
]
1005+
},
1006+
{
1007+
"description": "$id with file URI still resolves pointers - windows",
1008+
"schema": {
1009+
"$id": "file:///c:/folder/file.json",
1010+
"$defs": {
1011+
"foo": {
1012+
"type": "number"
1013+
}
1014+
},
1015+
"$ref": "#/$defs/foo"
1016+
},
1017+
"tests": [
1018+
{
1019+
"description": "number is valid",
1020+
"data": 1,
1021+
"valid": true
1022+
},
1023+
{
1024+
"description": "non-number is invalid",
1025+
"data": "a",
1026+
"valid": false
1027+
}
1028+
]
9811029
}
9821030
]

tests/draft2020-12/ref.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -978,5 +978,53 @@
978978
"valid": false
979979
}
980980
]
981+
},
982+
{
983+
"description": "$id with file URI still resolves pointers - *nix",
984+
"schema": {
985+
"$id": "file:///folder/file.json",
986+
"$defs": {
987+
"foo": {
988+
"type": "number"
989+
}
990+
},
991+
"$ref": "#/$defs/foo"
992+
},
993+
"tests": [
994+
{
995+
"description": "number is valid",
996+
"data": 1,
997+
"valid": true
998+
},
999+
{
1000+
"description": "non-number is invalid",
1001+
"data": "a",
1002+
"valid": false
1003+
}
1004+
]
1005+
},
1006+
{
1007+
"description": "$id with file URI still resolves pointers - windows",
1008+
"schema": {
1009+
"$id": "file:///c:/folder/file.json",
1010+
"$defs": {
1011+
"foo": {
1012+
"type": "number"
1013+
}
1014+
},
1015+
"$ref": "#/$defs/foo"
1016+
},
1017+
"tests": [
1018+
{
1019+
"description": "number is valid",
1020+
"data": 1,
1021+
"valid": true
1022+
},
1023+
{
1024+
"description": "non-number is invalid",
1025+
"data": "a",
1026+
"valid": false
1027+
}
1028+
]
9811029
}
9821030
]

tests/draft4/ref.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,5 +503,61 @@
503503
"valid": false
504504
}
505505
]
506+
},
507+
{
508+
"description": "id with file URI still resolves pointers - *nix",
509+
"schema": {
510+
"id": "file:///folder/file.json",
511+
"definitions": {
512+
"foo": {
513+
"type": "number"
514+
}
515+
},
516+
"allOf": [
517+
{
518+
"$ref": "#/definitions/foo"
519+
}
520+
]
521+
},
522+
"tests": [
523+
{
524+
"description": "number is valid",
525+
"data": 1,
526+
"valid": true
527+
},
528+
{
529+
"description": "non-number is invalid",
530+
"data": "a",
531+
"valid": false
532+
}
533+
]
534+
},
535+
{
536+
"description": "id with file URI still resolves pointers - windows",
537+
"schema": {
538+
"id": "file:///c:/folder/file.json",
539+
"definitions": {
540+
"foo": {
541+
"type": "number"
542+
}
543+
},
544+
"allOf": [
545+
{
546+
"$ref": "#/definitions/foo"
547+
}
548+
]
549+
},
550+
"tests": [
551+
{
552+
"description": "number is valid",
553+
"data": 1,
554+
"valid": true
555+
},
556+
{
557+
"description": "non-number is invalid",
558+
"data": "a",
559+
"valid": false
560+
}
561+
]
506562
}
507563
]

tests/draft6/ref.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,5 +813,61 @@
813813
"valid": false
814814
}
815815
]
816+
},
817+
{
818+
"description": "$id with file URI still resolves pointers - *nix",
819+
"schema": {
820+
"$id": "file:///folder/file.json",
821+
"definitions": {
822+
"foo": {
823+
"type": "number"
824+
}
825+
},
826+
"allOf": [
827+
{
828+
"$ref": "#/definitions/foo"
829+
}
830+
]
831+
},
832+
"tests": [
833+
{
834+
"description": "number is valid",
835+
"data": 1,
836+
"valid": true
837+
},
838+
{
839+
"description": "non-number is invalid",
840+
"data": "a",
841+
"valid": false
842+
}
843+
]
844+
},
845+
{
846+
"description": "$id with file URI still resolves pointers - windows",
847+
"schema": {
848+
"$id": "file:///c:/folder/file.json",
849+
"definitions": {
850+
"foo": {
851+
"type": "number"
852+
}
853+
},
854+
"allOf": [
855+
{
856+
"$ref": "#/definitions/foo"
857+
}
858+
]
859+
},
860+
"tests": [
861+
{
862+
"description": "number is valid",
863+
"data": 1,
864+
"valid": true
865+
},
866+
{
867+
"description": "non-number is invalid",
868+
"data": "a",
869+
"valid": false
870+
}
871+
]
816872
}
817873
]

0 commit comments

Comments
 (0)