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) :
Base<Path<T>>(JsonType::string, std::move(desc)), ptr_(ptr) {}
104 void set_state(State s) { req_state_ = s; }
111 return std::move(*
this);
114 [[nodiscard]]
Path absent() && {
return std::move(*this).
state(State::Absent); }
115 [[nodiscard]] Path exists() && {
return std::move(*this).state(State::Exists); }
116 [[nodiscard]] Path executable() && {
return std::move(*this).state(State::Executable); }
117 [[nodiscard]] Path file_exists() && {
return std::move(*this).state(State::FileExists); }
118 [[nodiscard]] Path dir_exists() && {
return std::move(*this).state(State::DirExists); }
119 [[nodiscard]] Path not_file() && {
return std::move(*this).state(State::NotFile); }
120 [[nodiscard]] Path not_dir() && {
return std::move(*this).state(State::NotDir); }
122 [[nodiscard]] Path not_empty() && {
124 return std::move(*
this);
127 [[nodiscard]]
bool absolute()
const {
131 void set_absolute(
bool value) {
140 return std::move(*
this);
150 [[nodiscard]]
bool resolve()
const {
return resolve_; }
152 void set_resolve(
bool value) { resolve_ = value; }
168 return std::move(*
this);
171 [[nodiscard]]
bool normalize()
const {
return normalize_; }
172 void set_normalize(
bool value) { normalize_ = value; }
173 [[nodiscard]] Path normalize(
bool value) && {
175 return std::move(*
this);
178 [[nodiscard]]
bool interpolate()
const {
return interpolate_; }
179 void set_interpolate(
bool value) { interpolate_ = value; }
180 [[nodiscard]] Path interpolate(
bool value) && {
181 interpolate_ = value;
182 return std::move(*
this);
185 [[nodiscard]]
Environment* environment()
const {
return env_; }
186 void set_environment(
Environment* env) { env_ = env; }
187 [[nodiscard]] Path environment(
Environment* env) && {
189 return std::move(*
this);
192 [[nodiscard]]
size_t min_length()
const {
return min_length_; }
193 void set_min_length(
size_t value) { min_length_ = value; }
194 [[nodiscard]] Path min_length(
size_t value) && {
196 return std::move(*
this);
199 [[nodiscard]]
size_t max_length()
const {
return max_length_; }
200 void set_max_length(
size_t value) { max_length_ = value; }
201 [[nodiscard]] Path max_length(
size_t value) && {
203 return std::move(*
this);
206 [[nodiscard]]
const std::string& pattern()
const {
return pattern_; }
207 void set_pattern(
const std::string& value) { pattern_ = value; }
208 [[nodiscard]] Path pattern(
const std::string& value) && {
210 return std::move(*
this);
215 bool validate(
const Conf& c, std::optional<SchemaError>& err)
const override;
219 assert(ptr_ !=
nullptr);
220 j = serialize(*ptr_);
224 assert(ptr_ !=
nullptr);
225 *ptr_ = deserialize(c);
228 [[nodiscard]]
Json serialize(
const Type& x)
const {
return x.native(); }
230 [[nodiscard]] Type deserialize(
const Conf& c)
const;
232 void serialize_into(
Json& j,
const Type& x)
const { j = serialize(x); }
234 void deserialize_into(
const Conf& c, Type& x)
const { x = deserialize(c); }
239 [[nodiscard]] Type resolve_path(
const Conf&,
const Type&)
const;
242 State req_state_{State::Any};
243 bool req_abs_{
false};
245 bool normalize_{
false};
246 bool interpolate_{
false};
247 size_t min_length_{0};
248 size_t max_length_{std::numeric_limits<size_t>::max()};
249 std::string pattern_{};
254 template <
typename T,
typename S, std::enable_if_t<is_path_v<T>,
bool> = true>
255 Path<T> make_schema(T* ptr, S&& desc) {
256 return {ptr, std::forward<S>(desc)};
Definition: server_test.cpp:72
Definition: interface.hpp:398
virtual Json to_json() const
Definition: interface.hpp:254
Path absolute(bool value) &&
Definition: path.hpp:138
void to_json(Json &j) const override
Definition: path.hpp:218
bool resolve() const
Definition: path.hpp:150
Path state(State s) &&
Definition: path.hpp:109
void from_conf(const Conf &c) override
Definition: path.hpp:223
bool validate(const Conf &c, std::optional< SchemaError > &err) const override
Definition: path_impl.hpp:89
State state() const
Definition: path.hpp:102
Path resolve(bool value) &&
Definition: path.hpp:166
Json json_schema() const override
Definition: path_impl.hpp:66
void reset_ptr() override
Definition: path.hpp:236
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