$darkmode
fable::schema::Base< CRTP > Class Template Reference
Inheritance diagram for fable::schema::Base< CRTP >:
[legend]
Collaboration diagram for fable::schema::Base< CRTP >:
[legend]

Public Member Functions

 Base (JsonType t, std::string &&desc)
 
 Base (JsonType t)
 
 Base (std::string &&desc)
 
Interfaceclone () const override
 
 operator Box () const
 
JsonType type () const override
 
std::string type_string () const override
 
Json usage () const override
 
bool is_required () const override
 
CRTP require () &&
 
CRTP required (bool value) &&
 
CRTP reset_pointer () &&
 
bool has_description () const
 
void set_description (const std::string &s) override
 
void set_description (std::string &&s)
 
const std::string & description () const override
 
CRTP description (std::string &&desc) &&
 
- Public Member Functions inherited from fable::schema::Interface
virtual bool is_variant () const
 
virtual Json json_schema () const =0
 
virtual void validate (const Conf &c) const =0
 
virtual bool is_valid (const Conf &c) const
 
virtual Json to_json () const
 
virtual void to_json (Json &) const =0
 
virtual void from_conf (const Conf &)=0
 
virtual void reset_ptr ()=0
 

Protected Member Functions

void validate_type (const Conf &c) const
 
template<typename... Args>
void throw_error (const Conf &c, const char *format, Args... args) const
 
void throw_error (const ConfError &e) const
 
void throw_wrong_type (const Conf &c) const
 
void augment_schema (Json &j) const
 

Protected Attributes

JsonType type_ {JsonType::null}
 
bool required_ {false}
 
std::string desc_ {}
 

Member Function Documentation

◆ clone()

template<typename CRTP>
Interface* fable::schema::Base< CRTP >::clone ( ) const
inlineoverridevirtual

Return a new instance of the object.

This is implemented by Base and allows us to wrap implementors of Interface with Schema.

Implements fable::schema::Interface.

◆ description()

template<typename CRTP>
const std::string& fable::schema::Base< CRTP >::description ( ) const
inlineoverridevirtual

Return human-readable description.

Implements fable::schema::Interface.

◆ is_required()

template<typename CRTP>
bool fable::schema::Base< CRTP >::is_required ( ) const
inlineoverridevirtual

Return whether this interface needs to be set.

Implements fable::schema::Interface.

◆ set_description()

template<typename CRTP>
void fable::schema::Base< CRTP >::set_description ( const std::string &  s)
inlineoverridevirtual

Set human-readable description.

Implements fable::schema::Interface.

◆ type()

template<typename CRTP>
JsonType fable::schema::Base< CRTP >::type ( ) const
inlineoverridevirtual

Return the JSON type.

If this is a variant type of differing types, then null should be returned. Otherwise, the type remains unique and can be returned. A type that is null is almost always a variant type of some sort, if even only an optional type.

Implements fable::schema::Interface.

◆ type_string()

template<typename CRTP>
std::string fable::schema::Base< CRTP >::type_string ( ) const
inlineoverridevirtual

Return the type as a string.

The format of the string is:

"[array of] TYPE"

where TYPE is one of: null, object, boolean, float, integer, unsigned, string, and unknown.

Example output:

"object"
"array of boolean"
"array of object"

Implements fable::schema::Interface.

◆ usage()

template<typename CRTP>
Json fable::schema::Base< CRTP >::usage ( ) const
inlineoverridevirtual

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.


The documentation for this class was generated from the following file: