Skip to content

Commit d0fae25

Browse files
authored
Don't enforce wrap() URIs to be absolute (they could be relative) (#1629)
See: sourcemeta/jsonschema#304 (comment) Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
1 parent 84dc1ab commit d0fae25

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/core/jsonschema/jsonschema.cc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,6 @@ auto sourcemeta::core::unidentify(
694694

695695
auto sourcemeta::core::wrap(const sourcemeta::core::JSON::String &identifier)
696696
-> sourcemeta::core::JSON {
697-
assert(URI{identifier}.is_absolute());
698697
auto result{JSON::make_object()};
699698
// JSON Schema 2020-12 is the first dialect that truly supports cross-dialect
700699
// references In practice, others do, but we can play it safe here

test/jsonschema/jsonschema_wrap_test.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@ TEST(JSONSchema_wrap, identifier_without_fragment) {
1515
EXPECT_EQ(result, expected);
1616
}
1717

18+
// Should still work, as people might be relying on relative URIs
19+
// as identifiers though still correctly resolving those
20+
TEST(JSONSchema_wrap, identifier_relative) {
21+
const auto identifier{"/foo/bar"};
22+
const auto result{sourcemeta::core::wrap(identifier)};
23+
24+
const auto expected{sourcemeta::core::parse_json(R"JSON({
25+
"$schema": "https://json-schema.org/draft/2020-12/schema",
26+
"$ref": "/foo/bar"
27+
})JSON")};
28+
29+
EXPECT_EQ(result, expected);
30+
}
31+
1832
TEST(JSONSchema_wrap, identifier_with_fragment) {
1933
const auto identifier{"https://www.example.com#/foo/bar"};
2034
const auto result{sourcemeta::core::wrap(identifier)};

0 commit comments

Comments
 (0)