121 #include <type_traits>
152 using schema::make_const_schema;
153 using schema::make_prototype;
154 using schema::make_schema;
163 template <
typename T>
165 using type = decltype(make_schema(
static_cast<T*
>(
nullptr),
""));
178 ~
Schema() noexcept
override =
default;
185 Schema(std::string desc, schema::PropertyList<> props)
188 Schema(schema::PropertyList<> props) :
Schema(
"", props) {}
190 Schema(std::string desc,
const Schema& base, schema::PropertyList<> props)
196 Schema(
const std::vector<Schema>& xs);
197 Schema(std::string desc,
const std::vector<Schema>& xs);
199 Schema(schema::BoxList props);
200 Schema(std::string desc, schema::BoxList props);
202 Schema(schema::BoxVec&& props);
203 Schema(std::string desc, schema::BoxVec&& props);
206 template <
typename T, std::enable_if_t<std::is_base_of_v<schema::Interface, T>,
int> = 0>
207 Schema(
const T& value) : impl_(value.clone()) {}
208 Schema(std::unique_ptr<schema::Interface> ptr) : impl_(std::move(ptr)) { assert(impl_); }
209 Schema(std::shared_ptr<schema::Interface> ptr) : impl_(std::move(ptr)) { assert(impl_); }
217 template <
typename T>
218 Schema(T* ptr, std::string desc) : impl_(make_schema(ptr, std::move(desc)).
clone()) {}
219 template <
typename T>
221 : impl_(make_schema(ptr, prototype, std::move(desc)).
clone()) {}
224 template <
typename T>
229 Schema reset_pointer() && {
231 return std::move(*
this);
234 [[nodiscard]]
Json json_schema_qualified()
const {
235 Json j = impl_->json_schema();
236 j[
"$schema"] =
"http://json-schema.org/draft-07/schema#";
240 [[nodiscard]]
Json json_schema_qualified(
const std::string&
id)
const {
241 Json j = json_schema_qualified();
247 using Interface::to_json;
249 [[nodiscard]] std::unique_ptr<Interface>
clone()
const override {
return impl_->clone(); }
251 [[nodiscard]] std::string
type_string()
const override {
return impl_->type_string(); }
252 [[nodiscard]]
bool is_required()
const override {
return impl_->is_required(); }
253 [[nodiscard]]
const std::string&
description()
const override {
return impl_->description(); }
254 void set_description(std::string s)
override {
return impl_->set_description(std::move(s)); }
255 [[nodiscard]]
Json usage()
const override {
return impl_->usage(); }
257 bool validate(
const Conf& c, std::optional<SchemaError>& err)
const override {
258 return impl_->validate(c, err);
267 std::shared_ptr<schema::Interface> impl_{
nullptr};
Definition: schema.hpp:175
bool is_required() const override
Definition: schema.hpp:252
void to_json(Json &j) const override
Definition: schema.hpp:260
Json usage() const override
Definition: schema.hpp:255
const std::string & description() const override
Definition: schema.hpp:253
void reset_ptr() override
Definition: schema.hpp:262
void set_description(std::string s) override
Definition: schema.hpp:254
void from_conf(const Conf &c) override
Definition: schema.hpp:261
Json json_schema() const override
Definition: schema.hpp:256
std::string type_string() const override
Definition: schema.hpp:251
std::unique_ptr< Interface > clone() const override
Definition: schema.hpp:249
JsonType type() const override
Definition: schema.hpp:250
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: schema.hpp:257
Definition: interface.hpp:297
Definition: ignore.hpp:43
Definition: interface.hpp:67
virtual Json to_json() const
Definition: interface.hpp:254
Definition: struct.hpp:70
nlohmann::json Json
Definition: fable_fwd.hpp:35
nlohmann::detail::value_t JsonType
Definition: fable_fwd.hpp:37
Definition: schema.hpp:164