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:
#include <sourcemeta/core/json.h>
#include <sourcemeta/blaze/foundation.h>
#include <cassert>
const sourcemeta::core::JSON document =
sourcemeta::core::parse_json(R"JSON({
"$id": "https://www.example.com/schema",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"items": { "$id": "foo", "type": "string" },
"properties": {
"foo": { "$anchor": "test", "type": "number" },
"bar": { "$ref": "#/properties/foo" }
}
})JSON");
frame{sourcemeta::blaze::SchemaFrame::Mode::References};
SOURCEMETA_BLAZE_FOUNDATION_EXPORT auto schema_walker(const std::string_view keyword, const Vocabularies &vocabularies) -> const SchemaWalkerResult &
SOURCEMETA_BLAZE_FOUNDATION_EXPORT auto schema_resolver(const std::string_view identifier) -> std::optional< sourcemeta::core::JSON >
auto analyse(const sourcemeta::core::JSON &root, const SchemaWalker &walker, const SchemaResolver &resolver, std::string_view default_dialect="", std::string_view default_id="", const Paths &paths={sourcemeta::core::empty_weak_pointer}) -> void
Public Types |
| enum class | Mode : std::uint8_t { Locations
, References
} |
| |
| enum class | LocationType : std::uint8_t { Resource
, Anchor
, Pointer
, Subschema
} |
| |
| using | References = std::map< std::pair< SchemaReferenceType, sourcemeta::core::WeakPointer >, ReferencesEntry > |
| |
| using | Locations = std::map< std::pair< SchemaReferenceType, sourcemeta::core::JSON::String >, Location > |
| |
|
using | Paths = std::vector< sourcemeta::core::WeakPointer > |
| | A list of paths to frame within a schema wrapper.
|
| |
Public Member Functions |
|
| SchemaFrame (const Mode mode) |
| |
|
| SchemaFrame (const SchemaFrame &)=delete |
| |
|
auto | operator= (const SchemaFrame &) -> SchemaFrame &=delete |
| |
|
| SchemaFrame (SchemaFrame &&)=delete |
| |
|
auto | operator= (SchemaFrame &&) -> SchemaFrame &=delete |
| |
|
auto | mode () const noexcept -> Mode |
| |
|
auto | to_json (const std::optional< sourcemeta::core::PointerPositionTracker > &tracker=std::nullopt) const -> sourcemeta::core::JSON |
| | Export the frame entries as JSON.
|
| |
| auto | analyse (const sourcemeta::core::JSON &root, const SchemaWalker &walker, const SchemaResolver &resolver, std::string_view default_dialect="", std::string_view default_id="", const Paths &paths={sourcemeta::core::empty_weak_pointer}) -> void |
| |
|
auto | locations () const noexcept -> const Locations & |
| | Access the analysed schema locations.
|
| |
|
auto | references () const noexcept -> const References & |
| | Access the analysed schema references.
|
| |
|
auto | reference (const SchemaReferenceType type, const sourcemeta::core::WeakPointer &pointer) const -> std::optional< std::reference_wrapper< const ReferencesEntry > > |
| | Get a specific reference entry by type and pointer.
|
| |
|
auto | standalone () const noexcept -> bool |
| | Check whether the analysed schema has no external references.
|
| |
|
auto | root () const noexcept -> const sourcemeta::core::JSON::String & |
| | Get the root schema identifier (empty if none)
|
| |
|
auto | vocabularies (const Location &location, const SchemaResolver &resolver) const -> Vocabularies |
| | Get the vocabularies associated with a location entry.
|
| |
|
auto | uri (const Location &location, const sourcemeta::core::WeakPointer &relative_schema_location=sourcemeta::core::empty_weak_pointer) const -> sourcemeta::core::JSON::String |
| | Get the URI associated with a location entry.
|
| |
|
auto | traverse (const Location &location, const sourcemeta::core::WeakPointer &relative_schema_location) const -> const Location & |
| | Get the location associated by traversing a pointer from another location.
|
| |
|
auto | traverse (const std::string_view uri) const -> std::optional< std::reference_wrapper< const Location > > |
| | Get the location associated with a given URI.
|
| |
|
auto | traverse (const sourcemeta::core::WeakPointer &pointer) const -> std::optional< std::reference_wrapper< const Location > > |
| | Get the location associated with a given pointer.
|
| |
|
auto | traverse (const sourcemeta::core::WeakPointer &pointer, const LocationType type) const -> std::optional< std::reference_wrapper< const Location > > |
| | Get the location of a specific type associated with a given pointer.
|
| |
|
auto | uri (const sourcemeta::core::WeakPointer &pointer) const -> std::optional< std::reference_wrapper< const sourcemeta::core::JSON::String > > |
| | Turn an absolute pointer into a location URI.
|
| |
|
auto | dereference (const Location &location, const sourcemeta::core::WeakPointer &relative_schema_location=sourcemeta::core::empty_weak_pointer) const -> std::pair< SchemaReferenceType, std::optional< std::reference_wrapper< const Location > > > |
| | Try to dereference a reference location into its destination location.
|
| |
|
template<std::invocable< std::string_view > F> |
| auto | for_each_resource_uri (const F &callback) const -> void |
| | Iterate over all resource URIs in the frame.
|
| |
| template<std::invocable< const sourcemeta::core::WeakPointer &, const ReferencesEntry & > F> |
| auto | for_each_unresolved_reference (const F &callback) const -> void |
| |
|
auto | has_references_to (const sourcemeta::core::WeakPointer &pointer) const -> bool |
| | Check if there are any references to a given location pointer.
|
| |
|
auto | has_references_through (const sourcemeta::core::WeakPointer &pointer) const -> bool |
| | Check if there are any references that go through a given location pointer.
|
| |
| auto | has_references_through (const sourcemeta::core::WeakPointer &pointer, const sourcemeta::core::WeakPointer::Token &tail) const -> bool |
| |
|
auto | relative_instance_location (const Location &location) const -> sourcemeta::core::WeakPointer |
| | Get the relative instance location pointer for a given location entry.
|
| |
|
auto | empty () const noexcept -> bool |
| | Check if the frame has no analysed data.
|
| |
|
auto | reset () -> void |
| | Reset the frame, clearing all analysed data.
|
| |
|
auto | is_reachable (const Location &base, const Location &location, const SchemaWalker &walker, const SchemaResolver &resolver) const -> bool |
| | Determines if a location could be evaluated during validation.
|
| |