Zane Shelley | 5191bae | 2021-08-04 22:48:28 -0500 | [diff] [blame] | 1 | #include <util/data_file.hpp> |
| 2 | #include <valijson/adapters/nlohmann_json_adapter.hpp> |
| 3 | #include <valijson/schema.hpp> |
| 4 | #include <valijson/schema_parser.hpp> |
| 5 | #include <valijson/validator.hpp> |
| 6 | |
| 7 | #include <regex> |
| 8 | |
| 9 | namespace fs = std::filesystem; |
| 10 | |
| 11 | namespace util |
| 12 | { |
| 13 | |
| 14 | void findFiles(const fs::path& i_dirPath, const std::string& i_matchString, |
| 15 | std::vector<fs::path>& o_foundPaths) |
| 16 | { |
| 17 | if (fs::exists(i_dirPath)) |
| 18 | { |
| 19 | std::regex search{i_matchString}; |
| 20 | for (const auto& file : fs::directory_iterator(i_dirPath)) |
| 21 | { |
Zane Shelley | ee54c99 | 2021-08-08 17:46:48 -0500 | [diff] [blame] | 22 | std::string filename = file.path().filename().string(); |
| 23 | if (std::regex_search(filename, search)) |
Zane Shelley | 5191bae | 2021-08-04 22:48:28 -0500 | [diff] [blame] | 24 | { |
| 25 | o_foundPaths.emplace_back(file.path()); |
| 26 | } |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | bool validateJson(const nlohmann::json& i_schema, const nlohmann::json& i_json) |
| 32 | { |
| 33 | valijson::Schema schema; |
| 34 | valijson::SchemaParser parser; |
| 35 | valijson::adapters::NlohmannJsonAdapter schemaAdapter(i_schema); |
| 36 | parser.populateSchema(schemaAdapter, schema); |
| 37 | |
| 38 | valijson::Validator validator; |
| 39 | valijson::adapters::NlohmannJsonAdapter targetAdapter(i_json); |
| 40 | |
| 41 | return validator.validate(schema, targetAdapter, nullptr); |
| 42 | } |
| 43 | |
| 44 | } // namespace util |