|
5 | 5 | // [ END OF LICENSE c6bd0f49d040fca8d8a9cb05868e66aa63f0e2e0 ] |
6 | 6 |
|
7 | 7 | #include "oas_validator_imp.hpp" |
| 8 | +#include <algorithm> |
8 | 9 | #include <fstream> |
9 | 10 | #include <rapidjson/istreamwrapper.h> |
10 | 11 | #include <sstream> |
11 | 12 |
|
12 | 13 | OASValidatorImp::OASValidatorImp(const std::string& oas_specs, |
13 | 14 | const std::unordered_map<std::string, std::unordered_set<std::string>>& method_map) |
14 | | - : method_map_(method_map) |
| 15 | + : method_map_(BuildCaseInsensitiveMap(method_map)) |
15 | 16 | { |
16 | 17 | rapidjson::Document doc; |
17 | 18 | ParseSpecs(oas_specs, doc); |
@@ -374,6 +375,24 @@ void OASValidatorImp::ResolveReferences(rapidjson::Value& value, rapidjson::Docu |
374 | 375 | } |
375 | 376 | } |
376 | 377 |
|
| 378 | +std::unordered_map<std::string, std::unordered_set<std::string>> OASValidatorImp::BuildCaseInsensitiveMap( |
| 379 | + const std::unordered_map<std::string, std::unordered_set<std::string>>& method_map) |
| 380 | +{ |
| 381 | + |
| 382 | + std::unordered_map<std::string, std::unordered_set<std::string>> case_insensitive_map; |
| 383 | + |
| 384 | + for (const auto& entry : method_map) { |
| 385 | + std::string lower_key(entry.first); |
| 386 | + std::transform(lower_key.begin(), lower_key.end(), lower_key.begin(), ::tolower); |
| 387 | + std::string upper_key(entry.first); |
| 388 | + std::transform(upper_key.begin(), upper_key.end(), upper_key.begin(), ::toupper); |
| 389 | + case_insensitive_map[lower_key] = entry.second; |
| 390 | + case_insensitive_map[upper_key] = entry.second; |
| 391 | + } |
| 392 | + |
| 393 | + return case_insensitive_map; |
| 394 | +} |
| 395 | + |
377 | 396 | const std::unordered_map<std::string, HttpMethod> OASValidatorImp::kStringToMethod = { |
378 | 397 | {"GET", HttpMethod::GET}, {"POST", HttpMethod::POST}, {"PUT", HttpMethod::PUT}, |
379 | 398 | {"DELETE", HttpMethod::DELETE}, {"HEAD", HttpMethod::HEAD}, {"OPTIONS", HttpMethod::OPTIONS}, |
|
0 commit comments