35 namespace fable::schema {
53 struct is_path<std::filesystem::path> : std::true_type {};
90 static_assert(is_path_v<T>);
96 Path(Type* ptr, std::string desc)
97 :
Base<Path<T>>(JsonType::string, std::move(desc)), ptr_(ptr) {}
110 return std::move(*
this);
112 void set_state(State s) { req_state_ = s; }
114 Path absent() && {
return std::move(*this).state(State::Absent); }
115 Path exists() && {
return std::move(*this).state(State::Exists); }
116 Path executable() && {
return std::move(*this).state(State::Executable); }
117 Path file_exists() && {
return std::move(*this).state(State::FileExists); }
118 Path dir_exists() && {
return std::move(*this).state(State::DirExists); }
119 Path not_file() && {
return std::move(*this).state(State::NotFile); }
120 Path not_dir() && {
return std::move(*this).state(State::NotDir); }
122 Path not_empty() && {
124 return std::move(*
this);
132 return std::move(*
this);
140 [[nodiscard]]
bool resolve()
const {
return resolve_; }
156 return std::move(*
this);
158 void set_resolve(
bool value) { resolve_ = value; }
160 [[nodiscard]]
bool normalize()
const {
return normalize_; }
161 Path normalize(
bool value) && {
163 return std::move(*
this);
165 void set_normalize(
bool value) { normalize_ = value; }
167 [[nodiscard]]
bool interpolate()
const {
return interpolate_; }
168 void set_interpolate(
bool value) { interpolate_ = value; }
169 Path interpolate(
bool value) && {
170 interpolate_ = value;
171 return std::move(*
this);
174 [[nodiscard]]
Environment* environment()
const {
return env_; }
175 void set_environment(
Environment* env) { env_ = env; }
178 return std::move(*
this);
181 [[nodiscard]]
size_t min_length()
const {
return min_length_; }
182 void set_min_length(
size_t value) { min_length_ = value; }
183 Path min_length(
size_t value) && {
185 return std::move(*
this);
188 [[nodiscard]]
size_t max_length()
const {
return max_length_; }
189 void set_max_length(
size_t value) { max_length_ = value; }
190 Path max_length(
size_t value) && {
192 return std::move(*
this);
195 [[nodiscard]]
const std::string& pattern()
const {
return pattern_; }
196 void set_pattern(
const std::string& value) { pattern_ = value; }
197 Path pattern(
const std::string& value) && {
199 return std::move(*
this);
204 bool validate(
const Conf& c, std::optional<SchemaError>& err)
const override;
208 assert(ptr_ !=
nullptr);
209 j = serialize(*ptr_);
213 assert(ptr_ !=
nullptr);
214 *ptr_ = deserialize(c);
217 [[nodiscard]]
Json serialize(
const Type& x)
const {
return x.native(); }
219 [[nodiscard]] Type deserialize(
const Conf& c)
const;
221 void serialize_into(
Json& j,
const Type& x)
const { j = serialize(x); }
223 void deserialize_into(
const Conf& c, Type& x)
const { x = deserialize(c); }
228 [[nodiscard]] Type resolve_path(
const Conf&,
const Type&)
const;
231 State req_state_{State::Any};
232 bool req_abs_{
false};
234 bool normalize_{
false};
235 bool interpolate_{
false};
236 size_t min_length_{0};
237 size_t max_length_{std::numeric_limits<size_t>::max()};
238 std::string pattern_{};
243 template <
typename T, std::enable_if_t<is_path_v<T>,
bool> = true>
244 inline Path<T> make_schema(T* ptr, std::string desc) {
245 return Path(ptr, std::move(desc));
Definition: server_test.cpp:71
Definition: interface.hpp:398
virtual Json to_json() const
Definition: interface.hpp:254
Path absolute() &&
Definition: path.hpp:130
void to_json(Json &j) const override
Definition: path.hpp:207
bool resolve() const
Definition: path.hpp:140
Path state(State s) &&
Definition: path.hpp:108
void from_conf(const Conf &c) override
Definition: path.hpp:212
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: path_impl.hpp:89
State state() const
Definition: path.hpp:103
Path resolve(bool value) &&
Definition: path.hpp:154
Json json_schema() const override
Definition: path_impl.hpp:66
void reset_ptr() override
Definition: path.hpp:225
nlohmann::json Json
Definition: fable_fwd.hpp:35
PathState
Definition: path.hpp:58
@ Exists
path does not exist
@ NotDir
path does not exist or is a directory
@ DirExists
path exists and is a file
@ NotFile
path exists and is a directory
@ FileExists
path exists in search path or locally and has executable permission