Skip to content

Commit d894234

Browse files
authored
Don't try to workaround top-level $ref on reidentify (#2017)
See: sourcemeta/jsonschema#479 Signed-off-by: Juan Cruz Viotti <[email protected]>
1 parent 6099789 commit d894234

File tree

5 files changed

+12
-46
lines changed

5 files changed

+12
-46
lines changed

src/core/jsonschema/jsonschema.cc

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -188,44 +188,6 @@ auto sourcemeta::core::reidentify(JSON &schema,
188188
assert(is_schema(schema));
189189
assert(schema.is_object());
190190
schema.assign(id_keyword(base_dialect), JSON{new_identifier});
191-
192-
if (schema.defines("$ref")) {
193-
// Workaround top-level `$ref` with `allOf`
194-
if (base_dialect == "http://json-schema.org/draft-07/schema#" ||
195-
base_dialect == "http://json-schema.org/draft-07/hyper-schema#" ||
196-
base_dialect == "http://json-schema.org/draft-06/schema#" ||
197-
base_dialect == "http://json-schema.org/draft-06/hyper-schema#" ||
198-
base_dialect == "http://json-schema.org/draft-04/schema#" ||
199-
base_dialect == "http://json-schema.org/draft-04/hyper-schema#") {
200-
// Note that if the schema already has an `allOf`, we can safely
201-
// remove it, as it was by definition ignored by `$ref` already
202-
if (schema.defines("allOf")) {
203-
schema.erase("allOf");
204-
}
205-
206-
schema.assign("allOf", JSON::make_array());
207-
auto conjunction{JSON::make_object()};
208-
conjunction.assign("$ref", schema.at("$ref"));
209-
schema.at("allOf").push_back(std::move(conjunction));
210-
schema.erase("$ref");
211-
}
212-
213-
// Workaround top-level `$ref` with `extends`
214-
if (base_dialect == "http://json-schema.org/draft-03/schema#" ||
215-
base_dialect == "http://json-schema.org/draft-03/hyper-schema#") {
216-
// Note that if the schema already has an `extends`, we can safely
217-
// remove it, as it was by definition ignored by `$ref` already
218-
if (schema.defines("extends")) {
219-
schema.erase("extends");
220-
}
221-
222-
schema.assign("extends", JSON::make_object());
223-
schema.at("extends").assign("$ref", schema.at("$ref"));
224-
schema.erase("$ref");
225-
}
226-
}
227-
228-
assert(identify(schema, base_dialect).has_value());
229191
}
230192

231193
auto sourcemeta::core::dialect(

test/jsonschema/jsonschema_identify_draft3_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ TEST(JSONSchema_identify_draft3, reidentify_set_with_top_level_ref) {
227227
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
228228
"id": "https://example.com/my-new-id",
229229
"$schema": "http://json-schema.org/draft-03/schema#",
230-
"extends": { "$ref": "https://example.com/schema" }
230+
"$ref": "https://example.com/schema"
231231
})JSON");
232232

233233
EXPECT_EQ(document, expected);
@@ -247,7 +247,8 @@ TEST(JSONSchema_identify_draft3,
247247
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
248248
"id": "https://example.com/my-new-id",
249249
"$schema": "http://json-schema.org/draft-03/schema#",
250-
"extends": { "$ref": "https://example.com/schema" }
250+
"$ref": "https://example.com/schema",
251+
"extends": { "type": "string" }
251252
})JSON");
252253

253254
EXPECT_EQ(document, expected);

test/jsonschema/jsonschema_identify_draft4_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ TEST(JSONSchema_identify_draft4, reidentify_set_with_top_level_ref) {
227227
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
228228
"id": "https://example.com/my-new-id",
229229
"$schema": "http://json-schema.org/draft-04/schema#",
230-
"allOf": [ { "$ref": "https://example.com/schema" } ]
230+
"$ref": "https://example.com/schema"
231231
})JSON");
232232

233233
EXPECT_EQ(document, expected);
@@ -246,7 +246,8 @@ TEST(JSONSchema_identify_draft4, reidentify_set_with_top_level_ref_and_allof) {
246246
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
247247
"id": "https://example.com/my-new-id",
248248
"$schema": "http://json-schema.org/draft-04/schema#",
249-
"allOf": [ { "$ref": "https://example.com/schema" } ]
249+
"$ref": "https://example.com/schema",
250+
"allOf": [ { "type": "string" } ]
250251
})JSON");
251252

252253
EXPECT_EQ(document, expected);

test/jsonschema/jsonschema_identify_draft6_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ TEST(JSONSchema_identify_draft6, reidentify_set_with_top_level_ref) {
227227
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
228228
"$id": "https://example.com/my-new-id",
229229
"$schema": "http://json-schema.org/draft-06/schema#",
230-
"allOf": [ { "$ref": "https://example.com/schema" } ]
230+
"$ref": "https://example.com/schema"
231231
})JSON");
232232

233233
EXPECT_EQ(document, expected);
@@ -246,7 +246,8 @@ TEST(JSONSchema_identify_draft6, reidentify_set_with_top_level_ref_and_allof) {
246246
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
247247
"$id": "https://example.com/my-new-id",
248248
"$schema": "http://json-schema.org/draft-06/schema#",
249-
"allOf": [ { "$ref": "https://example.com/schema" } ]
249+
"$ref": "https://example.com/schema",
250+
"allOf": [ { "type": "string" } ]
250251
})JSON");
251252

252253
EXPECT_EQ(document, expected);

test/jsonschema/jsonschema_identify_draft7_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ TEST(JSONSchema_identify_draft7, reidentify_set_with_top_level_ref) {
227227
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
228228
"$id": "https://example.com/my-new-id",
229229
"$schema": "http://json-schema.org/draft-07/schema#",
230-
"allOf": [ { "$ref": "https://example.com/schema" } ]
230+
"$ref": "https://example.com/schema"
231231
})JSON");
232232

233233
EXPECT_EQ(document, expected);
@@ -246,7 +246,8 @@ TEST(JSONSchema_identify_draft7, reidentify_set_with_top_level_ref_and_allof) {
246246
const sourcemeta::core::JSON expected = sourcemeta::core::parse_json(R"JSON({
247247
"$id": "https://example.com/my-new-id",
248248
"$schema": "http://json-schema.org/draft-07/schema#",
249-
"allOf": [ { "$ref": "https://example.com/schema" } ]
249+
"$ref": "https://example.com/schema",
250+
"allOf": [ { "type": "string" } ]
250251
})JSON");
251252

252253
EXPECT_EQ(document, expected);

0 commit comments

Comments
 (0)