$darkmode
#include <interface.hpp>
Public Member Functions | |
| virtual std::unique_ptr< Interface > | clone () const =0 |
| virtual bool | is_variant () const |
| virtual JsonType | type () const =0 |
| virtual std::string | type_string () const =0 |
| virtual bool | is_required () const =0 |
| virtual const std::string & | description () const =0 |
| virtual void | set_description (std::string s)=0 |
| virtual Json | usage () const =0 |
| virtual Json | json_schema () const =0 |
| virtual bool | validate (const Conf &c, std::optional< SchemaError > &error) const =0 |
| 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 |
| virtual void | to_json (Json &) const =0 |
| virtual void | from_conf (const Conf &)=0 |
| virtual void | reset_ptr ()=0 |
Protected Member Functions | |
| Interface (const Interface &)=default | |
| Interface (Interface &&) noexcept=default | |
| Interface & | operator= (const Interface &)=default |
| Interface & | operator= (Interface &&) noexcept=default |
Interface specifies all information for describing a JSON entity.
Schemas are instantiated through one of the many constructors that are defined.
Most constructor definitions make use of one of a set of private template constructors. These private template constructors enable slimmer constructors for all sorts of types later on. In order to differentiate between these constructors and the ones that users should use, the number of parameters and the order of types is sometimes varied.
We could use named constructors, but then you can not use the new operator with the construction or you need to use the copy constructor thereby constructing the schema twice.
When changing this Interface, the following implementors should be updated:
Box fable/schema/interface.hpp Schema fable/schema.hpp Variant fable/schema/variant.hpp FromConfable fable/schema/confable.hpp
|
pure virtual |
Return a new instance of the object.
This is implemented by Base and allows us to wrap implementors of Interface with Schema.
Implemented in fable::schema::Variant, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
pure virtual |
Return human-readable description.
Implemented in fable::schema::Variant, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
inlinefinalvirtual |
Return input JSON configuration schema error, if any.
If you don't have a Conf but would like to validate a Json type, then construct a Conf on the fly:
s.fail(Conf{j});
This overload is not provided inline to prevent incorrect use.
| c | JSON to check |
|
pure virtual |
Apply the input JSON configuration.
This does not validate the input.
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Struct, fable::schema::String, fable::schema::Path< T >, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Number< T >, fable::schema::Map< T, P >, fable::schema::FromJson< T >, fable::schema::Box, fable::schema::Factory< T >, fable::schema::Factory< DistributionPtr >, fable::schema::Enum< T >, fable::schema::Duration< T, Period >, fable::schema::CustomDeserializer, fable::schema::Const< T, P >, fable::schema::FromConfable< T, >, fable::schema::Boolean, fable::schema::Array< T, N, P >, fable::Schema, fable::schema::Ignore, fable::schema::FactoryBase< T, CRTP >, fable::schema::FactoryBase< T, Factory< T > >, and fable::schema::FactoryBase< T, FactoryPointerless< T > >.
|
pure virtual |
Return whether this interface needs to be set.
Implemented in fable::schema::Variant, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
inlinefinalvirtual |
Return whether the input JSON is valid.
|
inlinevirtual |
Return whether the accepted input type is a variant.
A variant type is one that is composed of other types, such as the special types: any-of, one-of, and all-of.
Reimplemented in fable::schema::Variant, and fable::schema::Optional< T, P >.
|
pure virtual |
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:
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Struct, fable::schema::String, fable::schema::Path< T >, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Number< T >, fable::schema::Map< T, P >, fable::schema::FromJson< T >, fable::schema::Box, fable::schema::Ignore, fable::schema::FactoryBase< T, CRTP >, fable::schema::FactoryBase< T, Factory< T > >, fable::schema::FactoryBase< T, FactoryPointerless< T > >, fable::schema::Enum< T >, fable::schema::Duration< T, Period >, fable::schema::CustomDeserializer, fable::schema::Const< T, P >, fable::schema::FromConfable< T, >, fable::schema::Boolean, fable::schema::Array< T, N, P >, and fable::Schema.
|
pure virtual |
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.
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Struct, fable::schema::String, fable::schema::Path< T >, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Number< T >, fable::schema::Map< T, P >, fable::schema::FromJson< T >, fable::schema::Box, fable::schema::Ignore, fable::schema::Factory< T >, fable::schema::Factory< DistributionPtr >, fable::schema::FactoryBase< T, CRTP >, fable::schema::FactoryBase< T, Factory< T > >, fable::schema::FactoryBase< T, FactoryPointerless< T > >, fable::schema::Enum< T >, fable::schema::Duration< T, Period >, fable::schema::CustomDeserializer, fable::schema::Const< T, P >, fable::schema::FromConfable< T, >, fable::schema::Boolean, fable::schema::Array< T, N, P >, and fable::Schema.
|
pure virtual |
Set human-readable description.
Implemented in fable::schema::Variant, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
inlinevirtual |
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.
|
pure virtual |
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.
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Struct, fable::schema::String, fable::schema::Path< T >, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Number< T >, fable::schema::Map< T, P >, fable::schema::FromJson< T >, fable::schema::Box, fable::schema::Ignore, fable::schema::Factory< T >, fable::schema::Factory< DistributionPtr >, fable::schema::Enum< T >, fable::schema::Duration< T, Period >, fable::schema::CustomDeserializer, fable::schema::Const< T, P >, fable::schema::FromConfable< T, >, fable::schema::Boolean, fable::schema::Array< T, N, P >, fable::Schema, fable::schema::FactoryBase< T, CRTP >, fable::schema::FactoryBase< T, Factory< T > >, and fable::schema::FactoryBase< T, FactoryPointerless< T > >.
|
pure virtual |
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.
Implemented in fable::schema::Variant, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
pure virtual |
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"
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, fable::schema::Array< T, N, P >, and fable::Schema.
|
pure virtual |
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.
Implemented in fable::schema::Variant, fable::schema::Struct, fable::schema::Base< CRTP >, fable::schema::Base< Array< T, N, P > >, fable::schema::Base< Path< T > >, fable::schema::Base< Factory< T > >, fable::schema::Base< FromConfable< T > >, fable::schema::Base< Vector< T, P > >, fable::schema::Base< String >, fable::schema::Base< FactoryPointerless< T > >, fable::schema::Base< Boolean >, fable::schema::Base< Optional< T, P > >, fable::schema::Base< FromJson< T > >, fable::schema::Base< Const< T, P > >, fable::schema::Base< Number< T > >, fable::schema::Base< Map< T, P > >, fable::schema::Base< Enum< T > >, fable::schema::Base< Duration< T, Period > >, fable::schema::Base< Ignore >, fable::schema::Base< Struct >, fable::schema::Base< Passthru< P > >, fable::schema::Box, fable::schema::CustomDeserializer, and fable::Schema.
|
pure virtual |
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 |
Implemented in fable::schema::Vector< T, P >, fable::schema::Variant, fable::schema::Struct, fable::schema::String, fable::schema::Path< T >, fable::schema::Passthru< P >, fable::schema::Optional< T, P >, fable::schema::Number< T >, fable::schema::Map< T, P >, fable::schema::FromJson< T >, fable::schema::Box, fable::schema::FactoryBase< T, CRTP >, fable::schema::FactoryBase< T, Factory< T > >, fable::schema::FactoryBase< T, FactoryPointerless< T > >, fable::schema::Enum< T >, fable::schema::Duration< T, Period >, fable::schema::CustomDeserializer, fable::schema::Const< T, P >, fable::schema::FromConfable< T, >, fable::schema::Boolean, fable::schema::Array< T, N, P >, fable::Schema, and fable::schema::Ignore.
|
inlinefinalvirtual |
Validate the input JSON configuration or throw an error.
If you don't have a Conf but would like to validate a Json type, then construct a Conf on the fly:
s.validate_or_throw(Conf{j});
This overload is not provided inline to prevent incorrect use.
| c | JSON to check |