$darkmode
#include <struct.hpp>
Public Member Functions | |
| Struct (std::string desc="") | |
| Struct (std::string desc, PropertyList< Box > props) | |
| Struct (PropertyList< Box > props) | |
| Struct (std::string desc, const Box &base, PropertyList< Box > props) | |
| Struct (const Box &base, PropertyList< Box > props) | |
| void | set_property (const std::string &key, Box &&s) |
| Struct | property (const std::string &key, Box &&s) && |
| void | set_properties (PropertyList< Box > props) |
| void | set_properties_from (const Struct &s) |
| void | set_properties_from (const Box &s) |
| template<typename T , typename = enable_if_confable_t<T>> | |
| void | set_properties_from (const T *x) |
| template<typename T > | |
| Struct | properties_from (const T x) && |
| void | set_require (std::initializer_list< std::string > init) |
| Struct | require (std::initializer_list< std::string > init) && |
| void | set_require_all () |
| Struct | require_all () && |
| Struct | additional_properties (bool v) && |
| template<typename S , typename = enable_if_schema_t<S>> | |
| void | set_additional_properties (const S &s) |
| template<typename S , typename = enable_if_schema_t<S>> | |
| Struct | additional_properties (const S &s) && |
| bool | additional_properties () const |
| void | reset_ptr () override |
| Json | usage () const override |
| Json | json_schema () const override |
| bool | validate (const Conf &c, std::optional< SchemaError > &err) const override |
| void | to_json (Json &j) const override |
| void | from_conf (const Conf &c) override |
| virtual Json | to_json () const |
| virtual void | to_json (Json &) const=0 |
Public Member Functions inherited from fable::schema::Base< Struct > | |
| std::unique_ptr< Interface > | clone () const override |
| operator Box () const | |
| JsonType | type () const override |
| std::string | type_string () const override |
| Json | usage () const override |
| bool | is_required () const override |
| Struct | require () && |
| Struct | required (bool value) && |
| Struct | reset_pointer () && |
| bool | has_description () const |
| void | set_description (std::string s) override |
| const std::string & | description () const override |
| Struct | description (std::string desc) && |
Public Member Functions inherited from fable::schema::Interface | |
| virtual bool | is_variant () const |
| virtual void | validate_or_throw (const Conf &c) const final |
| virtual std::optional< SchemaError > | fail (const Conf &c) const final |
| virtual bool | is_valid (const Conf &c) const final |
| virtual Json | to_json () const |
Additional Inherited Members | |
Protected Member Functions inherited from fable::schema::Base< Struct > | |
| Base (const Base< Struct > &)=default | |
| Base (Base< Struct > &&) noexcept=default | |
| Base (JsonType t, std::string desc) | |
| Base (JsonType t) | |
| Base (std::string desc) | |
| Base< Struct > & | operator= (const Base< Struct > &)=default |
| Base< Struct > & | operator= (Base< Struct > &&) noexcept=default |
| bool | validate_type (const Conf &c, std::optional< SchemaError > &err) const |
| SchemaError | error (const Conf &c, std::string_view format, Args &&... args) const |
| SchemaError | error (const ConfError &e) const |
| SchemaError | wrong_type (const Conf &c) const |
| bool | set_error (std::optional< SchemaError > &err, const Conf &c, std::string_view format, Args &&... args) const |
| bool | set_error (std::optional< SchemaError > &err, const ConfError &e) const |
| bool | set_error (std::optional< SchemaError > &err, SchemaError &&e) const |
| bool | set_wrong_type (std::optional< SchemaError > &err, const Conf &c) const |
| void | augment_schema (Json &j) const |
Protected Member Functions inherited from fable::schema::Interface | |
| Interface (const Interface &)=default | |
| Interface (Interface &&) noexcept=default | |
| Interface & | operator= (const Interface &)=default |
| Interface & | operator= (Interface &&) noexcept=default |
Protected Attributes inherited from fable::schema::Base< Struct > | |
| JsonType | type_ |
| bool | required_ |
| std::string | desc_ |
Struct maintains a key-value mapping, where the list of keys is usually known and the values can have different types (schemas).
This is usually the basis of any schema, since most start with a JSON object.
This should not be confused with the Map type.
|
inline |
Instantiate a Struct with a base Schema, which should also be a Struct, then extend it with the property list.
This is particularly useful when the Confable is inheriting from a base class:
struct Sub : public Base {
std::string member;
CONFABLE_SCHEMA(Sub) {
return Struct{
Base::schema_impl(),
{
{"member", make_schema(&member, "important addition")},
}
};
}
};
Warning: When implementing schema_impl, for example with CONFABLE_SCHEMA, it is absolutely important that you not call Base::schema(), as this will internally call this->schema_impl(), which will lead to an infinite recursion! Instead, call Base::schema_impl().
|
inline |
Set whether to tolerate unknown fields in this entry.
|
overridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
|
overridevirtual |
Return the JSON schema.
Example output:
{ "$schema": "http://json-schema.org/draft-07/schema#", "description": "stand-in no-operation simulator", "properties": { "vehicles": { "description": "list of vehicle names to make available", "items": { "type": "string" }, "type": "array" } }, "title": "nop", "additionalProperties": false, "type": "object" }
See the following links for the specification:
Implements fable::schema::Interface.
|
overridevirtual |
Reset the internal pointer to nullptr, protecting against invalid access.
This should be used when a schema is used after the backing data has been deleted.
Implements fable::schema::Interface.
| void fable::schema::Struct::set_properties | ( | PropertyList< Box > | props | ) |
Set all properties.
|
inline |
Add the properties from s to this schema.
| void fable::schema::Struct::set_property | ( | const std::string & | key, |
| Box && | s | ||
| ) |
Set the property to this schema.
| void fable::schema::Struct::set_require | ( | std::initializer_list< std::string > | init | ) |
Set which entries are required.
| void fable::schema::Struct::set_require_all | ( | ) |
Set whether all entries are required.
|
inline |
Return the current value of the destination.
Warning: This is NOT an efficient operation, but it can be useful for cases where speed is not important.
| virtual void fable::schema::Interface::to_json |
Return the current value of the destination.
Warning: This is NOT an efficient operation, but it can be useful for cases where speed is not important.
|
overridevirtual |
Return the current value of the destination.
Warning: This is NOT an efficient operation, but it can be useful for cases where speed is not important.
Implements fable::schema::Interface.
|
overridevirtual |
Return a compact JSON description of the schema. This is useful for human-readable error output.
Example output:
{ "field1": "boolean! :: lorem ipsum dolor sit amet", "field2": { "field2.1": "integer :: lorem ipsum dolor sit amet" "field2.2": "boolean :: lorem ipsum dolor sit amet" }, "field3": "array of integer :: lorem ipsum dolor sit amet", "field4": [{ "field4.1": "string :: lorem ipsum dolor sit amet" "field4.2": "boolean :: lorem ipsum dolor sit amet" }] }
When describing the schema of a primitive array, we can represent that as a single string. But when the array contains an object, we wrap a single object in an array. This isn't awfully consistent, but it's the best we can do.
Implements fable::schema::Interface.
|
overridevirtual |
Validate the input JSON configuration for correctness.
error if there is an error. This method should not reset error if there is no error. Therefore, the content of error is only valid if the method returns false. This allows you to chain validates and check at the end if there was an error.| c | JSON to check |
| error | reference to store error if occurred |
Implements fable::schema::Interface.