|
9 | 9 | #include <rapidjson/istreamwrapper.h> |
10 | 10 | #include <sstream> |
11 | 11 |
|
12 | | -OASValidatorImp::OASValidatorImp(const std::string& oas_specs) |
| 12 | +OASValidatorImp::OASValidatorImp(const std::string& oas_specs, |
| 13 | + const std::unordered_map<std::string, std::unordered_set<std::string>>& method_map) |
| 14 | + : method_map_(method_map) |
13 | 15 | { |
14 | 16 | rapidjson::Document doc; |
15 | 17 | ParseSpecs(oas_specs, doc); |
@@ -175,7 +177,30 @@ ValidationError OASValidatorImp::GetValidators(const std::string& method, const |
175 | 177 | auto err_code = method_validator_.Validate(method, error_msg); |
176 | 178 | CHECK_ERROR(err_code) |
177 | 179 |
|
178 | | - auto enum_method = kStringToMethod.at(method); |
| 180 | + err_code = GetValidators(method, method, http_path, validators, error_msg, param_idxs, query); |
| 181 | + if (ValidationError::INVALID_ROUTE == err_code) { |
| 182 | + try { |
| 183 | + auto mapped_methods = method_map_.at(method); |
| 184 | + for (const auto& mapped_method : mapped_methods) { |
| 185 | + err_code = GetValidators(method, mapped_method, http_path, validators, error_msg, param_idxs, query); |
| 186 | + if (ValidationError::NONE == err_code) { |
| 187 | + return err_code; |
| 188 | + } |
| 189 | + } |
| 190 | + } catch (const std::out_of_range&) { |
| 191 | + return err_code; |
| 192 | + } |
| 193 | + } |
| 194 | + |
| 195 | + return err_code; |
| 196 | +} |
| 197 | + |
| 198 | +ValidationError OASValidatorImp::GetValidators(const std::string& method, const std::string& mapped_method, |
| 199 | + const std::string& http_path, ValidatorsStore*& validators, |
| 200 | + std::string& error_msg, |
| 201 | + std::unordered_map<size_t, ParamRange>* param_idxs, std::string* query) |
| 202 | +{ |
| 203 | + auto enum_method = kStringToMethod.at(mapped_method); |
179 | 204 |
|
180 | 205 | auto query_pos = http_path.find('?'); |
181 | 206 | if (std::string::npos != query_pos && query) { |
|
0 commit comments