Skip to content

Commit

Permalink
Remove destination_of from framing
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti committed Feb 11, 2025
1 parent 4f74efa commit b16b0c8
Show file tree
Hide file tree
Showing 13 changed files with 1,203 additions and 1,406 deletions.
84 changes: 11 additions & 73 deletions src/core/jsonschema/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -172,50 +172,6 @@ static auto fragment_string(const sourcemeta::core::URI &uri)
return std::nullopt;
}

static auto has_equivalent_origin(
const sourcemeta::core::SchemaFrame::Locations &frame,
const std::vector<std::reference_wrapper<
const sourcemeta::core::SchemaFrame::LocationKey>> &destination_of,
const sourcemeta::core::SchemaFrame::Locations::value_type &entry) -> bool {
return std::any_of(destination_of.cbegin(), destination_of.cend(),
[&entry, &frame](const auto &destination) {
return destination.get() == entry.first ||
frame.at(destination.get()).pointer ==
entry.second.pointer;
});
}

static auto mark_reference_origins_from(
sourcemeta::core::SchemaFrame::Locations &frame,
const sourcemeta::core::SchemaFrame::References &references,
const sourcemeta::core::SchemaFrame::Locations::value_type &entry) -> void {
for (const auto &reference : references) {
assert(!reference.first.second.empty() &&
reference.first.second.back().is_property());
assert(reference.first.second.back().to_property() == "$schema" ||
reference.first.second.back().to_property() == "$ref" ||
reference.first.second.back().to_property() == "$recursiveRef" ||
reference.first.second.back().to_property() == "$dynamicRef");
if (reference.first.second.initial() != entry.second.pointer) {
continue;
}

auto match{
frame.find({reference.first.first, reference.second.destination})};
if (match == frame.cend()) {
continue;
}

for (auto &subentry : frame) {
if (subentry.second.pointer == match->second.pointer &&
!has_equivalent_origin(frame, subentry.second.destination_of,
entry)) {
subentry.second.destination_of.emplace_back(entry.first);
}
}
}
}

static auto
store(sourcemeta::core::SchemaFrame::Locations &frame,
const sourcemeta::core::SchemaReferenceType type,
Expand All @@ -234,16 +190,17 @@ store(sourcemeta::core::SchemaFrame::Locations &frame,
const auto canonical{sourcemeta::core::URI{uri}.canonicalize().recompose()};
const auto inserted{frame
.insert({{type, canonical},
{parent,
entry_type,
root_id,
base_id,
pointer_from_root,
pointer_from_base,
dialect,
base_dialect,
instance_locations,
{}}})
{
parent,
entry_type,
root_id,
base_id,
pointer_from_root,
pointer_from_base,
dialect,
base_dialect,
instance_locations,
}})
.second};
if (!ignore_if_present && !inserted) {
std::ostringstream error;
Expand Down Expand Up @@ -933,25 +890,6 @@ auto internal_analyse(const sourcemeta::core::SchemaFrame::Mode mode,
}

if (mode == sourcemeta::core::SchemaFrame::Mode::Instances) {
// We only care about marking reference origins from/to resources and
// subschemas

for (const auto &entry : frame) {
if (entry.second.type != SchemaFrame::LocationType::Resource) {
continue;
}

mark_reference_origins_from(frame, references, entry);
}

for (const auto &entry : frame) {
if (entry.second.type != SchemaFrame::LocationType::Subschema) {
continue;
}

mark_reference_origins_from(frame, references, entry);
}

// Calculate alternative unresolved instance locations
for (auto &entry : frame) {
traverse_origin_instance_locations(references, frame, entry.second,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
std::string dialect;
std::string base_dialect;
std::vector<PointerTemplate> instance_locations;
std::vector<std::reference_wrapper<const LocationKey>> destination_of;
};

/// A JSON Schema reference frame is a mapping of URIs to schema identifiers,
Expand Down
Loading

0 comments on commit b16b0c8

Please sign in to comment.