Skip to content

Commit

Permalink
Simplify re-identification in FlatFileSchemaResolver
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <jv@jviotti.com>
  • Loading branch information
jviotti committed Jan 2, 2025
1 parent 0ee2702 commit 678177e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT FlatFileSchemaResolver {
struct Entry {
const std::filesystem::path path;
const std::optional<std::string> default_dialect;
const std::optional<std::string> default_id;
};

private:
Expand Down
15 changes: 4 additions & 11 deletions src/jsonschema/resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ auto FlatFileSchemaResolver::add(
throw SchemaError(error.str());
}

const auto result{this->schemas.emplace(
identifier.value(), Entry{canonical, default_dialect, default_id})};
const auto result{this->schemas.emplace(identifier.value(),
Entry{canonical, default_dialect})};
if (!result.second && result.first->second.path != canonical) {
std::ostringstream error;
error << "Cannot register the same identifier twice: "
Expand All @@ -119,15 +119,8 @@ auto FlatFileSchemaResolver::operator()(std::string_view identifier) const
schema.assign("$schema", JSON{result->second.default_dialect.value()});
}

const auto schema_identifier{sourcemeta::jsontoolkit::identify(
schema, *this, IdentificationStrategy::Strict,
result->second.default_dialect)};
if (!schema_identifier.has_value() &&
result->second.default_id.has_value()) {
sourcemeta::jsontoolkit::reidentify(
schema, result->second.default_id.value(), *this,
result->second.default_dialect);
}
sourcemeta::jsontoolkit::reidentify(schema, result->first, *this,
result->second.default_dialect);

return schema;
}
Expand Down
1 change: 0 additions & 1 deletion test/jsonschema/jsonschema_flat_file_resolver_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,4 @@ TEST(JSONSchema_FlatFileSchemaResolver, iterators) {
EXPECT_EQ(entries.size(), 1);
EXPECT_EQ(entries.at(0).path, schema_path);
EXPECT_FALSE(entries.at(0).default_dialect.has_value());
EXPECT_FALSE(entries.at(0).default_id.has_value());
}

0 comments on commit 678177e

Please sign in to comment.