Skip to content

Commit

Permalink
Support relative base URIs
Browse files Browse the repository at this point in the history
Fixes: #960
See: sourcemeta/jsonschema#185
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Nov 4, 2024
1 parent 49e5bf6 commit 89d5c49
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 0 deletions.
31 changes: 31 additions & 0 deletions test/jsonschema/jsonschema_bundle_2019_09_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 31 additions & 0 deletions test/jsonschema/jsonschema_bundle_2020_12_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
50 changes: 50 additions & 0 deletions test/jsonschema/jsonschema_bundle_draft4_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 31 additions & 0 deletions test/jsonschema/jsonschema_bundle_draft6_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
31 changes: 31 additions & 0 deletions test/jsonschema/jsonschema_bundle_draft7_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit 89d5c49

Please sign in to comment.