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 
findFiles(const fs::path & i_dirPath,const std::string & i_matchString,std::vector<fs::path> & o_foundPaths)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         {
22             std::string filename = file.path().filename().string();
23             if (std::regex_search(filename, search))
24             {
25                 o_foundPaths.emplace_back(file.path());
26             }
27         }
28     }
29 }
30 
validateJson(const nlohmann::json & i_schema,const nlohmann::json & i_json)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
45