Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
* Copyright (c) 2024 Muhammad Nawaz |
3 |
|
|
* Licensed under the MIT License. See LICENSE file for more information. |
4 |
|
|
*/ |
5 |
|
|
// [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ] |
6 |
|
|
|
7 |
|
|
#ifndef PARAM_VALIDATOR_HPP |
8 |
|
|
#define PARAM_VALIDATOR_HPP |
9 |
|
|
|
10 |
|
|
#include "deserializers/base_deserializer.hpp" |
11 |
|
|
#include "validators/json_validator.hpp" |
12 |
|
|
#include <rapidjson/schema.h> |
13 |
|
|
#include <unordered_map> |
14 |
|
|
#include <utility> |
15 |
|
|
|
16 |
|
|
class ParamValidator: public JsonValidator |
17 |
|
|
{ |
18 |
|
|
private: |
19 |
|
|
struct ParamInfo |
20 |
|
|
{ |
21 |
|
|
std::string name; |
22 |
|
|
bool required; |
23 |
|
|
BaseDeserializer* deserializer; |
24 |
|
|
const rapidjson::Value& schema; |
25 |
|
|
}; |
26 |
|
|
|
27 |
|
|
public: |
28 |
|
|
ParamValidator(const ParamInfo& param_info, const std::vector<std::string>& ref_keys, ValidationError err_code); |
29 |
|
|
ParamValidator(const ParamValidator&) = delete; |
30 |
|
|
ParamValidator& operator=(const ParamValidator&) = delete; |
31 |
|
|
|
32 |
|
|
ValidationError ValidateParam(const char* beg, const char* end, std::string& error_msg); |
33 |
|
|
bool IsRequired() const; |
34 |
|
|
ValidationError ErrorOnMissing(std::string& error_msg) const; |
35 |
|
802 |
~ParamValidator() override = default; |
36 |
|
|
|
37 |
|
|
protected: |
38 |
|
|
static ParamInfo GetParamInfo(const rapidjson::Value& param_val, const std::string& default_style, |
39 |
|
|
bool default_explode, bool default_required, |
40 |
|
|
const std::vector<std::string>& ref_keys); |
41 |
|
|
|
42 |
|
|
private: |
43 |
|
|
const std::string name_; |
44 |
|
|
const bool required_; |
45 |
|
|
BaseDeserializer* deserializer_; |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
class PathParamValidator final: public ParamValidator |
49 |
|
|
{ |
50 |
|
|
public: |
51 |
|
|
explicit PathParamValidator(const rapidjson::Value& param_val, const std::vector<std::string>& keys); |
52 |
|
|
PathParamValidator(const PathParamValidator&) = delete; |
53 |
|
|
PathParamValidator& operator=(const PathParamValidator&) = delete; |
54 |
|
316 |
~PathParamValidator() override = default; |
55 |
|
|
}; |
56 |
|
|
|
57 |
|
|
class QueryParamValidator final: public ParamValidator |
58 |
|
|
{ |
59 |
|
|
public: |
60 |
|
|
explicit QueryParamValidator(const rapidjson::Value& param_val, const std::vector<std::string>& keys); |
61 |
|
|
QueryParamValidator(const QueryParamValidator&) = delete; |
62 |
|
|
QueryParamValidator& operator=(const QueryParamValidator&) = delete; |
63 |
|
|
bool IsEmptyAllowed() const; |
64 |
|
1256 |
~QueryParamValidator() override = default; |
65 |
|
|
|
66 |
|
|
private: |
67 |
|
|
bool empty_allowed_; |
68 |
|
|
}; |
69 |
|
|
|
70 |
|
|
class HeaderParamValidator final: public ParamValidator |
71 |
|
|
{ |
72 |
|
|
public: |
73 |
|
|
explicit HeaderParamValidator(const rapidjson::Value& param_val, const std::vector<std::string>& keys); |
74 |
|
|
HeaderParamValidator(const HeaderParamValidator&) = delete; |
75 |
|
|
HeaderParamValidator& operator=(const HeaderParamValidator&) = delete; |
76 |
|
32 |
~HeaderParamValidator() override = default; |
77 |
|
|
}; |
78 |
|
|
#endif // PARAM_VALIDATOR_HPP |
79 |
|
|
|