Skip to content

Commit 96255ef

Browse files
committed
Add some simple tests for URN base URIs.
See https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-01#section-8.2.1 (which specifies that $id is any URI from RFC 3986, which URNs are an example of). Earlier drafts (6 and 7) didn't fully disallow $ids with fragments (they left the behavior undefined, and their metaschemas didn't guard against them), so we leave off the f-component test in these drafts. Closes: #179
1 parent fd9bcfb commit 96255ef

File tree

5 files changed

+657
-0
lines changed

5 files changed

+657
-0
lines changed

tests/draft-next/ref.json

+137
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,142 @@
642642
"valid": false
643643
}
644644
]
645+
},
646+
{
647+
"description": "simple URN base URI with $ref via the URN",
648+
"schema": {
649+
"$comment": "URIs do not have to have HTTP(s) schemes",
650+
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
651+
"minimum": 30,
652+
"properties": {
653+
"foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"}
654+
}
655+
},
656+
"tests": [
657+
{
658+
"description": "valid under the URN IDed schema",
659+
"data": {"foo": 37},
660+
"valid": true
661+
},
662+
{
663+
"description": "invalid under the URN IDed schema",
664+
"data": {"foo": 12},
665+
"valid": false
666+
}
667+
]
668+
},
669+
{
670+
"description": "simple URN base URI with JSON pointer",
671+
"schema": {
672+
"$comment": "URIs do not have to have HTTP(s) schemes",
673+
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
674+
"properties": {
675+
"foo": {"$ref": "#/$defs/bar"}
676+
},
677+
"$defs": {
678+
"bar": {"type": "string"}
679+
}
680+
},
681+
"tests": [
682+
{
683+
"description": "a string is valid",
684+
"data": {"foo": "bar"},
685+
"valid": true
686+
},
687+
{
688+
"description": "a non-string is invalid",
689+
"data": {"foo": 12},
690+
"valid": false
691+
}
692+
]
693+
},
694+
{
695+
"description": "URN base URI with NSS",
696+
"schema": {
697+
"$comment": "RFC 8141 §2.2",
698+
"$id": "urn:example:1/406/47452/2",
699+
"properties": {
700+
"foo": {"$ref": "#/$defs/bar"}
701+
},
702+
"$defs": {
703+
"bar": {"type": "string"}
704+
}
705+
},
706+
"tests": [
707+
{
708+
"description": "a string is valid",
709+
"data": {"foo": "bar"},
710+
"valid": true
711+
},
712+
{
713+
"description": "a non-string is invalid",
714+
"data": {"foo": 12},
715+
"valid": false
716+
}
717+
]
718+
},
719+
{
720+
"description": "URN base URI with r-component",
721+
"schema": {
722+
"$comment": "RFC 8141 §2.3.1",
723+
"$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk",
724+
"properties": {
725+
"foo": {"$ref": "#/$defs/bar"}
726+
},
727+
"$defs": {
728+
"bar": {"type": "string"}
729+
}
730+
},
731+
"tests": [
732+
{
733+
"description": "a string is valid",
734+
"data": {"foo": "bar"},
735+
"valid": true
736+
},
737+
{
738+
"description": "a non-string is invalid",
739+
"data": {"foo": 12},
740+
"valid": false
741+
}
742+
]
743+
},
744+
{
745+
"description": "URN base URI with q-component",
746+
"schema": {
747+
"$comment": "RFC 8141 §2.3.2",
748+
"$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z",
749+
"properties": {
750+
"foo": {"$ref": "#/$defs/bar"}
751+
},
752+
"$defs": {
753+
"bar": {"type": "string"}
754+
}
755+
},
756+
"tests": [
757+
{
758+
"description": "a string is valid",
759+
"data": {"foo": "bar"},
760+
"valid": true
761+
},
762+
{
763+
"description": "a non-string is invalid",
764+
"data": {"foo": 12},
765+
"valid": false
766+
}
767+
]
768+
},
769+
{
770+
"description": "URN base URI with f-component",
771+
"schema": {
772+
"$comment": "RFC 8141 §2.3.3, but we don't allow fragments",
773+
"$ref": "https://json-schema.org/draft/next/schema"
774+
},
775+
"tests": [
776+
{
777+
"description": "is invalid",
778+
"data": {"$id": "urn:example:foo-bar-baz-qux#somepart"},
779+
"valid": false
780+
}
781+
]
645782
}
646783
]

