$darkmode
#include <schema.hpp>
Public Member Functions | |
| Schema (const Schema &)=default | |
| Schema (Schema &&)=default | |
| Schema & | operator= (const Schema &)=default |
| Schema & | operator= (Schema &&)=default |
| Schema (std::string desc, schema::PropertyList<> props) | |
| Schema (schema::PropertyList<> props) | |
| Schema (std::string desc, const Schema &base, schema::PropertyList<> props) | |
| Schema (const Schema &base, schema::PropertyList<> props) | |
| Schema (const std::vector< Schema > &xs) | |
| Schema (std::string desc, const std::vector< Schema > &xs) | |
| Schema (schema::BoxList props) | |
| Schema (std::string desc, schema::BoxList props) | |
| Schema (schema::BoxVec &&props) | |
| Schema (std::string desc, schema::BoxVec &&props) | |
| template<typename T , std::enable_if_t< std::is_base_of_v< schema::Interface, T >, int > = 0> | |
| Schema (const T &value) | |
| Schema (std::unique_ptr< schema::Interface > ptr) | |
| Schema (std::shared_ptr< schema::Interface > ptr) | |
| Schema (std::string desc, JsonType t=JsonType::object) | |
| template<typename T > | |
| Schema (T *ptr, std::string desc) | |
| template<typename T > | |
| Schema (T *ptr, const schema::Box &prototype, std::string desc) | |
| template<typename T > | |
| Schema (T *ptr, JsonType t, std::string desc) | |
| Schema | reset_pointer () && |
| Json | json_schema_qualified () const |
| Json | json_schema_qualified (const std::string &id) const |
| operator schema::Box () const | |
| std::unique_ptr< Interface > | clone () const override |
| JsonType | type () const override |
| std::string | type_string () const override |
| bool | is_required () const override |
| const std::string & | description () const override |
| void | set_description (std::string s) 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 |
| void | reset_ptr () override |
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 |
Friends | |
| void | to_json (Json &j, const Schema &s) |
Additional Inherited Members | |
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 |
Schema is a wrapper class for fable schemas that automatically chooses the correct underlying schema type.
That is, this class provides an interface that doesn't require you to know which class to use, but it doesn't cover all use-cases.
|
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.
|
inlineoverridevirtual |
Return human-readable description.
Implements fable::schema::Interface.
|
inlineoverridevirtual |
Apply the input JSON configuration.
This does not validate the input.
Implements fable::schema::Interface.
|
inlineoverridevirtual |
Return whether this interface needs to be set.
Implements fable::schema::Interface.
|
inlineoverridevirtual |
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.
|
inlineoverridevirtual |
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.
|
inlineoverridevirtual |
Set human-readable description.
Implements fable::schema::Interface.
|
inlineoverridevirtual |
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.
|
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.
|
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.
|
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.
|
inlineoverridevirtual |
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.