A growing collection of JSON Schema transformation rules. More...
Enumerations | |
| enum class | sourcemeta::blaze::AlterSchemaMode : std::uint8_t { AlterSchemaMode::Linter } |
Functions | |
| SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT auto | sourcemeta::blaze::add (SchemaTransformer &bundle, const AlterSchemaMode mode) -> void |
| SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT auto | sourcemeta::blaze::wrap (const sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaFrame::Location &location, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, sourcemeta::core::WeakPointer &base) -> sourcemeta::core::JSON |
A growing collection of JSON Schema transformation rules.
This functionality is included as follows:
| class sourcemeta::blaze::SchemaRule |
A linter rule driven by a JSON Schema. By default, every subschema in the document under inspection is validated as a JSON instance against the provided rule schema, though a rule may be scoped to only run against the document root. When a subschema does not conform, the rule fires and reports the validation errors. The rule name is extracted from the title keyword of the rule schema, and the rule description from the description keyword. The title must consist only of lowercase ASCII letters, digits, underscores, or slashes.
Public Types | |
| enum class | Scope : std::uint8_t { All , TopLevel } |
| The locations of the schema that the rule applies to. More... | |
| using | mutates = std::false_type |
| using | reframe_after_transform = std::false_type |
Public Member Functions | |
| SchemaRule (const sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Compiler &compiler, const std::string_view default_dialect="", const std::optional< Tweaks > &tweaks=std::nullopt, const Scope scope=Scope::All) | |
| auto | condition (const sourcemeta::core::JSON &, const sourcemeta::core::JSON &, const sourcemeta::core::SchemaVocabularies &, const sourcemeta::core::SchemaFrame &, const sourcemeta::core::SchemaFrame::Location &, const sourcemeta::core::SchemaWalker &, const sourcemeta::core::SchemaResolver &) const -> SchemaTransformRule::Result override |
| Public Member Functions inherited from sourcemeta::blaze::SchemaTransformRule | |
| SchemaTransformRule (const std::string_view name, const std::string_view message) | |
| SchemaTransformRule (const SchemaTransformRule &)=delete | |
| SchemaTransformRule (SchemaTransformRule &&)=delete | |
| auto | operator= (const SchemaTransformRule &) -> SchemaTransformRule &=delete |
| auto | operator= (SchemaTransformRule &&) -> SchemaTransformRule &=delete |
| auto | operator== (const SchemaTransformRule &other) const -> bool |
| Compare a rule against another rule. | |
| auto | name () const noexcept -> std::string_view |
| Fetch the name of a rule. | |
| auto | message () const noexcept -> std::string_view |
| Fetch the message of a rule. | |
| auto | check (const sourcemeta::core::JSON &schema, const sourcemeta::core::JSON &root, const sourcemeta::core::SchemaVocabularies &vocabularies, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaFrame::Location &location, const sourcemeta::core::JSON::String &exclude_keyword) const -> Result |
| Check if the rule applies to a schema. | |
| virtual auto | rereference (const std::string_view reference, const sourcemeta::core::Pointer &origin, const sourcemeta::core::Pointer &target, const sourcemeta::core::Pointer ¤t) const -> sourcemeta::core::Pointer |
| virtual auto | condition (const sourcemeta::core::JSON &schema, const sourcemeta::core::JSON &root, const sourcemeta::core::SchemaVocabularies &vocabularies, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaFrame::Location &location, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver) const -> Result=0 |
| The rule condition. | |
| virtual auto | transform (sourcemeta::core::JSON &schema, const Result &result) const -> void |
|
strong |
| class sourcemeta::blaze::SchemaRuleMissingNameError |
| class sourcemeta::blaze::SchemaRuleInvalidNameError |
An error that represents an invalid schema rule name. The name must consist only of lowercase ASCII letters, digits, underscores, or slashes.
| class sourcemeta::blaze::SchemaRuleInvalidNamePatternError |
An error that represents a schema rule name that does not match the required pattern
| class sourcemeta::blaze::SchemaAbortError |
An error that represents that a schema operation cannot continue
| class sourcemeta::blaze::SchemaBrokenReferenceError |
An error that represents a broken schema reference after transformation
| class sourcemeta::blaze::SchemaTransformRuleProcessedTwiceError |
An error that signifies that a transform rule was applied more than once
| class sourcemeta::blaze::SchemaTransformRule |
A class that represents a transformation rule. Clients of this class are expected to subclass and implement their own condition and transformation methods.
Public Member Functions | |
| SchemaTransformRule (const std::string_view name, const std::string_view message) | |
| SchemaTransformRule (const SchemaTransformRule &)=delete | |
| SchemaTransformRule (SchemaTransformRule &&)=delete | |
| auto | operator= (const SchemaTransformRule &) -> SchemaTransformRule &=delete |
| auto | operator= (SchemaTransformRule &&) -> SchemaTransformRule &=delete |
| auto | operator== (const SchemaTransformRule &other) const -> bool |
| Compare a rule against another rule. | |
| auto | name () const noexcept -> std::string_view |
| Fetch the name of a rule. | |
| auto | message () const noexcept -> std::string_view |
| Fetch the message of a rule. | |
| auto | check (const sourcemeta::core::JSON &schema, const sourcemeta::core::JSON &root, const sourcemeta::core::SchemaVocabularies &vocabularies, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaFrame::Location &location, const sourcemeta::core::JSON::String &exclude_keyword) const -> Result |
| Check if the rule applies to a schema. | |
| virtual auto | rereference (const std::string_view reference, const sourcemeta::core::Pointer &origin, const sourcemeta::core::Pointer &target, const sourcemeta::core::Pointer ¤t) const -> sourcemeta::core::Pointer |
| virtual auto | condition (const sourcemeta::core::JSON &schema, const sourcemeta::core::JSON &root, const sourcemeta::core::SchemaVocabularies &vocabularies, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaFrame::Location &location, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver) const -> Result=0 |
| The rule condition. | |
| virtual auto | transform (sourcemeta::core::JSON &schema, const Result &result) const -> void |
|
nodiscardvirtual |
A method to optionally fix any reference location that was affected by the transformation
|
virtual |
The rule transformation. If this virtual method is not overriden, then the rule is considered to not mutate the schema
| class sourcemeta::blaze::SchemaTransformer |
You can use this class to perform top-down transformations on subschemas given a set of rules. Every registered rule is applied to every subschema of the passed schema until no longer of them applies.
Public Types | |
| using | Callback |
| The callback that is called whenever the condition of a rule holds true. | |
| using | Framer |
Public Member Functions | |
| template<std::derived_from< SchemaTransformRule > T, typename... Args> | |
| auto | add (Args &&...args) -> std::string_view |
| auto | remove (const std::string_view name) -> bool |
| Remove a rule from the bundle. | |
| auto | apply (sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Callback &callback, std::string_view default_dialect="", std::string_view default_id="", const sourcemeta::core::JSON::String &exclude_keyword="") const -> std::pair< bool, std::uint8_t > |
| Apply the bundle of rules to a schema. | |
| auto | apply (sourcemeta::core::JSON &document, const Framer &framer, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Callback &callback, const sourcemeta::core::JSON::String &exclude_keyword="") const -> std::pair< bool, std::uint8_t > |
| auto | check (const sourcemeta::core::JSON &schema, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Callback &callback, std::string_view default_dialect="", std::string_view default_id="", const sourcemeta::core::JSON::String &exclude_keyword="") const -> std::pair< bool, std::uint8_t > |
| auto | check (const sourcemeta::core::JSON &document, const sourcemeta::core::SchemaFrame &frame, const sourcemeta::core::SchemaWalker &walker, const sourcemeta::core::SchemaResolver &resolver, const Callback &callback, const sourcemeta::core::JSON::String &exclude_keyword="") const -> std::pair< bool, std::uint8_t > |
| auto | begin () const -> auto |
| auto | end () const -> auto |
The callback that is called whenever the condition of a rule holds true.
Frame a document as it currently stands, in References mode. Applying rules calls it again whenever a transformation needs a new frame, so the frame it returns only has to remain valid until the next call
|
inline |
Add a rule to the bundle. Rules are evaluated in the order they are added. It is the caller's responsibility to not add duplicate rules.
|
nodiscard |
Apply the bundle of rules to every subschema that a framer locates within a document
|
nodiscard |
Report back the rules from the bundle that need to be applied to every subschema that a frame locates within a document
|
nodiscard |
Report back the rules from the bundle that need to be applied to a schema
|
strong |
| SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT auto sourcemeta::blaze::add | ( | SchemaTransformer & | bundle, |
| const AlterSchemaMode | mode )->void |
Add a set of built-in schema transformation rules given a category. For example:
| SOURCEMETA_BLAZE_ALTERSCHEMA_EXPORT auto sourcemeta::blaze::wrap | ( | const sourcemeta::core::JSON & | schema, |
| const sourcemeta::core::SchemaFrame & | frame, | ||
| const sourcemeta::core::SchemaFrame::Location & | location, | ||
| const sourcemeta::core::SchemaWalker & | walker, | ||
| const sourcemeta::core::SchemaResolver & | resolver, | ||
| sourcemeta::core::WeakPointer & | base )->sourcemeta::core::JSON |
Wrap a schema to only access one of its subschemas. This is useful if you want to perform validation on only a specific part of the schema without having to reinvent the wheel. For example: