diff --git a/test/jsonschema/jsonschema_bundle_2019_09_test.cc b/test/jsonschema/jsonschema_bundle_2019_09_test.cc index b54f0fe3b..59e2ce8b5 100644 --- a/test/jsonschema/jsonschema_bundle_2019_09_test.cc +++ b/test/jsonschema/jsonschema_bundle_2019_09_test.cc @@ -579,3 +579,34 @@ TEST(JSONSchema_bundle_2019_09, metaschema_without_id) { EXPECT_EQ(document, expected); } + +TEST(JSONSchema_bundle_2019_09, relative_base_uri_with_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$anchor": "reference" + } + } + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "https://json-schema.org/draft/2019-09/schema", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$anchor": "reference" + } + } + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/jsonschema/jsonschema_bundle_2020_12_test.cc b/test/jsonschema/jsonschema_bundle_2020_12_test.cc index dd879bbaf..1026a6d00 100644 --- a/test/jsonschema/jsonschema_bundle_2020_12_test.cc +++ b/test/jsonschema/jsonschema_bundle_2020_12_test.cc @@ -661,3 +661,34 @@ TEST(JSONSchema_bundle_2020_12, metaschema_without_id) { EXPECT_EQ(document, expected); } + +TEST(JSONSchema_bundle_2020_12, relative_base_uri_with_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$anchor": "reference" + } + } + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$anchor": "reference" + } + } + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/jsonschema/jsonschema_bundle_draft4_test.cc b/test/jsonschema/jsonschema_bundle_draft4_test.cc index 6a2c331ce..13264a1dd 100644 --- a/test/jsonschema/jsonschema_bundle_draft4_test.cc +++ b/test/jsonschema/jsonschema_bundle_draft4_test.cc @@ -585,3 +585,53 @@ TEST(JSONSchema_bundle_draft4, metaschema_without_id) { EXPECT_EQ(document, expected); } + +TEST(JSONSchema_bundle_draft4, relative_base_uri_without_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "foo" + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "foo" + })JSON"); + + EXPECT_EQ(document, expected); +} + +TEST(JSONSchema_bundle_draft4, relative_base_uri_with_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "id": "#reference" + } + } + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-04/schema#", + "id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "id": "#reference" + } + } + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/jsonschema/jsonschema_bundle_draft6_test.cc b/test/jsonschema/jsonschema_bundle_draft6_test.cc index 0834c77e5..098a1a4dd 100644 --- a/test/jsonschema/jsonschema_bundle_draft6_test.cc +++ b/test/jsonschema/jsonschema_bundle_draft6_test.cc @@ -560,3 +560,34 @@ TEST(JSONSchema_bundle_draft6, metaschema_without_id) { EXPECT_EQ(document, expected); } + +TEST(JSONSchema_bundle_draft6, relative_base_uri_with_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-06/schema#", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$id": "#reference" + } + } + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-06/schema#", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$id": "#reference" + } + } + })JSON"); + + EXPECT_EQ(document, expected); +} diff --git a/test/jsonschema/jsonschema_bundle_draft7_test.cc b/test/jsonschema/jsonschema_bundle_draft7_test.cc index 73b2b5203..49bc874a3 100644 --- a/test/jsonschema/jsonschema_bundle_draft7_test.cc +++ b/test/jsonschema/jsonschema_bundle_draft7_test.cc @@ -560,3 +560,34 @@ TEST(JSONSchema_bundle_draft7, metaschema_without_id) { EXPECT_EQ(document, expected); } + +TEST(JSONSchema_bundle_draft7, relative_base_uri_with_ref) { + sourcemeta::jsontoolkit::JSON document = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$id": "#reference" + } + } + })JSON"); + + sourcemeta::jsontoolkit::bundle( + document, sourcemeta::jsontoolkit::default_schema_walker, test_resolver); + + const sourcemeta::jsontoolkit::JSON expected = + sourcemeta::jsontoolkit::parse(R"JSON({ + "$schema": "http://json-schema.org/draft-07/schema#", + "$id": "common", + "allOf": [ { "$ref": "#reference" } ], + "definitions": { + "reference": { + "$id": "#reference" + } + } + })JSON"); + + EXPECT_EQ(document, expected); +}