Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 30 additions & 18 deletions src/core/jsonschema/frame.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ auto store(sourcemeta::core::SchemaFrame::Locations &frame,
const std::string_view dialect,
const sourcemeta::core::SchemaBaseDialect base_dialect,
const std::optional<sourcemeta::core::WeakPointer> &parent,
const bool ignore_if_present = false,
const bool property_name, const bool ignore_if_present = false,
const bool already_canonical = false) -> void {
auto canonical{already_canonical ? std::move(uri)
: sourcemeta::core::URI::canonicalize(uri)};
Expand All @@ -308,7 +308,8 @@ auto store(sourcemeta::core::SchemaFrame::Locations &frame,
.pointer = pointer_from_root,
.relative_pointer = relative_pointer_offset,
.dialect = dialect,
.base_dialect = base_dialect}});
.base_dialect = base_dialect,
.property_name = property_name}});
if (!ignore_if_present && !inserted) {
throw_already_exists(iterator->first.second);
}
Expand All @@ -329,6 +330,7 @@ struct InternalEntry {
// NOLINTNEXTLINE(bugprone-exception-escape)
struct CacheSubschema {
bool orphan{};
bool property_name{};
std::optional<sourcemeta::core::WeakPointer> parent{};
};

Expand Down Expand Up @@ -391,6 +393,8 @@ auto SchemaFrame::to_json(
entry.assign_assume_new(
"baseDialect",
JSON{JSON::String{to_string(location.second.base_dialect)}});
entry.assign_assume_new("propertyName",
JSON{location.second.property_name});

switch (location.first.first) {
case SchemaReferenceType::Static:
Expand Down Expand Up @@ -498,7 +502,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
store(this->locations_, SchemaReferenceType::Static,
SchemaFrame::LocationType::Resource, default_id_canonical,
this->root_, path, path.size(), root_dialect,
root_base_dialect.value(), std::nullopt);
root_base_dialect.value(), std::nullopt, false);

base_uris.insert({path, {root_id.value(), default_id_canonical}});
}
Expand Down Expand Up @@ -535,8 +539,10 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
: std::nullopt};

// Store information
subschemas.emplace(entry.pointer, CacheSubschema{.orphan = entry.orphan,
.parent = entry.parent});
subschemas.emplace(entry.pointer,
CacheSubschema{.orphan = entry.orphan,
.property_name = entry.property_name,
.parent = entry.parent});
subschema_entries.emplace_back(
InternalEntry{.common = std::move(entry), .id = std::move(id)});
current_subschema_entries.emplace_back(subschema_entries.size() - 1);
Expand Down Expand Up @@ -602,7 +608,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Resource, new_id, new_id,
common_pointer_weak, common_pointer_weak.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent);
common_parent, entry.common.property_name);
}

auto base_uri_match{base_uris.find(common_pointer_weak)};
Expand Down Expand Up @@ -665,15 +671,15 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Anchor, relative_anchor_uri, "",
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent);
common_parent, entry.common.property_name);
}

if (type == AnchorType::Dynamic || type == AnchorType::All) {
store(this->locations_, SchemaReferenceType::Dynamic,
SchemaFrame::LocationType::Anchor, relative_anchor_uri, "",
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent);
common_parent, entry.common.property_name);

// Register a dynamic anchor as a static anchor if possible too
if (entry.common.vocabularies.contains(
Expand All @@ -682,7 +688,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Anchor, relative_anchor_uri, "",
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent, true);
common_parent, entry.common.property_name, true);
}
}
} else {
Expand Down Expand Up @@ -712,7 +718,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Anchor, anchor_uri, base_view,
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent);
common_parent, entry.common.property_name);
}

if (type == AnchorType::Dynamic || type == AnchorType::All) {
Expand All @@ -721,7 +727,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Anchor, anchor_uri, base_view,
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent);
common_parent, entry.common.property_name);

// Register a dynamic anchor as a static anchor if possible too
if (entry.common.vocabularies.contains(
Expand All @@ -731,7 +737,7 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Anchor, anchor_uri, base_view,
common_pointer_weak, bases.second.size(),
entry.common.dialect, entry.common.base_dialect.value(),
common_parent, true);
common_parent, entry.common.property_name, true);
}
}

Expand Down Expand Up @@ -833,16 +839,22 @@ auto SchemaFrame::analyse(const JSON &root, const SchemaWalker &walker,
SchemaFrame::LocationType::Subschema, std::move(result),
base_view, pointer_weak, nearest_base_depth,
dialect_for_pointer, current_base_dialect,
subschema_it->second.parent, false, true);
subschema_it->second.parent,
subschema_it->second.property_name, false, true);
} else {
const auto &parent_pointer{combined.dialect_match.has_value()
? combined.dialect_match->second
: empty_weak_pointer};
const auto parent_subschema_it{subschemas.find(parent_pointer)};
const bool parent_property_name{
parent_subschema_it != subschemas.cend() &&
parent_subschema_it->second.property_name};

store(this->locations_, SchemaReferenceType::Static,
SchemaFrame::LocationType::Pointer, std::move(result),
base_view, pointer_weak, nearest_base_depth,
dialect_for_pointer, current_base_dialect,
combined.dialect_match.has_value()
? combined.dialect_match->second
: empty_weak_pointer,
false, true);
dialect_for_pointer, current_base_dialect, parent_pointer,
parent_property_name, false, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class SOURCEMETA_CORE_JSONSCHEMA_EXPORT SchemaFrame {
std::size_t relative_pointer;
std::string_view dialect;
SchemaBaseDialect base_dialect;
bool property_name;
};

/// A JSON Schema reference frame is a mapping of URIs to schema identifiers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ struct SchemaIteratorEntry {
std::optional<SchemaBaseDialect> base_dialect;
std::reference_wrapper<const JSON> subschema;
bool orphan;
bool property_name;
};

} // namespace sourcemeta::core
Expand Down
Loading