From 1a6da6d690f630010cdc6ef83e23aac1794deadf Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 2 Jan 2025 13:51:41 -0400 Subject: [PATCH] Turn schema framing into a class (#1417) Signed-off-by: Juan Cruz Viotti --- src/jsonschema/bundle.cc | 63 +-- src/jsonschema/frame.cc | 181 +++++-- .../sourcemeta/jsontoolkit/jsonschema_frame.h | 219 ++++---- .../jsontoolkit/jsonschema_unevaluated.h | 14 +- src/jsonschema/resolver.cc | 18 +- src/jsonschema/unevaluated.cc | 109 ++-- .../jsonschema_frame_2019_09_test.cc | 495 ++++++++---------- .../jsonschema_frame_2020_12_test.cc | 457 +++++++--------- .../jsonschema_frame_draft0_test.cc | 132 ++--- .../jsonschema_frame_draft1_test.cc | 132 ++--- .../jsonschema_frame_draft2_test.cc | 132 ++--- .../jsonschema_frame_draft3_test.cc | 150 +++--- .../jsonschema_frame_draft4_test.cc | 198 +++---- .../jsonschema_frame_draft6_test.cc | 198 +++---- .../jsonschema_frame_draft7_test.cc | 198 +++---- test/jsonschema/jsonschema_frame_test.cc | 244 +++------ test/jsonschema/jsonschema_test_utils.h | 128 +++-- .../jsonschema_unevaluated_2019_09_test.cc | 70 +-- .../jsonschema_unevaluated_2020_12_test.cc | 100 ++-- test/jsonschema/referencingsuite.cc | 10 +- 20 files changed, 1474 insertions(+), 1774 deletions(-) diff --git a/src/jsonschema/bundle.cc b/src/jsonschema/bundle.cc index 049d5b15e..5bc12878c 100644 --- a/src/jsonschema/bundle.cc +++ b/src/jsonschema/bundle.cc @@ -52,19 +52,14 @@ auto is_official_metaschema_reference( auto bundle_schema(sourcemeta::jsontoolkit::JSON &root, const std::string &container, const sourcemeta::jsontoolkit::JSON &subschema, - sourcemeta::jsontoolkit::FrameLocations &frame, - sourcemeta::jsontoolkit::FrameReferences &references, + sourcemeta::jsontoolkit::Frame &frame, const sourcemeta::jsontoolkit::SchemaWalker &walker, const sourcemeta::jsontoolkit::SchemaResolver &resolver, const std::optional &default_dialect) -> void { - sourcemeta::jsontoolkit::frame(subschema, frame, references, walker, resolver, - default_dialect); + frame.analyse(subschema, walker, resolver, default_dialect); - for (const auto &[key, reference] : references) { - if (frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, - reference.destination}) || - frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - reference.destination}) || + for (const auto &[key, reference] : frame.references()) { + if (frame.traverse(reference.destination).has_value() || // We don't want to bundle official schemas, as we can expect // virtually all implementations to understand them out of the box @@ -74,15 +69,11 @@ auto bundle_schema(sourcemeta::jsontoolkit::JSON &root, // If we can't find the destination but there is a base and we can // find base, then we are facing an unresolved fragment - if (reference.base.has_value()) { - if (frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, - reference.base.value()}) || - frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - reference.base.value()})) { - throw sourcemeta::jsontoolkit::SchemaReferenceError( - reference.destination, key.second, - "Could not resolve schema reference"); - } + if (reference.base.has_value() && + frame.traverse(reference.base.value()).has_value()) { + throw sourcemeta::jsontoolkit::SchemaReferenceError( + reference.destination, key.second, + "Could not resolve schema reference"); } root.assign_if_missing(container, @@ -98,10 +89,7 @@ auto bundle_schema(sourcemeta::jsontoolkit::JSON &root, const auto identifier{reference.base.value()}; const auto remote{resolver(identifier)}; if (!remote.has_value()) { - if (frame.contains( - {sourcemeta::jsontoolkit::ReferenceType::Static, identifier}) || - frame.contains( - {sourcemeta::jsontoolkit::ReferenceType::Dynamic, identifier})) { + if (frame.traverse(identifier).has_value()) { throw sourcemeta::jsontoolkit::SchemaReferenceError( reference.destination, key.second, "Could not resolve schema reference"); @@ -134,7 +122,7 @@ auto bundle_schema(sourcemeta::jsontoolkit::JSON &root, } embed_schema(root.at(container), identifier, copy); - bundle_schema(root, container, copy, frame, references, walker, resolver, + bundle_schema(root, container, copy, frame, walker, resolver, default_dialect); } } @@ -145,10 +133,8 @@ auto remove_identifiers(sourcemeta::jsontoolkit::JSON &schema, const std::optional &default_dialect) -> void { // (1) Re-frame before changing anything - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, walker, resolver, - default_dialect); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, walker, resolver, default_dialect); // (2) Remove all identifiers and anchors for (const auto &entry : sourcemeta::jsontoolkit::SchemaIterator{ @@ -175,28 +161,20 @@ auto remove_identifiers(sourcemeta::jsontoolkit::JSON &schema, } // (3) Fix-up reference based on pointers from the root - for (const auto &[key, reference] : references) { + for (const auto &[key, reference] : frame.references()) { // We don't want to bundle official schemas, as we can expect // virtually all implementations to understand them out of the box if (is_official_metaschema_reference(key.second, reference.destination)) { continue; } - assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, - reference.destination}) || - frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - reference.destination})); - const auto &entry{ - frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, - reference.destination}) - ? frame.at({sourcemeta::jsontoolkit::ReferenceType::Static, - reference.destination}) - : frame.at({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - reference.destination})}; + const auto result{frame.traverse(reference.destination)}; + assert(result.has_value()); sourcemeta::jsontoolkit::set( schema, key.second, sourcemeta::jsontoolkit::JSON{ - sourcemeta::jsontoolkit::to_uri(entry.pointer).recompose()}); + sourcemeta::jsontoolkit::to_uri(result.value().get().pointer) + .recompose()}); } } @@ -209,10 +187,9 @@ auto bundle(sourcemeta::jsontoolkit::JSON &schema, const SchemaWalker &walker, const std::optional &default_dialect) -> void { const auto vocabularies{ sourcemeta::jsontoolkit::vocabularies(schema, resolver, default_dialect)}; - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; + sourcemeta::jsontoolkit::Frame frame; bundle_schema(schema, definitions_keyword(vocabularies), schema, frame, - references, walker, resolver, default_dialect); + walker, resolver, default_dialect); if (options == BundleOptions::WithoutIdentifiers) { remove_identifiers(schema, walker, resolver, default_dialect); diff --git a/src/jsonschema/frame.cc b/src/jsonschema/frame.cc index 03dae46ff..774c7d723 100644 --- a/src/jsonschema/frame.cc +++ b/src/jsonschema/frame.cc @@ -91,9 +91,9 @@ static auto fragment_string(const sourcemeta::jsontoolkit::URI &uri) return std::nullopt; } -static auto store(sourcemeta::jsontoolkit::FrameLocations &frame, +static auto store(sourcemeta::jsontoolkit::Frame::Locations &frame, const sourcemeta::jsontoolkit::ReferenceType type, - const sourcemeta::jsontoolkit::FrameLocationType entry_type, + const sourcemeta::jsontoolkit::Frame::LocationType entry_type, const std::string &uri, const std::optional &root_id, const std::string &base_id, @@ -126,17 +126,15 @@ struct InternalEntry { const std::optional id; }; -// TODO: Revise this function, try to simplify it, and avoid redundant -// operations (like resolving schemas) by adding relevant overloads -// for the functions it consumes. -auto sourcemeta::jsontoolkit::frame( - const sourcemeta::jsontoolkit::JSON &schema, - sourcemeta::jsontoolkit::FrameLocations &frame, - sourcemeta::jsontoolkit::FrameReferences &references, - const sourcemeta::jsontoolkit::SchemaWalker &walker, - const sourcemeta::jsontoolkit::SchemaResolver &resolver, - const std::optional &default_dialect, - const std::optional &default_id) -> void { +auto internal_analyse(const sourcemeta::jsontoolkit::JSON &schema, + sourcemeta::jsontoolkit::Frame::Locations &frame, + sourcemeta::jsontoolkit::Frame::References &references, + const sourcemeta::jsontoolkit::SchemaWalker &walker, + const sourcemeta::jsontoolkit::SchemaResolver &resolver, + const std::optional &default_dialect, + const std::optional &default_id) -> void { + using namespace sourcemeta::jsontoolkit; + std::vector subschema_entries; std::set subschemas; std::map> @@ -163,7 +161,7 @@ auto sourcemeta::jsontoolkit::frame( default_id.has_value() && root_id.value() != default_id.value()}; if (has_explicit_different_id) { - store(frame, ReferenceType::Static, FrameLocationType::Resource, + store(frame, ReferenceType::Static, Frame::LocationType::Resource, default_id.value(), root_id.value(), root_id.value(), sourcemeta::jsontoolkit::empty_pointer, sourcemeta::jsontoolkit::empty_pointer, root_dialect.value(), @@ -227,7 +225,7 @@ auto sourcemeta::jsontoolkit::frame( if (!maybe_relative_is_absolute || !frame.contains({ReferenceType::Static, new_id})) { assert(entry.common.base_dialect.has_value()); - store(frame, ReferenceType::Static, FrameLocationType::Resource, + store(frame, ReferenceType::Static, Frame::LocationType::Resource, new_id, root_id, new_id, entry.common.pointer, sourcemeta::jsontoolkit::empty_pointer, entry.common.dialect.value(), @@ -259,9 +257,9 @@ auto sourcemeta::jsontoolkit::frame( assert(entry.common.value.defines("$schema")); references.insert_or_assign( {ReferenceType::Static, entry.common.pointer.concat({"$schema"})}, - FrameReferencesEntry{destination, - metaschema.recompose_without_fragment(), - fragment_string(metaschema)}); + Frame::ReferencesEntry{destination, + metaschema.recompose_without_fragment(), + fragment_string(metaschema)}); } // Handle schema anchors @@ -277,7 +275,7 @@ auto sourcemeta::jsontoolkit::frame( if (type == sourcemeta::jsontoolkit::AnchorType::Static || type == sourcemeta::jsontoolkit::AnchorType::All) { - store(frame, ReferenceType::Static, FrameLocationType::Anchor, + store(frame, ReferenceType::Static, Frame::LocationType::Anchor, relative_anchor_uri, root_id, "", entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), @@ -286,7 +284,7 @@ auto sourcemeta::jsontoolkit::frame( if (type == sourcemeta::jsontoolkit::AnchorType::Dynamic || type == sourcemeta::jsontoolkit::AnchorType::All) { - store(frame, ReferenceType::Dynamic, FrameLocationType::Anchor, + store(frame, ReferenceType::Dynamic, Frame::LocationType::Anchor, relative_anchor_uri, root_id, "", entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), @@ -295,7 +293,7 @@ auto sourcemeta::jsontoolkit::frame( // Register a dynamic anchor as a static anchor if possible too if (entry.common.vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/core")) { - store(frame, ReferenceType::Static, FrameLocationType::Anchor, + store(frame, ReferenceType::Static, Frame::LocationType::Anchor, relative_anchor_uri, root_id, "", entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), @@ -326,7 +324,7 @@ auto sourcemeta::jsontoolkit::frame( if (type == sourcemeta::jsontoolkit::AnchorType::Static || type == sourcemeta::jsontoolkit::AnchorType::All) { store(frame, sourcemeta::jsontoolkit::ReferenceType::Static, - FrameLocationType::Anchor, anchor_uri, root_id, base_string, + Frame::LocationType::Anchor, anchor_uri, root_id, base_string, entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), @@ -336,7 +334,7 @@ auto sourcemeta::jsontoolkit::frame( if (type == sourcemeta::jsontoolkit::AnchorType::Dynamic || type == sourcemeta::jsontoolkit::AnchorType::All) { store(frame, sourcemeta::jsontoolkit::ReferenceType::Dynamic, - FrameLocationType::Anchor, anchor_uri, root_id, base_string, + Frame::LocationType::Anchor, anchor_uri, root_id, base_string, entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), @@ -346,8 +344,8 @@ auto sourcemeta::jsontoolkit::frame( if (entry.common.vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/core")) { store(frame, sourcemeta::jsontoolkit::ReferenceType::Static, - FrameLocationType::Anchor, anchor_uri, root_id, base_string, - entry.common.pointer, + Frame::LocationType::Anchor, anchor_uri, root_id, + base_string, entry.common.pointer, entry.common.pointer.resolve_from(bases.second), entry.common.dialect.value(), entry.common.base_dialect.value(), true); @@ -396,12 +394,12 @@ auto sourcemeta::jsontoolkit::frame( ? root_base_dialect.value() : maybe_base_entry->second.base_dialect}; if (subschemas.contains(pointer)) { - store(frame, ReferenceType::Static, FrameLocationType::Subschema, + store(frame, ReferenceType::Static, Frame::LocationType::Subschema, result, root_id, current_base, pointer, pointer.resolve_from(nearest_bases.second), dialects.first.front(), current_base_dialect); } else { - store(frame, ReferenceType::Static, FrameLocationType::Pointer, + store(frame, ReferenceType::Static, Frame::LocationType::Pointer, result, root_id, current_base, pointer, pointer.resolve_from(nearest_bases.second), dialects.first.front(), current_base_dialect); @@ -426,9 +424,9 @@ auto sourcemeta::jsontoolkit::frame( ref.canonicalize(); references.insert_or_assign( {ReferenceType::Static, entry.common.pointer.concat({"$ref"})}, - FrameReferencesEntry{ref.recompose(), - ref.recompose_without_fragment(), - fragment_string(ref)}); + Frame::ReferencesEntry{ref.recompose(), + ref.recompose_without_fragment(), + fragment_string(ref)}); } if (entry.common.vocabularies.contains( @@ -458,9 +456,9 @@ auto sourcemeta::jsontoolkit::frame( std::move(anchor_uri_string)}; references.insert_or_assign( {reference_type, entry.common.pointer.concat({"$recursiveRef"})}, - FrameReferencesEntry{anchor_uri.recompose(), - anchor_uri.recompose_without_fragment(), - fragment_string(anchor_uri)}); + Frame::ReferencesEntry{anchor_uri.recompose(), + anchor_uri.recompose_without_fragment(), + fragment_string(anchor_uri)}); } if (entry.common.vocabularies.contains( @@ -492,9 +490,9 @@ auto sourcemeta::jsontoolkit::frame( references.insert_or_assign( {behaves_as_static ? ReferenceType::Static : ReferenceType::Dynamic, entry.common.pointer.concat({"$dynamicRef"})}, - FrameReferencesEntry{std::move(ref_string), - ref.recompose_without_fragment(), - fragment_string(ref)}); + Frame::ReferencesEntry{std::move(ref_string), + ref.recompose_without_fragment(), + fragment_string(ref)}); } } } @@ -518,7 +516,7 @@ auto sourcemeta::jsontoolkit::frame( std::map> dynamic_anchors; for (const auto &entry : frame) { if (entry.first.first != ReferenceType::Dynamic || - entry.second.type != FrameLocationType::Anchor) { + entry.second.type != Frame::LocationType::Anchor) { continue; } @@ -534,8 +532,8 @@ auto sourcemeta::jsontoolkit::frame( // If there is a dynamic reference that only has one possible // dynamic anchor destination, then that dynamic reference // is a static reference in disguise - std::vector to_delete; - std::vector to_insert; + std::vector to_delete; + std::vector to_insert; for (const auto &reference : references) { if (reference.first.first != ReferenceType::Dynamic || !reference.second.fragment.has_value()) { @@ -552,12 +550,13 @@ auto sourcemeta::jsontoolkit::frame( to_delete.push_back(reference.first); const URI new_destination{match->second.front()}; - to_insert.emplace_back(FrameReferences::key_type{ReferenceType::Static, - reference.first.second}, - FrameReferences::mapped_type{ - match->second.front(), - new_destination.recompose_without_fragment(), - fragment_string(new_destination)}); + to_insert.emplace_back( + Frame::References::key_type{ReferenceType::Static, + reference.first.second}, + Frame::References::mapped_type{ + match->second.front(), + new_destination.recompose_without_fragment(), + fragment_string(new_destination)}); } // Because we can't mutate a map as we are traversing it @@ -593,3 +592,95 @@ auto sourcemeta::jsontoolkit::frame( } } } + +namespace sourcemeta::jsontoolkit { + +auto Frame::analyse(const JSON &schema, const SchemaWalker &walker, + const SchemaResolver &resolver, + const std::optional &default_dialect, + const std::optional &default_id) -> void { + internal_analyse(schema, this->locations_, this->references_, walker, + resolver, default_dialect, default_id); +} + +auto Frame::locations() const noexcept -> const Locations & { + return this->locations_; +} + +auto Frame::references() const noexcept -> const References & { + return this->references_; +} + +auto Frame::vocabularies(const LocationsEntry &location, + const SchemaResolver &resolver) const + -> std::map { + return sourcemeta::jsontoolkit::vocabularies(resolver, location.base_dialect, + location.dialect); +} + +auto Frame::uri(const LocationsEntry &location, + const Pointer &relative_schema_location) const -> std::string { + return to_uri(location.relative_pointer.concat(relative_schema_location), + location.base) + .recompose(); +} + +auto Frame::traverse(const LocationsEntry &location, + const Pointer &relative_schema_location) const + -> const LocationsEntry & { + const auto new_uri{this->uri(location, relative_schema_location)}; + const auto static_match{ + this->locations_.find({ReferenceType::Static, new_uri})}; + if (static_match != this->locations_.cend()) { + return static_match->second; + } + + const auto dynamic_match{ + this->locations_.find({ReferenceType::Dynamic, new_uri})}; + assert(dynamic_match != this->locations_.cend()); + return dynamic_match->second; +} + +auto Frame::traverse(const std::string &uri) const + -> std::optional> { + const auto static_result{this->locations_.find({ReferenceType::Static, uri})}; + if (static_result != this->locations_.cend()) { + return static_result->second; + } + + const auto dynamic_result{ + this->locations_.find({ReferenceType::Dynamic, uri})}; + if (dynamic_result != this->locations_.cend()) { + return dynamic_result->second; + } + + return std::nullopt; +} + +auto Frame::dereference(const LocationsEntry &location, + const Pointer &relative_schema_location) const + -> std::pair>> { + const auto effective_location{ + location.pointer.concat({relative_schema_location})}; + const auto maybe_reference_entry{ + this->references_.find({ReferenceType::Static, effective_location})}; + if (maybe_reference_entry == this->references_.cend()) { + // If static dereferencing failed but we know the reference + // is dynamic, then report so, but without a location, as by + // definition we can't know the destination until at runtime + if (this->references_.contains( + {ReferenceType::Dynamic, effective_location})) { + return {ReferenceType::Dynamic, std::nullopt}; + } + + return {ReferenceType::Static, std::nullopt}; + } + + const auto destination{this->locations_.find( + {ReferenceType::Static, maybe_reference_entry->second.destination})}; + assert(destination != this->locations_.cend()); + return {ReferenceType::Static, destination->second}; +} + +} // namespace sourcemeta::jsontoolkit diff --git a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h index 175e41fc9..1efe6c4a5 100644 --- a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h +++ b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_frame.h @@ -21,67 +21,9 @@ namespace sourcemeta::jsontoolkit { -/// @ingroup jsonschema -/// A single entry in a JSON Schema reference map -struct FrameReferencesEntry { - std::string destination; - std::optional base; - std::optional fragment; -}; - -/// @ingroup jsonschema -/// A JSON Schema reference map is a mapping of a JSON Pointer -/// of a subschema to a destination static reference URI. -/// For convenience, the value consists of the URI on its entirety, -/// but also broken down by its potential fragment component. -/// The reference type is part of the key as it is possible to -/// have a static and a dynamic reference to the same location -/// on the same schema object. -using FrameReferences = - std::map, FrameReferencesEntry>; - -#if defined(__GNUC__) -#pragma GCC diagnostic push -// GCC believes that a member of an enum class (which is namespaced by -// definition), can shadow an alias defined even on a different namespace. -#pragma GCC diagnostic ignored "-Wshadow" -#endif -/// @ingroup jsonschema -/// The type of a location frame -enum class FrameLocationType : std::uint8_t { - Resource, - Anchor, - Pointer, - Subschema -}; -#if defined(__GNUC__) -#pragma GCC diagnostic pop -#endif - -/// @ingroup jsonschema -/// A single frame in a JSON Schema reference frame -struct FrameLocationsEntry { - FrameLocationType type; - std::optional root; - std::string base; - Pointer pointer; - Pointer relative_pointer; - std::string dialect; - std::string base_dialect; - std::vector> - destination_of; -}; - -/// @ingroup jsonschema -/// A JSON Schema reference frame is a mapping of URIs to schema identifiers, -/// JSON Pointers within the schema, and subschemas dialects. We call it -/// reference frame as this mapping is essential for resolving references. -using FrameLocations = - std::map, FrameLocationsEntry>; - /// @ingroup jsonschema /// -/// This function performs a static analysis pass on the input schema, computing +/// This class performs a static analysis pass on the input schema, computing /// things such as the static identifiers and references of a schema. /// /// For example: @@ -102,65 +44,166 @@ using FrameLocations = /// } /// })JSON"); /// -/// sourcemeta::jsontoolkit::FrameLocations frame; -/// sourcemeta::jsontoolkit::FrameReferences references; -/// sourcemeta::jsontoolkit::frame(document, frame, references, -/// sourcemeta::jsontoolkit::default_schema_walker, -/// sourcemeta::jsontoolkit::official_resolver); +/// sourcemeta::jsontoolkit::Frame frame; +/// frame.analyse(document, +/// sourcemeta::jsontoolkit::default_schema_walker, +/// sourcemeta::jsontoolkit::official_resolver); /// /// // IDs -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/foo"})); /// /// // Anchors -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#test"})); /// /// // Root Pointers -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/$id"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/$schema"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/items"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/items/$id"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/items/type"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties/foo"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties/foo/$anchor"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties/foo/type"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties/bar"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/schema#/properties/bar/$ref"})); /// /// // Subpointers -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/foo#/$id"})); -/// assert(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.locations().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// "https://www.example.com/foo#/type"})); /// /// // References -/// assert(references.contains({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.references().contains({sourcemeta::jsontoolkit::ReferenceType::Static, /// { "properties", "bar", "$ref" }})); -/// assert(references.at({sourcemeta::jsontoolkit::ReferenceType::Static, +/// assert(frame.references().at({sourcemeta::jsontoolkit::ReferenceType::Static, /// { "properties", "bar", "$ref" }}).destination == /// "https://www.example.com/schema#/properties/foo"); /// ``` -SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT -auto frame(const JSON &schema, FrameLocations &frame, - FrameReferences &references, const SchemaWalker &walker, - const SchemaResolver &resolver, - const std::optional &default_dialect = std::nullopt, - const std::optional &default_id = std::nullopt) -> void; +class SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT Frame { +public: + /// A single entry in a JSON Schema reference map + struct ReferencesEntry { + std::string destination; + std::optional base; + std::optional fragment; + }; + + /// A JSON Schema reference map is a mapping of a JSON Pointer + /// of a subschema to a destination static reference URI. + /// For convenience, the value consists of the URI on its entirety, + /// but also broken down by its potential fragment component. + /// The reference type is part of the key as it is possible to + /// have a static and a dynamic reference to the same location + /// on the same schema object. + using References = + std::map, ReferencesEntry>; + +#if defined(__GNUC__) +#pragma GCC diagnostic push +// GCC believes that a member of an enum class (which is namespaced by +// definition), can shadow an alias defined even on a different namespace. +#pragma GCC diagnostic ignored "-Wshadow" +#endif + /// @ingroup jsonschema + /// The type of a location frame + enum class LocationType : std::uint8_t { + Resource, + Anchor, + Pointer, + Subschema + }; +#if defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + + /// A single frame in a JSON Schema reference frame + struct LocationsEntry { + LocationType type; + std::optional root; + std::string base; + Pointer pointer; + Pointer relative_pointer; + std::string dialect; + std::string base_dialect; + std::vector> + destination_of; + }; + + /// A JSON Schema reference frame is a mapping of URIs to schema identifiers, + /// JSON Pointers within the schema, and subschemas dialects. We call it + /// reference frame as this mapping is essential for resolving references. + using Locations = + std::map, LocationsEntry>; + + /// Analyse a given schema + auto analyse(const JSON &schema, const SchemaWalker &walker, + const SchemaResolver &resolver, + const std::optional &default_dialect = std::nullopt, + const std::optional &default_id = std::nullopt) + -> void; + + /// Access the analysed schema locations + auto locations() const noexcept -> const Locations &; + + /// Access the analysed schema references + auto references() const noexcept -> const References &; + + /// Get the vocabularies associated with a location entry + auto vocabularies(const LocationsEntry &location, + const SchemaResolver &resolver) const + -> std::map; + + /// Get the URI associated with a location entry + auto uri(const LocationsEntry &location, + const Pointer &relative_schema_location = empty_pointer) const + -> std::string; + + /// Get the location associated by traversing a pointer from another location + auto traverse(const LocationsEntry &location, + const Pointer &relative_schema_location) const + -> const LocationsEntry &; + + /// Get the location associated with a given URI + auto traverse(const std::string &uri) const + -> std::optional>; + + /// Try to dereference a reference location into its destination location + auto + dereference(const LocationsEntry &location, + const Pointer &relative_schema_location = empty_pointer) const + -> std::pair>>; + +private: +// Exporting symbols that depends on the standard C++ library is considered +// safe. +// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-2-c4275?view=msvc-170&redirectedfrom=MSDN +#if defined(_MSC_VER) +#pragma warning(disable : 4251 4275) +#endif + Locations locations_; + References references_; +#if defined(_MSC_VER) +#pragma warning(default : 4251 4275) +#endif +}; } // namespace sourcemeta::jsontoolkit diff --git a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_unevaluated.h b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_unevaluated.h index 6e114d4f8..f63200cac 100644 --- a/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_unevaluated.h +++ b/src/jsonschema/include/sourcemeta/jsontoolkit/jsonschema_unevaluated.h @@ -54,13 +54,12 @@ using UnevaluatedEntries = std::map; /// "unevaluatedProperties": false /// })JSON"); /// -/// sourcemeta::jsontoolkit::FrameLocations frame; -/// sourcemeta::jsontoolkit::FrameReferences references; -/// sourcemeta::jsontoolkit::frame(document, frame, references, -/// sourcemeta::jsontoolkit::default_schema_walker, -/// sourcemeta::jsontoolkit::official_resolver); +/// sourcemeta::jsontoolkit::Frame frame; +/// frame.analyse(document, +/// sourcemeta::jsontoolkit::default_schema_walker, +/// sourcemeta::jsontoolkit::official_resolver); /// const auto result{sourcemeta::jsontoolkit::unevaluated( -/// schema, frame, references, +/// schema, frame, /// sourcemeta::jsontoolkit::default_schema_walker, /// sourcemeta::jsontoolkit::official_resolver)}; /// @@ -69,8 +68,7 @@ using UnevaluatedEntries = std::map; /// assert(result.at("#/unevaluatedProperties").dependencies.empty()); /// ``` auto SOURCEMETA_JSONTOOLKIT_JSONSCHEMA_EXPORT -unevaluated(const JSON &schema, const FrameLocations &frame, - const FrameReferences &references, const SchemaWalker &walker, +unevaluated(const JSON &schema, const Frame &frame, const SchemaWalker &walker, const SchemaResolver &resolver) -> UnevaluatedEntries; } // namespace sourcemeta::jsontoolkit diff --git a/src/jsonschema/resolver.cc b/src/jsonschema/resolver.cc index 0abd862fd..3e18a8bc7 100644 --- a/src/jsonschema/resolver.cc +++ b/src/jsonschema/resolver.cc @@ -19,23 +19,17 @@ auto MapSchemaResolver::add(const JSON &schema, // Registering the top-level schema is not enough. We need to check // and register every embedded schema resource too - FrameLocations entries; - FrameReferences references; - frame(schema, entries, references, default_schema_walker, *this, - default_dialect, default_id); + Frame frame; + frame.analyse(schema, default_schema_walker, *this, default_dialect, + default_id); - for (const auto &[key, entry] : entries) { - if (entry.type != FrameLocationType::Resource) { + for (const auto &[key, entry] : frame.locations()) { + if (entry.type != Frame::LocationType::Resource) { continue; } auto subschema{get(schema, entry.pointer)}; - // TODO: Set the base dialect in the frame entries - const auto subschema_base_dialect{ - base_dialect(subschema, *this, entry.dialect)}; - assert(subschema_base_dialect.has_value()); - const auto subschema_vocabularies{ - vocabularies(*this, subschema_base_dialect.value(), entry.dialect)}; + const auto subschema_vocabularies{frame.vocabularies(entry, *this)}; // Given we might be resolving embedded resources, we fully // resolve their dialect and identifiers, otherwise the diff --git a/src/jsonschema/unevaluated.cc b/src/jsonschema/unevaluated.cc index 02e4799f8..11cbdbc1c 100644 --- a/src/jsonschema/unevaluated.cc +++ b/src/jsonschema/unevaluated.cc @@ -7,28 +7,16 @@ namespace { using namespace sourcemeta::jsontoolkit; -// TODO: We need to do this dance in various places. If we turn -// `Frame` into a proper class, then this can be a utility method -auto navigate_frame(const FrameLocations &frame, - const FrameLocationsEntry &entry, - const Pointer &relative_pointer) - -> const FrameLocationsEntry & { - const auto new_uri{ - to_uri(entry.relative_pointer.concat(relative_pointer), entry.base) - .recompose()}; - assert(frame.contains({ReferenceType::Static, new_uri})); - return frame.at({ReferenceType::Static, new_uri}); -} - // TODO: Extract all of this into a public utility to traverse // adjacent subschemas -auto find_adjacent_dependencies( - const JSON::String ¤t, const JSON &schema, - const FrameLocations &frame, const FrameReferences &references, - const SchemaWalker &walker, const SchemaResolver &resolver, - const std::set &keywords, const FrameLocationsEntry &root, - const FrameLocationsEntry &entry, const bool is_static, - UnevaluatedEntry &result) -> void { +auto find_adjacent_dependencies(const JSON::String ¤t, const JSON &schema, + const Frame &frame, const SchemaWalker &walker, + const SchemaResolver &resolver, + const std::set &keywords, + const Frame::LocationsEntry &root, + const Frame::LocationsEntry &entry, + const bool is_static, UnevaluatedEntry &result) + -> void { const auto &subschema{get(schema, entry.pointer)}; if (!subschema.is_object()) { return; @@ -60,32 +48,27 @@ auto find_adjacent_dependencies( switch (walker(property.first, subschema_vocabularies).type) { // References - case KeywordType::Reference: - if (references.contains({ReferenceType::Static, - entry.pointer.concat({property.first})})) { - const auto &reference{references.at( - {ReferenceType::Static, entry.pointer.concat({property.first})})}; - assert( - frame.contains({ReferenceType::Static, reference.destination})); + case KeywordType::Reference: { + const auto reference{frame.dereference(entry, {property.first})}; + if (reference.first == ReferenceType::Static && + reference.second.has_value()) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, frame.at({ReferenceType::Static, reference.destination}), - is_static, result); - } else if (references.contains( - {ReferenceType::Dynamic, - entry.pointer.concat({property.first})})) { + current, schema, frame, walker, resolver, keywords, root, + reference.second.value().get(), is_static, result); + } else if (reference.first == ReferenceType::Dynamic) { result.unresolved = true; } break; + } // Static case KeywordType::ApplicatorElementsInline: for (std::size_t index = 0; index < property.second.size(); index++) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, navigate_frame(frame, entry, {property.first, index}), - is_static, result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first, index}), is_static, + result); } break; @@ -95,9 +78,8 @@ auto find_adjacent_dependencies( if (property.second.is_array()) { for (std::size_t index = 0; index < property.second.size(); index++) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, navigate_frame(frame, entry, {property.first, index}), - false, result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first, index}), false, result); } } @@ -105,9 +87,8 @@ auto find_adjacent_dependencies( case KeywordType::ApplicatorValueInPlace: if (is_schema(property.second)) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, navigate_frame(frame, entry, {property.first}), false, - result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first}), false, result); } break; @@ -115,15 +96,13 @@ auto find_adjacent_dependencies( if (property.second.is_array()) { for (std::size_t index = 0; index < property.second.size(); index++) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, navigate_frame(frame, entry, {property.first, index}), - false, result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first, index}), false, result); } } else if (is_schema(property.second)) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, navigate_frame(frame, entry, {property.first}), false, - result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first}), false, result); } break; @@ -131,10 +110,9 @@ auto find_adjacent_dependencies( if (property.second.is_object()) { for (const auto &pair : property.second.as_object()) { find_adjacent_dependencies( - current, schema, frame, references, walker, resolver, keywords, - root, - navigate_frame(frame, entry, {property.first, pair.first}), - false, result); + current, schema, frame, walker, resolver, keywords, root, + frame.traverse(entry, {property.first, pair.first}), false, + result); } } @@ -151,14 +129,14 @@ auto find_adjacent_dependencies( namespace sourcemeta::jsontoolkit { -auto unevaluated(const JSON &schema, const FrameLocations &frame, - const FrameReferences &references, const SchemaWalker &walker, - const SchemaResolver &resolver) -> UnevaluatedEntries { +auto unevaluated(const JSON &schema, const Frame &frame, + const SchemaWalker &walker, const SchemaResolver &resolver) + -> UnevaluatedEntries { UnevaluatedEntries result; - for (const auto &entry : frame) { - if (entry.second.type != FrameLocationType::Subschema && - entry.second.type != FrameLocationType::Resource) { + for (const auto &entry : frame.locations()) { + if (entry.second.type != Frame::LocationType::Subschema && + entry.second.type != Frame::LocationType::Resource) { continue; } @@ -169,12 +147,9 @@ auto unevaluated(const JSON &schema, const FrameLocations &frame, } const auto subschema_vocabularies{ - vocabularies(schema, resolver, entry.second.dialect)}; + frame.vocabularies(entry.second, resolver)}; for (const auto &pair : subschema.as_object()) { - const auto keyword_uri{ - to_uri(entry.second.relative_pointer.concat({pair.first}), - entry.second.base) - .recompose()}; + const auto keyword_uri{frame.uri(entry.second, {pair.first})}; UnevaluatedEntry unevaluated; if ((subschema_vocabularies.contains( "https://json-schema.org/draft/2020-12/vocab/unevaluated") && @@ -182,7 +157,7 @@ auto unevaluated(const JSON &schema, const FrameLocations &frame, "https://json-schema.org/draft/2020-12/vocab/applicator")) && pair.first == "unevaluatedProperties") { find_adjacent_dependencies( - pair.first, schema, frame, references, walker, resolver, + pair.first, schema, frame, walker, resolver, {"properties", "patternProperties", "additionalProperties", "unevaluatedProperties"}, entry.second, entry.second, true, unevaluated); @@ -194,7 +169,7 @@ auto unevaluated(const JSON &schema, const FrameLocations &frame, "https://json-schema.org/draft/2020-12/vocab/applicator")) && pair.first == "unevaluatedItems") { find_adjacent_dependencies( - pair.first, schema, frame, references, walker, resolver, + pair.first, schema, frame, walker, resolver, {"prefixItems", "items", "contains", "unevaluatedItems"}, entry.second, entry.second, true, unevaluated); result.emplace(keyword_uri, std::move(unevaluated)); @@ -203,7 +178,7 @@ auto unevaluated(const JSON &schema, const FrameLocations &frame, "applicator") && pair.first == "unevaluatedProperties") { find_adjacent_dependencies( - pair.first, schema, frame, references, walker, resolver, + pair.first, schema, frame, walker, resolver, {"properties", "patternProperties", "additionalProperties", "unevaluatedProperties"}, entry.second, entry.second, true, unevaluated); @@ -213,7 +188,7 @@ auto unevaluated(const JSON &schema, const FrameLocations &frame, "applicator") && pair.first == "unevaluatedItems") { find_adjacent_dependencies( - pair.first, schema, frame, references, walker, resolver, + pair.first, schema, frame, walker, resolver, {"items", "additionalItems", "unevaluatedItems"}, entry.second, entry.second, true, unevaluated); result.emplace(keyword_uri, std::move(unevaluated)); diff --git a/test/jsonschema/jsonschema_frame_2019_09_test.cc b/test/jsonschema/jsonschema_frame_2019_09_test.cc index fb103098c..6c877c17f 100644 --- a/test/jsonschema/jsonschema_frame_2019_09_test.cc +++ b/test/jsonschema/jsonschema_frame_2019_09_test.cc @@ -58,13 +58,11 @@ TEST(JSONSchema_frame_2019_09, anonymous_with_nested_schema_resource) { "additionalProperties": { "$id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -95,10 +93,10 @@ TEST(JSONSchema_frame_2019_09, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -109,13 +107,11 @@ TEST(JSONSchema_frame_2019_09, empty_schema) { "$schema": "https://json-schema.org/draft/2019-09/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -134,10 +130,10 @@ TEST(JSONSchema_frame_2019_09, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -152,13 +148,11 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -197,10 +191,10 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -215,13 +209,11 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_with_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 14); + EXPECT_EQ(frame.locations().size(), 14); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", @@ -289,10 +281,10 @@ TEST(JSONSchema_frame_2019_09, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -307,13 +299,11 @@ TEST(JSONSchema_frame_2019_09, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -356,10 +346,10 @@ TEST(JSONSchema_frame_2019_09, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -388,13 +378,11 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 30); + EXPECT_EQ(frame.locations().size(), 30); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -530,10 +518,10 @@ TEST(JSONSchema_frame_2019_09, nested_schemas) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -545,12 +533,10 @@ TEST(JSONSchema_frame_2019_09, id_override) { "items": { "$id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -563,12 +549,10 @@ TEST(JSONSchema_frame_2019_09, static_anchor_override) { "items": { "$anchor": "foo" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -579,15 +563,13 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_same) { "$schema": "https://json-schema.org/draft/2019-09/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "https://json-schema.org/draft/2019-09/schema", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "https://json-schema.org/draft/2019-09/schema", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -606,10 +588,10 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -621,13 +603,11 @@ TEST(JSONSchema_frame_2019_09, anchor_top_level) { "$anchor": "foo" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -655,10 +635,10 @@ TEST(JSONSchema_frame_2019_09, anchor_top_level) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -682,15 +662,13 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "https://json-schema.org/draft/2019-09/schema", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "https://json-schema.org/draft/2019-09/schema", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 38); + EXPECT_EQ(frame.locations().size(), 38); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -796,10 +774,10 @@ TEST(JSONSchema_frame_2019_09, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -810,13 +788,11 @@ TEST(JSONSchema_frame_2019_09, ref_metaschema) { "$ref": "https://json-schema.org/draft/2019-09/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", @@ -831,13 +807,13 @@ TEST(JSONSchema_frame_2019_09, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "https://json-schema.org/draft/2019-09/schema", + frame, "/$ref", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -855,13 +831,11 @@ TEST(JSONSchema_frame_2019_09, location_independent_identifier_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; + sourcemeta::jsontoolkit::Frame frame; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -873,13 +847,11 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_with_id) { "$recursiveAnchor": true })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); // Dynamic anchors @@ -912,10 +884,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_with_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -927,13 +899,11 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_with_id) { "$recursiveAnchor": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 4); + EXPECT_EQ(frame.locations().size(), 4); // Static identifiers @@ -959,10 +929,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_with_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -977,13 +947,11 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_without_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); // Dynamic anchors @@ -1017,10 +985,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_true_without_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -1035,13 +1003,11 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_without_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); // Static frames @@ -1068,10 +1034,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_false_without_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -1084,13 +1050,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 4); + EXPECT_EQ(frame.locations().size(), 4); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", @@ -1111,12 +1075,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/additionalItems/$recursiveRef", "", + EXPECT_STATIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "", std::nullopt, std::nullopt); } @@ -1130,13 +1094,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1162,12 +1124,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_no_recursive_anchor) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_STATIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); } @@ -1182,13 +1144,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", @@ -1213,12 +1173,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/additionalItems/$recursiveRef", "", + EXPECT_STATIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "", std::nullopt, std::nullopt); } @@ -1233,13 +1193,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1269,12 +1227,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_false) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_STATIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); } @@ -1289,13 +1247,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", @@ -1326,12 +1282,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/additionalItems/$recursiveRef", "", + EXPECT_DYNAMIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "", std::nullopt, std::nullopt); } @@ -1346,13 +1302,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1389,12 +1343,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_recursive_anchor_true) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); } @@ -1411,13 +1365,11 @@ TEST(JSONSchema_frame_2019_09, } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalItems", @@ -1467,12 +1419,12 @@ TEST(JSONSchema_frame_2019_09, // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_STATIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://example.com", "https://example.com", std::nullopt); } @@ -1489,13 +1441,11 @@ TEST(JSONSchema_frame_2019_09, } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 11); + EXPECT_EQ(frame.locations().size(), 11); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalItems", @@ -1552,12 +1502,12 @@ TEST(JSONSchema_frame_2019_09, // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://example.com", "https://example.com", std::nullopt); } @@ -1573,13 +1523,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_nested_recursive_anchor_true) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1618,12 +1566,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_nested_recursive_anchor_true) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); } @@ -1641,13 +1589,11 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_multiple_recursive_anchor_true) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 14); + EXPECT_EQ(frame.locations().size(), 14); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1714,12 +1660,12 @@ TEST(JSONSchema_frame_2019_09, recursive_ref_multiple_recursive_anchor_true) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/additionalItems/$recursiveRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/additionalItems/$recursiveRef", "https://www.sourcemeta.com/nested", "https://www.sourcemeta.com/nested", std::nullopt); } @@ -1735,12 +1681,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_conflict) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -1752,12 +1696,10 @@ TEST(JSONSchema_frame_2019_09, invalid_recursive_ref) { "$recursiveRef": "nested#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -1772,13 +1714,11 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_on_relative_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 11); + EXPECT_EQ(frame.locations().size(), 11); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2019-09/schema", @@ -1832,10 +1772,10 @@ TEST(JSONSchema_frame_2019_09, recursive_anchor_on_relative_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -1850,13 +1790,11 @@ TEST(JSONSchema_frame_2019_09, ref_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1892,12 +1830,12 @@ TEST(JSONSchema_frame_2019_09, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", + EXPECT_STATIC_REFERENCE(frame, "/$ref", "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string"); } @@ -1914,13 +1852,11 @@ TEST(JSONSchema_frame_2019_09, ref_from_definitions) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_2019_09_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1964,17 +1900,16 @@ TEST(JSONSchema_frame_2019_09, ref_from_definitions) { // References - EXPECT_EQ(references.size(), 3); + EXPECT_EQ(frame.references().size(), 3); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", - "https://www.sourcemeta.com/schema#/definitions/middle", + frame, "/$ref", "https://www.sourcemeta.com/schema#/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle"); EXPECT_STATIC_REFERENCE( - references, "/definitions/middle/$ref", + frame, "/definitions/middle/$ref", "https://www.sourcemeta.com/schema#/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string"); } @@ -1986,13 +1921,11 @@ TEST(JSONSchema_frame_2019_09, relative_base_uri_without_ref) { "$id": "common" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2019_09_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -2006,10 +1939,10 @@ TEST(JSONSchema_frame_2019_09, relative_base_uri_without_ref) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -2026,13 +1959,11 @@ TEST(JSONSchema_frame_2019_09, relative_base_uri_with_ref) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_FRAME_STATIC_2019_09_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -2065,11 +1996,11 @@ TEST(JSONSchema_frame_2019_09, relative_base_uri_with_ref) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/allOf/0/$ref", "common#foo", "common", + EXPECT_STATIC_REFERENCE(frame, "/allOf/0/$ref", "common#foo", "common", "foo"); } diff --git a/test/jsonschema/jsonschema_frame_2020_12_test.cc b/test/jsonschema/jsonschema_frame_2020_12_test.cc index e997f5907..0b6454081 100644 --- a/test/jsonschema/jsonschema_frame_2020_12_test.cc +++ b/test/jsonschema/jsonschema_frame_2020_12_test.cc @@ -58,13 +58,11 @@ TEST(JSONSchema_frame_2020_12, anonymous_with_nested_schema_resource) { "additionalProperties": { "$id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -95,10 +93,10 @@ TEST(JSONSchema_frame_2020_12, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -109,13 +107,11 @@ TEST(JSONSchema_frame_2020_12, empty_schema) { "$schema": "https://json-schema.org/draft/2020-12/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -134,10 +130,10 @@ TEST(JSONSchema_frame_2020_12, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -152,13 +148,11 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -197,10 +191,10 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -215,13 +209,11 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_with_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 14); + EXPECT_EQ(frame.locations().size(), 14); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -288,10 +280,10 @@ TEST(JSONSchema_frame_2020_12, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -306,13 +298,11 @@ TEST(JSONSchema_frame_2020_12, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -347,10 +337,10 @@ TEST(JSONSchema_frame_2020_12, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -379,13 +369,11 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 30); + EXPECT_EQ(frame.locations().size(), 30); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -521,10 +509,10 @@ TEST(JSONSchema_frame_2020_12, nested_schemas) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -536,12 +524,10 @@ TEST(JSONSchema_frame_2020_12, id_override) { "items": { "$id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -554,12 +540,10 @@ TEST(JSONSchema_frame_2020_12, static_anchor_override) { "items": { "$anchor": "foo" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -570,15 +554,13 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_same) { "$schema": "https://json-schema.org/draft/2020-12/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "https://json-schema.org/draft/2020-12/schema", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "https://json-schema.org/draft/2020-12/schema", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -597,10 +579,10 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -612,13 +594,11 @@ TEST(JSONSchema_frame_2020_12, anchor_top_level) { "$anchor": "foo" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -646,10 +626,10 @@ TEST(JSONSchema_frame_2020_12, anchor_top_level) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -673,15 +653,13 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "https://json-schema.org/draft/2020-12/schema", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "https://json-schema.org/draft/2020-12/schema", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 38); + EXPECT_EQ(frame.locations().size(), 38); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -787,10 +765,10 @@ TEST(JSONSchema_frame_2020_12, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -825,35 +803,33 @@ TEST(JSONSchema_frame_2020_12, dynamic_refs_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 7); + EXPECT_EQ(frame.references().size(), 7); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$dynamicRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$dynamicRef", "https://www.sourcemeta.com/schema#/properties/baz", "https://www.sourcemeta.com/schema", "/properties/baz"); - EXPECT_STATIC_REFERENCE(references, "/properties/qux/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/qux/$dynamicRef", "https://www.sourcemeta.com/test", "https://www.sourcemeta.com/test", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/anchor/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/anchor/$dynamicRef", "https://www.sourcemeta.com/schema#baz", "https://www.sourcemeta.com/schema", "baz"); - EXPECT_DYNAMIC_REFERENCE(references, "/properties/extra/$dynamicRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/properties/extra/$dynamicRef", "https://www.sourcemeta.com/schema#dynamic", "https://www.sourcemeta.com/schema", "dynamic"); - EXPECT_DYNAMIC_REFERENCE(references, "/properties/unknown/$dynamicRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/properties/unknown/$dynamicRef", "https://www.sourcemeta.com/foo#xxx", "https://www.sourcemeta.com/foo", "xxx"); } @@ -888,30 +864,28 @@ TEST(JSONSchema_frame_2020_12, dynamic_refs_with_no_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 7); + EXPECT_EQ(frame.references().size(), 7); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$dynamicRef", "", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$dynamicRef", "", std::nullopt, std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$dynamicRef", "#/properties/baz", std::nullopt, "/properties/baz"); - EXPECT_STATIC_REFERENCE(references, "/properties/qux/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/qux/$dynamicRef", "https://www.example.com", "https://www.example.com", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/anchor/$dynamicRef", "#baz", + EXPECT_STATIC_REFERENCE(frame, "/properties/anchor/$dynamicRef", "#baz", std::nullopt, "baz"); - EXPECT_DYNAMIC_REFERENCE(references, "/properties/extra/$dynamicRef", - "#dynamic", std::nullopt, "dynamic"); - EXPECT_DYNAMIC_REFERENCE(references, "/properties/unknown/$dynamicRef", + EXPECT_DYNAMIC_REFERENCE(frame, "/properties/extra/$dynamicRef", "#dynamic", + std::nullopt, "dynamic"); + EXPECT_DYNAMIC_REFERENCE(frame, "/properties/unknown/$dynamicRef", "https://www.example.com/foo#xxx", "https://www.example.com/foo", "xxx"); } @@ -931,15 +905,13 @@ TEST(JSONSchema_frame_2020_12, ref_to_dynamic_anchor) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$ref", "https://www.sourcemeta.com/schema#foo", "https://www.sourcemeta.com/schema", "foo"); } @@ -960,23 +932,21 @@ TEST(JSONSchema_frame_2020_12, different_dynamic_and_refs_in_same_object) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 3); + EXPECT_EQ(frame.references().size(), 3); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar"); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$dynamicRef", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); } @@ -997,23 +967,21 @@ TEST(JSONSchema_frame_2020_12, same_dynamic_and_refs_in_same_object) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 3); + EXPECT_EQ(frame.references().size(), 3); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar"); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$dynamicRef", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$dynamicRef", "https://www.sourcemeta.com/schema#/properties/bar", "https://www.sourcemeta.com/schema", "/properties/bar"); @@ -1037,13 +1005,11 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 21); + EXPECT_EQ(frame.locations().size(), 21); // Dynamic anchors @@ -1143,10 +1109,10 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_with_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -1161,13 +1127,11 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_without_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); // Dynamic anchors @@ -1205,10 +1169,10 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_without_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -1225,13 +1189,11 @@ TEST(JSONSchema_frame_2020_12, } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); // Dynamic anchors @@ -1272,13 +1234,12 @@ TEST(JSONSchema_frame_2020_12, // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$dynamicRef", "#test", std::nullopt, - "test"); + EXPECT_STATIC_REFERENCE(frame, "/$dynamicRef", "#test", std::nullopt, "test"); } TEST(JSONSchema_frame_2020_12, dynamic_ref_to_single_dynamic_anchor_external) { @@ -1296,13 +1257,11 @@ TEST(JSONSchema_frame_2020_12, dynamic_ref_to_single_dynamic_anchor_external) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); // Dynamic anchors @@ -1351,16 +1310,15 @@ TEST(JSONSchema_frame_2020_12, dynamic_ref_to_single_dynamic_anchor_external) { // References - EXPECT_EQ(references.size(), 3); + EXPECT_EQ(frame.references().size(), 3); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_DYNAMIC_REFERENCE(references, "/$dynamicRef", "#test", std::nullopt, + EXPECT_DYNAMIC_REFERENCE(frame, "/$dynamicRef", "#test", std::nullopt, "test"); - EXPECT_STATIC_REFERENCE(references, "/$defs/foo/$ref", - "https://sourcemeta.com", "https://sourcemeta.com", - std::nullopt); + EXPECT_STATIC_REFERENCE(frame, "/$defs/foo/$ref", "https://sourcemeta.com", + "https://sourcemeta.com", std::nullopt); } TEST(JSONSchema_frame_2020_12, dynamic_anchor_same_on_schema_resource) { @@ -1374,12 +1332,10 @@ TEST(JSONSchema_frame_2020_12, dynamic_anchor_same_on_schema_resource) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -1394,13 +1350,11 @@ TEST(JSONSchema_frame_2020_12, no_id_recursive_empty_pointer) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 5); + EXPECT_EQ(frame.locations().size(), 5); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", @@ -1424,12 +1378,12 @@ TEST(JSONSchema_frame_2020_12, no_id_recursive_empty_pointer) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", "", std::nullopt, + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "", std::nullopt, std::nullopt); } @@ -1440,13 +1394,11 @@ TEST(JSONSchema_frame_2020_12, ref_metaschema) { "$ref": "https://json-schema.org/draft/2020-12/schema" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "https://json-schema.org/draft/2020-12/schema", @@ -1461,13 +1413,13 @@ TEST(JSONSchema_frame_2020_12, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "https://json-schema.org/draft/2020-12/schema", + frame, "/$ref", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -1485,13 +1437,11 @@ TEST(JSONSchema_frame_2020_12, location_independent_identifier_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; + sourcemeta::jsontoolkit::Frame frame; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -1506,13 +1456,11 @@ TEST(JSONSchema_frame_2020_12, ref_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1548,12 +1496,12 @@ TEST(JSONSchema_frame_2020_12, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", + EXPECT_STATIC_REFERENCE(frame, "/$ref", "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string"); } @@ -1570,13 +1518,11 @@ TEST(JSONSchema_frame_2020_12, ref_from_definitions) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1620,17 +1566,16 @@ TEST(JSONSchema_frame_2020_12, ref_from_definitions) { // References - EXPECT_EQ(references.size(), 3); + EXPECT_EQ(frame.references().size(), 3); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", - "https://www.sourcemeta.com/schema#/definitions/middle", + frame, "/$ref", "https://www.sourcemeta.com/schema#/definitions/middle", "https://www.sourcemeta.com/schema", "/definitions/middle"); EXPECT_STATIC_REFERENCE( - references, "/definitions/middle/$ref", + frame, "/definitions/middle/$ref", "https://www.sourcemeta.com/schema#/definitions/string", "https://www.sourcemeta.com/schema", "/definitions/string"); } @@ -1642,13 +1587,11 @@ TEST(JSONSchema_frame_2020_12, relative_base_uri_without_ref) { "$id": "common" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_2020_12_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -1662,10 +1605,10 @@ TEST(JSONSchema_frame_2020_12, relative_base_uri_without_ref) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -1682,13 +1625,11 @@ TEST(JSONSchema_frame_2020_12, relative_base_uri_with_ref) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_FRAME_STATIC_2020_12_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -1721,12 +1662,12 @@ TEST(JSONSchema_frame_2020_12, relative_base_uri_with_ref) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/allOf/0/$ref", "common#foo", "common", + EXPECT_STATIC_REFERENCE(frame, "/allOf/0/$ref", "common#foo", "common", "foo"); } @@ -1741,20 +1682,16 @@ TEST(JSONSchema_frame_2020_12, idempotent_with_refs) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; + sourcemeta::jsontoolkit::Frame frame; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_FRAME_STATIC_2020_12_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -1786,12 +1723,12 @@ TEST(JSONSchema_frame_2020_12, idempotent_with_refs) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", + EXPECT_STATIC_REFERENCE(frame, "/$ref", "https://www.sourcemeta.com/schema#/$defs/string", "https://www.sourcemeta.com/schema", "/$defs/string"); } diff --git a/test/jsonschema/jsonschema_frame_draft0_test.cc b/test/jsonschema/jsonschema_frame_draft0_test.cc index e6da1939a..261441a5b 100644 --- a/test/jsonschema/jsonschema_frame_draft0_test.cc +++ b/test/jsonschema/jsonschema_frame_draft0_test.cc @@ -40,13 +40,11 @@ TEST(JSONSchema_frame_draft0, anonymous_with_nested_schema_resource) { "additionalProperties": { "id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -76,10 +74,10 @@ TEST(JSONSchema_frame_draft0, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -90,13 +88,11 @@ TEST(JSONSchema_frame_draft0, empty_schema) { "$schema": "http://json-schema.org/draft-00/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -115,10 +111,10 @@ TEST(JSONSchema_frame_draft0, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -133,13 +129,11 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -178,10 +172,10 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -193,13 +187,11 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_with_identifiers) { "items": { "id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -242,10 +234,10 @@ TEST(JSONSchema_frame_draft0, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -260,13 +252,11 @@ TEST(JSONSchema_frame_draft0, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -309,10 +299,10 @@ TEST(JSONSchema_frame_draft0, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -324,12 +314,10 @@ TEST(JSONSchema_frame_draft0, id_override) { "items": { "id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -340,15 +328,13 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-00/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-00/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-00/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -367,10 +353,10 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -389,15 +375,13 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-00/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-00/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT0_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -458,10 +442,10 @@ TEST(JSONSchema_frame_draft0, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } @@ -472,13 +456,11 @@ TEST(JSONSchema_frame_draft0, ref_metaschema) { "$ref": "http://json-schema.org/draft-00/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-00/schema#", @@ -492,12 +474,12 @@ TEST(JSONSchema_frame_draft0, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-00/schema", + frame, "/$schema", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-00/schema", + frame, "/$ref", "http://json-schema.org/draft-00/schema", "http://json-schema.org/draft-00/schema", std::nullopt); } diff --git a/test/jsonschema/jsonschema_frame_draft1_test.cc b/test/jsonschema/jsonschema_frame_draft1_test.cc index d86e170d8..450cb69c3 100644 --- a/test/jsonschema/jsonschema_frame_draft1_test.cc +++ b/test/jsonschema/jsonschema_frame_draft1_test.cc @@ -40,13 +40,11 @@ TEST(JSONSchema_frame_draft1, anonymous_with_nested_schema_resource) { "additionalProperties": { "id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -76,10 +74,10 @@ TEST(JSONSchema_frame_draft1, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -90,13 +88,11 @@ TEST(JSONSchema_frame_draft1, empty_schema) { "$schema": "http://json-schema.org/draft-01/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -115,10 +111,10 @@ TEST(JSONSchema_frame_draft1, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -133,13 +129,11 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -178,10 +172,10 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -193,13 +187,11 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_with_identifiers) { "items": { "id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -242,10 +234,10 @@ TEST(JSONSchema_frame_draft1, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -260,13 +252,11 @@ TEST(JSONSchema_frame_draft1, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -309,10 +299,10 @@ TEST(JSONSchema_frame_draft1, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -324,12 +314,10 @@ TEST(JSONSchema_frame_draft1, id_override) { "items": { "id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -340,15 +328,13 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-01/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-01/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-01/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -367,10 +353,10 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -389,15 +375,13 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-01/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-01/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT1_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -458,10 +442,10 @@ TEST(JSONSchema_frame_draft1, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } @@ -472,13 +456,11 @@ TEST(JSONSchema_frame_draft1, ref_metaschema) { "$ref": "http://json-schema.org/draft-01/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-01/schema#", @@ -492,12 +474,12 @@ TEST(JSONSchema_frame_draft1, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-01/schema", + frame, "/$schema", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-01/schema", + frame, "/$ref", "http://json-schema.org/draft-01/schema", "http://json-schema.org/draft-01/schema", std::nullopt); } diff --git a/test/jsonschema/jsonschema_frame_draft2_test.cc b/test/jsonschema/jsonschema_frame_draft2_test.cc index 56f0dc0c8..e57fac7a6 100644 --- a/test/jsonschema/jsonschema_frame_draft2_test.cc +++ b/test/jsonschema/jsonschema_frame_draft2_test.cc @@ -40,13 +40,11 @@ TEST(JSONSchema_frame_draft2, anonymous_with_nested_schema_resource) { "additionalProperties": { "id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -76,10 +74,10 @@ TEST(JSONSchema_frame_draft2, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -90,13 +88,11 @@ TEST(JSONSchema_frame_draft2, empty_schema) { "$schema": "http://json-schema.org/draft-02/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -115,10 +111,10 @@ TEST(JSONSchema_frame_draft2, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -133,13 +129,11 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -178,10 +172,10 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -193,13 +187,11 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_with_identifiers) { "items": { "id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -242,10 +234,10 @@ TEST(JSONSchema_frame_draft2, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -260,13 +252,11 @@ TEST(JSONSchema_frame_draft2, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -309,10 +299,10 @@ TEST(JSONSchema_frame_draft2, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -324,12 +314,10 @@ TEST(JSONSchema_frame_draft2, id_override) { "items": { "id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -340,15 +328,13 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-02/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-02/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-02/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -367,10 +353,10 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -389,15 +375,13 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-02/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-02/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT2_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -458,10 +442,10 @@ TEST(JSONSchema_frame_draft2, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } @@ -472,13 +456,11 @@ TEST(JSONSchema_frame_draft2, ref_metaschema) { "$ref": "http://json-schema.org/draft-02/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-02/schema#", @@ -492,12 +474,12 @@ TEST(JSONSchema_frame_draft2, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-02/schema", + frame, "/$schema", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-02/schema", + frame, "/$ref", "http://json-schema.org/draft-02/schema", "http://json-schema.org/draft-02/schema", std::nullopt); } diff --git a/test/jsonschema/jsonschema_frame_draft3_test.cc b/test/jsonschema/jsonschema_frame_draft3_test.cc index f8603f796..558f0010b 100644 --- a/test/jsonschema/jsonschema_frame_draft3_test.cc +++ b/test/jsonschema/jsonschema_frame_draft3_test.cc @@ -40,13 +40,11 @@ TEST(JSONSchema_frame_draft3, anonymous_with_nested_schema_resource) { "additionalProperties": { "id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -76,10 +74,10 @@ TEST(JSONSchema_frame_draft3, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -90,13 +88,11 @@ TEST(JSONSchema_frame_draft3, empty_schema) { "$schema": "http://json-schema.org/draft-03/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -115,10 +111,10 @@ TEST(JSONSchema_frame_draft3, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -133,13 +129,11 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -178,10 +172,10 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -193,13 +187,11 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_with_identifiers) { "items": { "id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -242,10 +234,10 @@ TEST(JSONSchema_frame_draft3, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -260,13 +252,11 @@ TEST(JSONSchema_frame_draft3, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -309,10 +299,10 @@ TEST(JSONSchema_frame_draft3, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -324,12 +314,10 @@ TEST(JSONSchema_frame_draft3, id_override) { "items": { "id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -340,15 +328,13 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-03/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-03/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-03/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -367,10 +353,10 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -389,15 +375,13 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-03/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-03/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT3_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -458,10 +442,10 @@ TEST(JSONSchema_frame_draft3, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -472,13 +456,11 @@ TEST(JSONSchema_frame_draft3, ref_metaschema) { "$ref": "http://json-schema.org/draft-03/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-03/schema#", @@ -492,13 +474,13 @@ TEST(JSONSchema_frame_draft3, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-03/schema", + frame, "/$ref", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); } @@ -510,13 +492,11 @@ TEST(JSONSchema_frame_draft3, ref_with_id) { "$ref": "#/definitions/string" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 4); + EXPECT_EQ(frame.locations().size(), 4); // JSON Pointers @@ -535,11 +515,11 @@ TEST(JSONSchema_frame_draft3, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-03/schema", + frame, "/$schema", "http://json-schema.org/draft-03/schema", "http://json-schema.org/draft-03/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", "#/definitions/string", - std::nullopt, "/definitions/string"); + EXPECT_STATIC_REFERENCE(frame, "/$ref", "#/definitions/string", std::nullopt, + "/definitions/string"); } diff --git a/test/jsonschema/jsonschema_frame_draft4_test.cc b/test/jsonschema/jsonschema_frame_draft4_test.cc index 5cbe16287..6e3d9d394 100644 --- a/test/jsonschema/jsonschema_frame_draft4_test.cc +++ b/test/jsonschema/jsonschema_frame_draft4_test.cc @@ -49,13 +49,11 @@ TEST(JSONSchema_frame_draft4, anonymous_with_nested_schema_resource) { "additionalProperties": { "id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -85,10 +83,10 @@ TEST(JSONSchema_frame_draft4, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -99,13 +97,11 @@ TEST(JSONSchema_frame_draft4, empty_schema) { "$schema": "http://json-schema.org/draft-04/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -124,10 +120,10 @@ TEST(JSONSchema_frame_draft4, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -142,13 +138,11 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -187,10 +181,10 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -202,13 +196,11 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_with_identifiers) { "items": { "id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -251,10 +243,10 @@ TEST(JSONSchema_frame_draft4, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -269,13 +261,11 @@ TEST(JSONSchema_frame_draft4, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -318,10 +308,10 @@ TEST(JSONSchema_frame_draft4, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -333,12 +323,10 @@ TEST(JSONSchema_frame_draft4, id_override) { "items": { "id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -349,15 +337,13 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-04/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-04/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-04/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -376,10 +362,10 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -398,15 +384,13 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-04/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-04/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -467,10 +451,10 @@ TEST(JSONSchema_frame_draft4, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -481,13 +465,11 @@ TEST(JSONSchema_frame_draft4, ref_metaschema) { "$ref": "http://json-schema.org/draft-04/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-04/schema#", @@ -501,13 +483,13 @@ TEST(JSONSchema_frame_draft4, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-04/schema", + frame, "/$ref", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -525,13 +507,11 @@ TEST(JSONSchema_frame_draft4, location_independent_identifier_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); // Pointers EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( @@ -573,13 +553,13 @@ TEST(JSONSchema_frame_draft4, location_independent_identifier_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/definitions/bar/$ref", "#foo", - std::nullopt, "foo"); + EXPECT_STATIC_REFERENCE(frame, "/definitions/bar/$ref", "#foo", std::nullopt, + "foo"); } TEST(JSONSchema_frame_draft4, ref_with_id) { @@ -593,13 +573,11 @@ TEST(JSONSchema_frame_draft4, ref_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); // JSON Pointers @@ -630,13 +608,13 @@ TEST(JSONSchema_frame_draft4, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", "#/definitions/string", - std::nullopt, "/definitions/string"); + EXPECT_STATIC_REFERENCE(frame, "/$ref", "#/definitions/string", std::nullopt, + "/definitions/string"); } TEST(JSONSchema_frame_draft4, relative_base_uri_without_ref) { @@ -646,13 +624,11 @@ TEST(JSONSchema_frame_draft4, relative_base_uri_without_ref) { "id": "common" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -666,10 +642,10 @@ TEST(JSONSchema_frame_draft4, relative_base_uri_without_ref) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); } @@ -686,13 +662,11 @@ TEST(JSONSchema_frame_draft4, relative_base_uri_with_ref) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_FRAME_STATIC_DRAFT4_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -727,11 +701,11 @@ TEST(JSONSchema_frame_draft4, relative_base_uri_with_ref) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-04/schema", + frame, "/$schema", "http://json-schema.org/draft-04/schema", "http://json-schema.org/draft-04/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/allOf/0/$ref", "common#foo", "common", + EXPECT_STATIC_REFERENCE(frame, "/allOf/0/$ref", "common#foo", "common", "foo"); } diff --git a/test/jsonschema/jsonschema_frame_draft6_test.cc b/test/jsonschema/jsonschema_frame_draft6_test.cc index 70121c8cc..15dfcf992 100644 --- a/test/jsonschema/jsonschema_frame_draft6_test.cc +++ b/test/jsonschema/jsonschema_frame_draft6_test.cc @@ -49,13 +49,11 @@ TEST(JSONSchema_frame_draft6, anonymous_with_nested_schema_resource) { "additionalProperties": { "$id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -85,10 +83,10 @@ TEST(JSONSchema_frame_draft6, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -99,13 +97,11 @@ TEST(JSONSchema_frame_draft6, empty_schema) { "$schema": "http://json-schema.org/draft-06/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -124,10 +120,10 @@ TEST(JSONSchema_frame_draft6, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -142,13 +138,11 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -187,10 +181,10 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -202,13 +196,11 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_with_identifiers) { "items": { "$id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -251,10 +243,10 @@ TEST(JSONSchema_frame_draft6, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -269,13 +261,11 @@ TEST(JSONSchema_frame_draft6, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -318,10 +308,10 @@ TEST(JSONSchema_frame_draft6, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -333,12 +323,10 @@ TEST(JSONSchema_frame_draft6, id_override) { "items": { "$id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -349,15 +337,13 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-06/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-06/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-06/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -376,10 +362,10 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -398,15 +384,13 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-06/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-06/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -467,10 +451,10 @@ TEST(JSONSchema_frame_draft6, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -481,13 +465,11 @@ TEST(JSONSchema_frame_draft6, ref_metaschema) { "$ref": "http://json-schema.org/draft-06/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-06/schema#", @@ -501,13 +483,13 @@ TEST(JSONSchema_frame_draft6, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-06/schema", + frame, "/$ref", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -525,13 +507,11 @@ TEST(JSONSchema_frame_draft6, location_independent_identifier_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); // Pointers EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( @@ -573,13 +553,13 @@ TEST(JSONSchema_frame_draft6, location_independent_identifier_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/definitions/bar/$ref", "#foo", - std::nullopt, "foo"); + EXPECT_STATIC_REFERENCE(frame, "/definitions/bar/$ref", "#foo", std::nullopt, + "foo"); } TEST(JSONSchema_frame_draft6, ref_with_id) { @@ -593,13 +573,11 @@ TEST(JSONSchema_frame_draft6, ref_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); // JSON Pointers @@ -630,13 +608,13 @@ TEST(JSONSchema_frame_draft6, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", "#/definitions/string", - std::nullopt, "/definitions/string"); + EXPECT_STATIC_REFERENCE(frame, "/$ref", "#/definitions/string", std::nullopt, + "/definitions/string"); } TEST(JSONSchema_frame_draft6, relative_base_uri_without_ref) { @@ -646,13 +624,11 @@ TEST(JSONSchema_frame_draft6, relative_base_uri_without_ref) { "$id": "common" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -666,10 +642,10 @@ TEST(JSONSchema_frame_draft6, relative_base_uri_without_ref) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); } @@ -686,13 +662,11 @@ TEST(JSONSchema_frame_draft6, relative_base_uri_with_ref) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_FRAME_STATIC_DRAFT6_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -727,11 +701,11 @@ TEST(JSONSchema_frame_draft6, relative_base_uri_with_ref) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-06/schema", + frame, "/$schema", "http://json-schema.org/draft-06/schema", "http://json-schema.org/draft-06/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/allOf/0/$ref", "common#foo", "common", + EXPECT_STATIC_REFERENCE(frame, "/allOf/0/$ref", "common#foo", "common", "foo"); } diff --git a/test/jsonschema/jsonschema_frame_draft7_test.cc b/test/jsonschema/jsonschema_frame_draft7_test.cc index 8c98e1042..9305f8a77 100644 --- a/test/jsonschema/jsonschema_frame_draft7_test.cc +++ b/test/jsonschema/jsonschema_frame_draft7_test.cc @@ -49,13 +49,11 @@ TEST(JSONSchema_frame_draft7, anonymous_with_nested_schema_resource) { "additionalProperties": { "$id": "https://example.com" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 6); + EXPECT_EQ(frame.locations().size(), 6); EXPECT_ANONYMOUS_FRAME_STATIC_RESOURCE( frame, "https://example.com", "/additionalProperties", @@ -85,10 +83,10 @@ TEST(JSONSchema_frame_draft7, anonymous_with_nested_schema_resource) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -99,13 +97,11 @@ TEST(JSONSchema_frame_draft7, empty_schema) { "$schema": "http://json-schema.org/draft-07/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -124,10 +120,10 @@ TEST(JSONSchema_frame_draft7, empty_schema) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -142,13 +138,11 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_without_identifiers) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -187,10 +181,10 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_without_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -202,13 +196,11 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_with_identifiers) { "items": { "$id": "../foo", "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/test/qux", "https://www.sourcemeta.com/test/qux", "", @@ -251,10 +243,10 @@ TEST(JSONSchema_frame_draft7, one_level_applicators_with_identifiers) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -269,13 +261,11 @@ TEST(JSONSchema_frame_draft7, subschema_absolute_identifier) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 9); + EXPECT_EQ(frame.locations().size(), 9); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -318,10 +308,10 @@ TEST(JSONSchema_frame_draft7, subschema_absolute_identifier) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -333,12 +323,10 @@ TEST(JSONSchema_frame_draft7, id_override) { "items": { "$id": "schema" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } @@ -349,15 +337,13 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_same) { "$schema": "http://json-schema.org/draft-07/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-07/schema#", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-07/schema#", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", @@ -376,10 +362,10 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_same) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -398,15 +384,13 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_different) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "http://json-schema.org/draft-07/schema#", - "https://www.example.com"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "http://json-schema.org/draft-07/schema#", + "https://www.example.com"); - EXPECT_EQ(frame.size(), 22); + EXPECT_EQ(frame.locations().size(), 22); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE( frame, "https://www.sourcemeta.com/schema", @@ -467,10 +451,10 @@ TEST(JSONSchema_frame_draft7, explicit_argument_id_different) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -481,13 +465,11 @@ TEST(JSONSchema_frame_draft7, ref_metaschema) { "$ref": "http://json-schema.org/draft-07/schema#" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( frame, "", "", "http://json-schema.org/draft-07/schema#", @@ -501,13 +483,13 @@ TEST(JSONSchema_frame_draft7, ref_metaschema) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); EXPECT_STATIC_REFERENCE( - references, "/$ref", "http://json-schema.org/draft-07/schema", + frame, "/$ref", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -525,13 +507,11 @@ TEST(JSONSchema_frame_draft7, location_independent_identifier_anonymous) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 8); + EXPECT_EQ(frame.locations().size(), 8); // Pointers EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( @@ -573,13 +553,13 @@ TEST(JSONSchema_frame_draft7, location_independent_identifier_anonymous) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/definitions/bar/$ref", "#foo", - std::nullopt, "foo"); + EXPECT_STATIC_REFERENCE(frame, "/definitions/bar/$ref", "#foo", std::nullopt, + "foo"); } TEST(JSONSchema_frame_draft7, ref_with_id) { @@ -593,13 +573,11 @@ TEST(JSONSchema_frame_draft7, ref_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 7); + EXPECT_EQ(frame.locations().size(), 7); // JSON Pointers @@ -630,13 +608,13 @@ TEST(JSONSchema_frame_draft7, ref_with_id) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$ref", "#/definitions/string", - std::nullopt, "/definitions/string"); + EXPECT_STATIC_REFERENCE(frame, "/$ref", "#/definitions/string", std::nullopt, + "/definitions/string"); } TEST(JSONSchema_frame_draft7, relative_base_uri_without_ref) { @@ -646,13 +624,11 @@ TEST(JSONSchema_frame_draft7, relative_base_uri_without_ref) { "$id": "common" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 3); + EXPECT_EQ(frame.locations().size(), 3); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -666,10 +642,10 @@ TEST(JSONSchema_frame_draft7, relative_base_uri_without_ref) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); } @@ -686,13 +662,11 @@ TEST(JSONSchema_frame_draft7, relative_base_uri_with_ref) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 10); + EXPECT_EQ(frame.locations().size(), 10); EXPECT_FRAME_STATIC_DRAFT7_RESOURCE(frame, "common", "common", "", "common", "", 0); @@ -727,11 +701,11 @@ TEST(JSONSchema_frame_draft7, relative_base_uri_with_ref) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "http://json-schema.org/draft-07/schema", + frame, "/$schema", "http://json-schema.org/draft-07/schema", "http://json-schema.org/draft-07/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/allOf/0/$ref", "common#foo", "common", + EXPECT_STATIC_REFERENCE(frame, "/allOf/0/$ref", "common#foo", "common", "foo"); } diff --git a/test/jsonschema/jsonschema_frame_test.cc b/test/jsonschema/jsonschema_frame_test.cc index 1a73bd08e..586d713cd 100644 --- a/test/jsonschema/jsonschema_frame_test.cc +++ b/test/jsonschema/jsonschema_frame_test.cc @@ -27,13 +27,11 @@ TEST(JSONSchema_frame, nested_schemas_mixing_dialects) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 21); + EXPECT_EQ(frame.locations().size(), 21); EXPECT_FRAME_STATIC_RESOURCE(frame, "https://www.sourcemeta.com/test", "https://www.sourcemeta.com/test", "", @@ -162,15 +160,14 @@ TEST(JSONSchema_frame, nested_schemas_mixing_dialects) { // References - EXPECT_EQ(references.size(), 2); + EXPECT_EQ(frame.references().size(), 2); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/$defs/foo/$schema", - "http://json-schema.org/draft-04/schema", - "http://json-schema.org/draft-04/schema", - std::nullopt); + EXPECT_STATIC_REFERENCE( + frame, "/$defs/foo/$schema", "http://json-schema.org/draft-04/schema", + "http://json-schema.org/draft-04/schema", std::nullopt); } TEST(JSONSchema_frame, no_id) { @@ -189,13 +186,11 @@ TEST(JSONSchema_frame, no_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 14); + EXPECT_EQ(frame.locations().size(), 14); // Top level @@ -264,10 +259,10 @@ TEST(JSONSchema_frame, no_id) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -278,15 +273,13 @@ TEST(JSONSchema_frame, no_id_with_default) { "items": { "type": "string" } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver, - "https://json-schema.org/draft/2020-12/schema", - "https://www.sourcemeta.com/schema"); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver, + "https://json-schema.org/draft/2020-12/schema", + "https://www.sourcemeta.com/schema"); - EXPECT_EQ(frame.size(), 4); + EXPECT_EQ(frame.locations().size(), 4); EXPECT_FRAME_STATIC_RESOURCE(frame, "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", "", "https://json-schema.org/draft/2020-12/schema", @@ -313,10 +306,10 @@ TEST(JSONSchema_frame, no_id_with_default) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -333,13 +326,11 @@ TEST(JSONSchema_frame, anchor_on_absolute_subid) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(frame.size(), 12); + EXPECT_EQ(frame.locations().size(), 12); EXPECT_FRAME_STATIC_RESOURCE(frame, "https://www.example.com", "https://www.example.com", "", "https://json-schema.org/draft/2020-12/schema", @@ -407,10 +398,10 @@ TEST(JSONSchema_frame, anchor_on_absolute_subid) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -426,18 +417,16 @@ TEST(JSONSchema_frame, uri_iterators) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); std::set uris; - for (const auto &entry : frame) { + for (const auto &entry : frame.locations()) { uris.insert(entry.first.second); } - EXPECT_EQ(frame.size(), 12); + EXPECT_EQ(frame.locations().size(), 12); EXPECT_EQ(uris.size(), 12); EXPECT_TRUE(uris.contains("https://www.sourcemeta.com/schema")); @@ -456,80 +445,13 @@ TEST(JSONSchema_frame, uri_iterators) { // References - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } -TEST(JSONSchema_frame, reference_frame_static) { - sourcemeta::jsontoolkit::FrameLocations frame; - frame.insert( - {{sourcemeta::jsontoolkit::ReferenceType::Static, "https://example.com"}, - {sourcemeta::jsontoolkit::FrameLocationType::Resource, - "https://example.com", - "https://example.com", - sourcemeta::jsontoolkit::empty_pointer, - sourcemeta::jsontoolkit::empty_pointer, - "https://json-schema.org/draft/2020-12/schema", - "https://json-schema.org/draft/2020-12/schema", - {}}}); - EXPECT_EQ(frame.size(), 1); - EXPECT_TRUE(frame.contains( - {sourcemeta::jsontoolkit::ReferenceType::Static, "https://example.com"})); - EXPECT_FALSE(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - "https://example.com"})); -} - -TEST(JSONSchema_frame, reference_frame_dynamic) { - sourcemeta::jsontoolkit::FrameLocations frame; - frame.insert( - {{sourcemeta::jsontoolkit::ReferenceType::Dynamic, "https://example.com"}, - {sourcemeta::jsontoolkit::FrameLocationType::Resource, - "https://example.com", - "https://example.com", - sourcemeta::jsontoolkit::empty_pointer, - sourcemeta::jsontoolkit::empty_pointer, - "https://json-schema.org/draft/2020-12/schema", - "https://json-schema.org/draft/2020-12/schema", - {}}}); - EXPECT_EQ(frame.size(), 1); - EXPECT_FALSE(frame.contains( - {sourcemeta::jsontoolkit::ReferenceType::Static, "https://example.com"})); - EXPECT_TRUE(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - "https://example.com"})); -} - -TEST(JSONSchema_frame, reference_frame_both) { - sourcemeta::jsontoolkit::FrameLocations frame; - frame.insert( - {{sourcemeta::jsontoolkit::ReferenceType::Static, "https://example.com"}, - {sourcemeta::jsontoolkit::FrameLocationType::Resource, - "https://example.com", - "https://example.com", - sourcemeta::jsontoolkit::empty_pointer, - sourcemeta::jsontoolkit::empty_pointer, - "https://json-schema.org/draft/2020-12/schema", - "https://json-schema.org/draft/2020-12/schema", - {}}}); - frame.insert( - {{sourcemeta::jsontoolkit::ReferenceType::Dynamic, "https://example.com"}, - {sourcemeta::jsontoolkit::FrameLocationType::Resource, - "https://example.com", - "https://example.com", - sourcemeta::jsontoolkit::empty_pointer, - sourcemeta::jsontoolkit::empty_pointer, - "https://json-schema.org/draft/2020-12/schema", - "https://json-schema.org/draft/2020-12/schema", - {}}}); - EXPECT_EQ(frame.size(), 2); - EXPECT_TRUE(frame.contains( - {sourcemeta::jsontoolkit::ReferenceType::Static, "https://example.com"})); - EXPECT_TRUE(frame.contains({sourcemeta::jsontoolkit::ReferenceType::Dynamic, - "https://example.com"})); -} - TEST(JSONSchema_frame, no_refs) { const sourcemeta::jsontoolkit::JSON document = sourcemeta::jsontoolkit::parse(R"JSON({ @@ -542,16 +464,14 @@ TEST(JSONSchema_frame, no_refs) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); } @@ -577,11 +497,9 @@ TEST(JSONSchema_frame, refs_with_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); EXPECT_FRAME_DESTINATION_OF(frame, Static, "https://www.sourcemeta.com/schema", 0, @@ -604,21 +522,21 @@ TEST(JSONSchema_frame, refs_with_id) { frame, Static, "https://www.sourcemeta.com/schema#/properties/qux", 0, "/properties/qux/$ref") - EXPECT_EQ(references.size(), 5); + EXPECT_EQ(frame.references().size(), 5); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "https://www.sourcemeta.com/schema", "https://www.sourcemeta.com/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$ref", "https://www.sourcemeta.com/schema#/properties/baz", "https://www.sourcemeta.com/schema", "/properties/baz"); - EXPECT_STATIC_REFERENCE(references, "/properties/qux/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/qux/$ref", "https://www.sourcemeta.com/test", "https://www.sourcemeta.com/test", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/anchor/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/anchor/$ref", "https://www.sourcemeta.com/schema#baz", "https://www.sourcemeta.com/schema", "baz"); } @@ -644,11 +562,9 @@ TEST(JSONSchema_frame, refs_with_no_id) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); EXPECT_FRAME_DESTINATION_OF(frame, Static, "", 0, "/properties/foo/$ref") EXPECT_FRAME_DESTINATION_OF(frame, Static, "#baz", 0, @@ -663,18 +579,18 @@ TEST(JSONSchema_frame, refs_with_no_id) { EXPECT_FRAME_DESTINATION_OF(frame, Static, "#/properties/qux", 0, "/properties/qux/$ref") - EXPECT_EQ(references.size(), 5); + EXPECT_EQ(frame.references().size(), 5); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", "", std::nullopt, + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "", std::nullopt, std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$ref", - "#/properties/baz", std::nullopt, "/properties/baz"); - EXPECT_STATIC_REFERENCE(references, "/properties/qux/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$ref", "#/properties/baz", + std::nullopt, "/properties/baz"); + EXPECT_STATIC_REFERENCE(frame, "/properties/qux/$ref", "https://www.example.com", "https://www.example.com", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/anchor/$ref", "#baz", + EXPECT_STATIC_REFERENCE(frame, "/properties/anchor/$ref", "#baz", std::nullopt, "baz"); } @@ -688,16 +604,14 @@ TEST(JSONSchema_frame, no_dynamic_ref_on_old_drafts) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 1); + EXPECT_EQ(frame.references().size(), 1); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2019-09/schema", + frame, "/$schema", "https://json-schema.org/draft/2019-09/schema", "https://json-schema.org/draft/2019-09/schema", std::nullopt); } @@ -712,23 +626,21 @@ TEST(JSONSchema_frame, remote_refs) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(document, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); - EXPECT_EQ(references.size(), 4); + EXPECT_EQ(frame.references().size(), 4); EXPECT_STATIC_REFERENCE( - references, "/$schema", "https://json-schema.org/draft/2020-12/schema", + frame, "/$schema", "https://json-schema.org/draft/2020-12/schema", "https://json-schema.org/draft/2020-12/schema", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/foo/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/foo/$ref", "https://www.example.com", "https://www.example.com", std::nullopt); - EXPECT_STATIC_REFERENCE(references, "/properties/bar/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/bar/$ref", "https://www.example.com/test#foo", "https://www.example.com/test", "foo"); - EXPECT_STATIC_REFERENCE(references, "/properties/baz/$ref", + EXPECT_STATIC_REFERENCE(frame, "/properties/baz/$ref", "https://www.example.com/x/y#/foo/bar", "https://www.example.com/x/y", "/foo/bar"); } @@ -739,11 +651,9 @@ TEST(JSONSchema_frame, no_dialect) { "type": "string" })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - EXPECT_THROW(sourcemeta::jsontoolkit::frame( - document, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver), + sourcemeta::jsontoolkit::Frame frame; + EXPECT_THROW(frame.analyse(document, + sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver), sourcemeta::jsontoolkit::SchemaError); } diff --git a/test/jsonschema/jsonschema_test_utils.h b/test/jsonschema/jsonschema_test_utils.h index 02d147836..5c0ba5fe0 100644 --- a/test/jsonschema/jsonschema_test_utils.h +++ b/test/jsonschema/jsonschema_test_utils.h @@ -12,20 +12,30 @@ expected_pointer, expected_dialect, \ expected_base_dialect, expected_base, \ expected_relative_pointer, expected_destination_of_size) \ - EXPECT_TRUE((frame).contains({(expected_type), (reference)})); \ - EXPECT_TRUE((frame).at({(expected_type), (reference)}).root.has_value()); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).root.value(), \ - (root_id)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).pointer, \ + EXPECT_TRUE((frame).locations().contains({(expected_type), (reference)})); \ + EXPECT_TRUE((frame) \ + .locations() \ + .at({(expected_type), (reference)}) \ + .root.has_value()); \ + EXPECT_EQ( \ + (frame).locations().at({(expected_type), (reference)}).root.value(), \ + (root_id)); \ + EXPECT_EQ((frame).locations().at({(expected_type), (reference)}).pointer, \ TO_POINTER(expected_pointer)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).dialect, \ + EXPECT_EQ((frame).locations().at({(expected_type), (reference)}).dialect, \ (expected_dialect)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).base, (expected_base)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).base_dialect, \ - (expected_base_dialect)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).relative_pointer, \ - TO_POINTER(expected_relative_pointer)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).destination_of.size(), \ + EXPECT_EQ((frame).locations().at({(expected_type), (reference)}).base, \ + (expected_base)); \ + EXPECT_EQ( \ + (frame).locations().at({(expected_type), (reference)}).base_dialect, \ + (expected_base_dialect)); \ + EXPECT_EQ( \ + (frame).locations().at({(expected_type), (reference)}).relative_pointer, \ + TO_POINTER(expected_relative_pointer)); \ + EXPECT_EQ((frame) \ + .locations() \ + .at({(expected_type), (reference)}) \ + .destination_of.size(), \ expected_destination_of_size); #define EXPECT_FRAME_STATIC(frame, reference, root_id, expected_pointer, \ @@ -46,9 +56,10 @@ expected_relative_pointer, expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Resource); + sourcemeta::jsontoolkit::Frame::LocationType::Resource); #define EXPECT_FRAME_STATIC_POINTER( \ frame, reference, root_id, expected_pointer, expected_dialect, \ @@ -59,9 +70,10 @@ expected_relative_pointer, expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Pointer); + sourcemeta::jsontoolkit::Frame::LocationType::Pointer); #define EXPECT_FRAME_STATIC_SUBSCHEMA( \ frame, reference, root_id, expected_pointer, expected_dialect, \ @@ -72,9 +84,10 @@ expected_relative_pointer, expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Subschema); + sourcemeta::jsontoolkit::Frame::LocationType::Subschema); #define EXPECT_FRAME_STATIC_ANCHOR( \ frame, reference, root_id, expected_pointer, expected_dialect, \ @@ -85,9 +98,10 @@ expected_relative_pointer, expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Anchor); + sourcemeta::jsontoolkit::Frame::LocationType::Anchor); #define EXPECT_FRAME_DYNAMIC_ANCHOR( \ frame, reference, root_id, expected_pointer, expected_dialect, \ @@ -99,9 +113,10 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Dynamic, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Anchor); + sourcemeta::jsontoolkit::Frame::LocationType::Anchor); #define EXPECT_FRAME_DYNAMIC(frame, reference, root_id, expected_pointer, \ expected_dialect, expected_base_dialect, \ @@ -115,15 +130,22 @@ #define __EXPECT_ANONYMOUS_FRAME( \ frame, expected_type, reference, expected_pointer, expected_dialect, \ expected_base_dialect, expected_destination_of_size) \ - EXPECT_TRUE((frame).contains({(expected_type), (reference)})); \ - EXPECT_FALSE((frame).at({(expected_type), (reference)}).root.has_value()); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).pointer, \ + EXPECT_TRUE((frame).locations().contains({(expected_type), (reference)})); \ + EXPECT_FALSE((frame) \ + .locations() \ + .at({(expected_type), (reference)}) \ + .root.has_value()); \ + EXPECT_EQ((frame).locations().at({(expected_type), (reference)}).pointer, \ TO_POINTER(expected_pointer)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).dialect, \ + EXPECT_EQ((frame).locations().at({(expected_type), (reference)}).dialect, \ (expected_dialect)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).base_dialect, \ - (expected_base_dialect)); \ - EXPECT_EQ((frame).at({(expected_type), (reference)}).destination_of.size(), \ + EXPECT_EQ( \ + (frame).locations().at({(expected_type), (reference)}).base_dialect, \ + (expected_base_dialect)); \ + EXPECT_EQ((frame) \ + .locations() \ + .at({(expected_type), (reference)}) \ + .destination_of.size(), \ (expected_destination_of_size)); #define EXPECT_ANONYMOUS_FRAME_STATIC(frame, reference, expected_pointer, \ @@ -143,9 +165,10 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Resource); + sourcemeta::jsontoolkit::Frame::LocationType::Resource); #define EXPECT_ANONYMOUS_FRAME_STATIC_POINTER( \ frame, reference, expected_pointer, expected_dialect, \ @@ -156,9 +179,10 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Pointer); + sourcemeta::jsontoolkit::Frame::LocationType::Pointer); #define EXPECT_ANONYMOUS_FRAME_STATIC_SUBSCHEMA( \ frame, reference, expected_pointer, expected_dialect, \ @@ -169,9 +193,10 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Subschema); + sourcemeta::jsontoolkit::Frame::LocationType::Subschema); #define EXPECT_ANONYMOUS_FRAME_STATIC_ANCHOR( \ frame, reference, expected_pointer, expected_dialect, \ @@ -182,9 +207,10 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Static, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Anchor); + sourcemeta::jsontoolkit::Frame::LocationType::Anchor); #define EXPECT_ANONYMOUS_FRAME_DYNAMIC_ANCHOR( \ frame, reference, expected_pointer, expected_dialect, \ @@ -195,47 +221,53 @@ expected_destination_of_size) \ EXPECT_EQ( \ (frame) \ + .locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::Dynamic, (reference)}) \ .type, \ - sourcemeta::jsontoolkit::FrameLocationType::Anchor); + sourcemeta::jsontoolkit::Frame::LocationType::Anchor); -#define EXPECT_REFERENCE(references, expected_type, expected_pointer, \ - expected_uri, expected_base, expected_fragment) \ - EXPECT_TRUE( \ - (references).contains({expected_type, TO_POINTER(expected_pointer)})); \ - EXPECT_EQ((references) \ +#define EXPECT_REFERENCE(frame, expected_type, expected_pointer, expected_uri, \ + expected_base, expected_fragment) \ + EXPECT_TRUE((frame).references().contains( \ + {expected_type, TO_POINTER(expected_pointer)})); \ + EXPECT_EQ((frame) \ + .references() \ .at({expected_type, TO_POINTER(expected_pointer)}) \ .destination, \ (expected_uri)); \ - EXPECT_EQ( \ - (references).at({expected_type, TO_POINTER(expected_pointer)}).base, \ - (expected_base)); \ - EXPECT_EQ( \ - (references).at({expected_type, TO_POINTER(expected_pointer)}).fragment, \ - (expected_fragment)); + EXPECT_EQ((frame) \ + .references() \ + .at({expected_type, TO_POINTER(expected_pointer)}) \ + .base, \ + (expected_base)); \ + EXPECT_EQ((frame) \ + .references() \ + .at({expected_type, TO_POINTER(expected_pointer)}) \ + .fragment, \ + (expected_fragment)); -#define EXPECT_STATIC_REFERENCE(references, expected_pointer, expected_uri, \ +#define EXPECT_STATIC_REFERENCE(frame, expected_pointer, expected_uri, \ expected_base, expected_fragment) \ - EXPECT_REFERENCE(references, sourcemeta::jsontoolkit::ReferenceType::Static, \ + EXPECT_REFERENCE(frame, sourcemeta::jsontoolkit::ReferenceType::Static, \ expected_pointer, expected_uri, expected_base, \ expected_fragment) -#define EXPECT_DYNAMIC_REFERENCE(references, expected_pointer, expected_uri, \ +#define EXPECT_DYNAMIC_REFERENCE(frame, expected_pointer, expected_uri, \ expected_base, expected_fragment) \ - EXPECT_REFERENCE( \ - references, sourcemeta::jsontoolkit::ReferenceType::Dynamic, \ - expected_pointer, expected_uri, expected_base, expected_fragment) + EXPECT_REFERENCE(frame, sourcemeta::jsontoolkit::ReferenceType::Dynamic, \ + expected_pointer, expected_uri, expected_base, \ + expected_fragment) #define EXPECT_FRAME_DESTINATION_OF(frame, expected_type, expected_uri, \ expected_index, expected_origin) \ - EXPECT_EQ(frame \ + EXPECT_EQ(frame.locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::expected_type, \ expected_uri}) \ .destination_of.at(expected_index) \ .get() \ .first, \ sourcemeta::jsontoolkit::ReferenceType::Static); \ - EXPECT_EQ(frame \ + EXPECT_EQ(frame.locations() \ .at({sourcemeta::jsontoolkit::ReferenceType::expected_type, \ expected_uri}) \ .destination_of.at(expected_index) \ diff --git a/test/jsonschema/jsonschema_unevaluated_2019_09_test.cc b/test/jsonschema/jsonschema_unevaluated_2019_09_test.cc index 29902c2db..5009436bb 100644 --- a/test/jsonschema/jsonschema_unevaluated_2019_09_test.cc +++ b/test/jsonschema/jsonschema_unevaluated_2019_09_test.cc @@ -15,13 +15,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedProperties_1) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -49,13 +47,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedProperties_2) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -99,13 +95,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedProperties_3) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -140,13 +134,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedProperties_4) { ] })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -173,13 +165,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedItems_1) { "unevaluatedItems": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -210,13 +200,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedItems_2) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -237,13 +225,11 @@ TEST(JSONSchema_unevaluated_2019_09, unevaluatedItems_3) { "unevaluatedItems": {"type": "string"} })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); diff --git a/test/jsonschema/jsonschema_unevaluated_2020_12_test.cc b/test/jsonschema/jsonschema_unevaluated_2020_12_test.cc index c3b2624dc..33abadd67 100644 --- a/test/jsonschema/jsonschema_unevaluated_2020_12_test.cc +++ b/test/jsonschema/jsonschema_unevaluated_2020_12_test.cc @@ -15,13 +15,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_1) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -49,13 +47,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_2) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -86,13 +82,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_3) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -126,13 +120,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_4) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -160,13 +152,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_5) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 2); @@ -190,13 +180,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_6) { "unevaluatedProperties": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 2); @@ -231,13 +219,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_7) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -274,13 +260,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedProperties_8) { } })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -302,13 +286,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedItems_1) { "unevaluatedItems": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 1); @@ -332,13 +314,11 @@ TEST(JSONSchema_unevaluated_2020_12, unevaluatedItems_2) { "unevaluatedItems": false })JSON"); - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame(schema, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, - sourcemeta::jsontoolkit::official_resolver); + sourcemeta::jsontoolkit::Frame frame; + frame.analyse(schema, sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::official_resolver); const auto result{sourcemeta::jsontoolkit::unevaluated( - schema, frame, references, sourcemeta::jsontoolkit::default_schema_walker, + schema, frame, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver)}; EXPECT_EQ(result.size(), 2); diff --git a/test/jsonschema/referencingsuite.cc b/test/jsonschema/referencingsuite.cc index 4eabaf1c9..a8171607f 100644 --- a/test/jsonschema/referencingsuite.cc +++ b/test/jsonschema/referencingsuite.cc @@ -49,13 +49,11 @@ class ReferencingTest : public testing::Test { std::map> new_entries; for (const auto &[uri, schema] : this->registry) { - sourcemeta::jsontoolkit::FrameLocations frame; - sourcemeta::jsontoolkit::FrameReferences references; - sourcemeta::jsontoolkit::frame( - schema.first, frame, references, - sourcemeta::jsontoolkit::default_schema_walker, + sourcemeta::jsontoolkit::Frame frame; + frame.analyse( + schema.first, sourcemeta::jsontoolkit::default_schema_walker, sourcemeta::jsontoolkit::official_resolver, this->dialect, uri); - for (const auto &[key, entry] : frame) { + for (const auto &[key, entry] : frame.locations()) { new_entries.insert( {key.second, {sourcemeta::jsontoolkit::get(schema.first, entry.pointer),