Blaze 0.0.1
The ultra high-performance JSON Schema evaluator
 
Loading...
Searching...
No Matches
Frame

A static analysis pass that maps URIs and pointers to subschemas. More...

Classes

class  sourcemeta::blaze::SchemaFrame
 
class  sourcemeta::blaze::SchemaFrameError
 
class  sourcemeta::blaze::SchemaAnchorCollisionError
 

Enumerations

enum class  sourcemeta::blaze::SchemaFrame::LocationType : std::uint8_t { Resource , Anchor , Pointer , Subschema }
 

Detailed Description

A static analysis pass that maps URIs and pointers to subschemas.

This functionality is included as follows:

#include <sourcemeta/blaze/frame.h>

Class Documentation

◆ sourcemeta::blaze::SchemaFrame

class sourcemeta::blaze::SchemaFrame

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};
frame.analyse(document,
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
Definition frame.h:70

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.
 

Member Typedef Documentation

◆ Locations

using sourcemeta::blaze::SchemaFrame::Locations = std::map<std::pair<SchemaReferenceType, sourcemeta::core::JSON::String>, Location>

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.

◆ References

using sourcemeta::blaze::SchemaFrame::References = std::map<std::pair<SchemaReferenceType, sourcemeta::core::WeakPointer>, ReferencesEntry>

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.

Member Enumeration Documentation

◆ Mode

enum class sourcemeta::blaze::SchemaFrame::Mode : std::uint8_t
strong

The mode of framing. More extensive analysis can be compute and memory intensive

Member Function Documentation

◆ analyse()

auto sourcemeta::blaze::SchemaFrame::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

Analyse a schema or set of schemas from a given root. Passing multiple paths that have any overlap is undefined behaviour

◆ for_each_unresolved_reference()

template<std::invocable< const sourcemeta::core::WeakPointer &, const ReferencesEntry & > F>
auto sourcemeta::blaze::SchemaFrame::for_each_unresolved_reference ( const F &  callback) const -> void
inline

Iterate over all unresolved references (where destination cannot be traversed)

◆ has_references_through()

auto sourcemeta::blaze::SchemaFrame::has_references_through ( const sourcemeta::core::WeakPointer &  pointer,
const sourcemeta::core::WeakPointer::Token &  tail 
) const -> bool

Check if there are any references that go through a given location pointer with a tail token

◆ sourcemeta::blaze::SchemaFrameError

class sourcemeta::blaze::SchemaFrameError

An error that represents a schema frame error

Inheritance diagram for sourcemeta::blaze::SchemaFrameError:

Public Member Functions

 SchemaFrameError (const std::string_view identifier, const char *message)
 
auto what () const noexcept -> const char *override
 
auto identifier () const noexcept -> std::string_view
 

◆ sourcemeta::blaze::SchemaAnchorCollisionError

class sourcemeta::blaze::SchemaAnchorCollisionError

An error that represents a schema anchor collision error

Inheritance diagram for sourcemeta::blaze::SchemaAnchorCollisionError:

Public Member Functions

 SchemaAnchorCollisionError (const std::string_view identifier, sourcemeta::core::Pointer location, sourcemeta::core::Pointer other)
 
auto what () const noexcept -> const char *override
 
auto identifier () const noexcept -> std::string_view
 
auto location () const noexcept -> const sourcemeta::core::Pointer &
 
auto other () const noexcept -> const sourcemeta::core::Pointer &
 

Enumeration Type Documentation

◆ LocationType

enum class sourcemeta::blaze::SchemaFrame::LocationType : std::uint8_t
strong

The type of a location frame