tests/draft2019-09/ref.json

+137
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,142 @@
642642
"valid": false
643643
}
644644
]
645+
},
646+
{
647+
"description": "simple URN base URI with $ref via the URN",
648+
"schema": {
649+
"$comment": "URIs do not have to have HTTP(s) schemes",
650+
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
651+
"minimum": 30,
652+
"properties": {
653+
"foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"}
654+
}
655+
},
656+
"tests": [
657+
{
658+
"description": "valid under the URN IDed schema",
659+
"data": {"foo": 37},
660+
"valid": true
661+
},
662+
{
663+
"description": "invalid under the URN IDed schema",
664+
"data": {"foo": 12},
665+
"valid": false
666+
}
667+
]
668+
},
669+
{
670+
"description": "simple URN base URI with JSON pointer",
671+
"schema": {
672+
"$comment": "URIs do not have to have HTTP(s) schemes",
673+
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
674+
"properties": {
675+
"foo": {"$ref": "#/$defs/bar"}
676+
},
677+
"$defs": {
678+
"bar": {"type": "string"}
679+
}
680+
},
681+
"tests": [
682+
{
683+
"description": "a string is valid",
684+
"data": {"foo": "bar"},
685+
"valid": true
686+
},
687+
{
688+
"description": "a non-string is invalid",
689+
"data": {"foo": 12},
690+
"valid": false
691+
}
692+
]
693+
},
694+
{
695+
"description": "URN base URI with NSS",
696+
"schema": {
697+
"$comment": "RFC 8141 §2.2",
698+
"$id": "urn:example:1/406/47452/2",
699+
"properties": {
700+
"foo": {"$ref": "#/$defs/bar"}
701+
},
702+
"$defs": {
703+
"bar": {"type": "string"}
704+
}
705+
},
706+
"tests": [
707+
{
708+
"description": "a string is valid",
709+
"data": {"foo": "bar"},
710+
"valid": true
711+
},
712+
{
713+
"description": "a non-string is invalid",
714+
"data": {"foo": 12},
715+
"valid": false
716+
}
717+
]
718+
},
719+
{
720+
"description": "URN base URI with r-component",
721+
"schema": {
722+
"$comment": "RFC 8141 §2.3.1",
723+
"$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk",
724+
"properties": {
725+
"foo": {"$ref": "#/$defs/bar"}
726+
},
727+
"$defs": {
728+
"bar": {"type": "string"}
729+
}
730+
},
731+
"tests": [
732+
{
733+
"description": "a string is valid",
734+
"data": {"foo": "bar"},
735+
"valid": true
736+
},
737+
{
738+
"description": "a non-string is invalid",
739+
"data": {"foo": 12},
740+
"valid": false
741+
}
742+
]
743+
},
744+
{
745+
"description": "URN base URI with q-component",
746+
"schema": {
747+
"$comment": "RFC 8141 §2.3.2",
748+
"$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z",
749+
"properties": {
750+
"foo": {"$ref": "#/$defs/bar"}
751+
},
752+
"$defs": {
753+
"bar": {"type": "string"}
754+
}
755+
},
756+
"tests": [
757+
{
758+
"description": "a string is valid",
759+
"data": {"foo": "bar"},
760+
"valid": true
761+
},
762+
{
763+
"description": "a non-string is invalid",
764+
"data": {"foo": 12},
765+
"valid": false
766+
}
767+
]
768+
},
769+
{
770+
"description": "URN base URI with f-component",
771+
"schema": {
772+
"$comment": "RFC 8141 §2.3.3, but we don't allow fragments",
773+
"$ref": "https://json-schema.org/draft/2019-09/schema"
774+
},
775+
"tests": [
776+
{
777+
"description": "is invalid",
778+
"data": {"$id": "urn:example:foo-bar-baz-qux#somepart"},
779+
"valid": false
780+
}
781+
]
645782
}
646783
]

0 commit comments

Comments
 (0)