@@ -90,27 +90,23 @@ class yaml_helper
90
90
* Load all the YAML document represented by the input string.
91
91
* Since this is used by rule loader, does not process env vars.
92
92
*/
93
- std::vector<YAML::Node> loadall_from_string (const std::string& input, const nlohmann::json& schema={}, std::string *validation =nullptr )
93
+ std::vector<YAML::Node> loadall_from_string (const std::string& input, const nlohmann::json& schema={}, std::vector<std:: string> *schema_warnings =nullptr )
94
94
{
95
95
auto nodes = YAML::LoadAll (input);
96
- if (validation )
96
+ if (schema_warnings )
97
97
{
98
+ schema_warnings->clear ();
98
99
if (!schema.empty ())
99
100
{
100
101
// Validate each node.
101
- for (const auto & node : nodes)
102
+ for (const auto & node : nodes)
102
103
{
103
- *validation = validate_node (node, schema);
104
- if (*validation != validation_ok)
105
- {
106
- // Return first error
107
- break ;
108
- }
104
+ validate_node (node, schema, schema_warnings);
109
105
}
110
106
}
111
107
else
112
108
{
113
- *validation = validation_none;
109
+ schema_warnings-> push_back ( validation_none) ;
114
110
}
115
111
}
116
112
return nodes;
@@ -119,35 +115,36 @@ class yaml_helper
119
115
/* *
120
116
* Load the YAML document represented by the input string.
121
117
*/
122
- void load_from_string (const std::string& input, const nlohmann::json& schema={}, std::string *validation =nullptr )
118
+ void load_from_string (const std::string& input, const nlohmann::json& schema={}, std::vector<std:: string> *schema_warnings =nullptr )
123
119
{
124
120
m_root = YAML::Load (input);
125
121
pre_process_env_vars (m_root);
126
122
127
- if (validation )
123
+ if (schema_warnings )
128
124
{
125
+ schema_warnings->clear ();
129
126
if (!schema.empty ())
130
127
{
131
- *validation = validate_node (m_root, schema);
128
+ validate_node (m_root, schema, schema_warnings );
132
129
}
133
130
else
134
131
{
135
- *validation = validation_none;
132
+ schema_warnings-> push_back ( validation_none) ;
136
133
}
137
134
}
138
135
}
139
136
140
137
/* *
141
138
* Load the YAML document from the given file path.
142
139
*/
143
- void load_from_file (const std::string& path, const nlohmann::json& schema={}, std::string *validation =nullptr )
140
+ void load_from_file (const std::string& path, const nlohmann::json& schema={}, std::vector<std:: string> *schema_warnings =nullptr )
144
141
{
145
- m_root = load_from_file_int (path, schema, validation );
142
+ m_root = load_from_file_int (path, schema, schema_warnings );
146
143
}
147
144
148
- void include_config_file (const std::string& include_file_path, const nlohmann::json& schema={}, std::string *validation =nullptr )
145
+ void include_config_file (const std::string& include_file_path, const nlohmann::json& schema={}, std::vector<std:: string> *schema_warnings =nullptr )
149
146
{
150
- auto loaded_nodes = load_from_file_int (include_file_path, schema, validation );
147
+ auto loaded_nodes = load_from_file_int (include_file_path, schema, schema_warnings );
151
148
for (auto n : loaded_nodes)
152
149
{
153
150
/*
@@ -243,26 +240,27 @@ class yaml_helper
243
240
private:
244
241
YAML::Node m_root;
245
242
246
- YAML::Node load_from_file_int (const std::string& path, const nlohmann::json& schema={} , std::string *validation= nullptr )
243
+ YAML::Node load_from_file_int (const std::string& path, const nlohmann::json& schema, std::vector<std:: string> *schema_warnings )
247
244
{
248
245
auto root = YAML::LoadFile (path);
249
246
pre_process_env_vars (root);
250
247
251
- if (validation )
248
+ if (schema_warnings )
252
249
{
250
+ schema_warnings->clear ();
253
251
if (!schema.empty ())
254
252
{
255
- *validation = validate_node (root, schema);
253
+ validate_node (root, schema, schema_warnings );
256
254
}
257
255
else
258
256
{
259
- *validation = validation_none;
257
+ schema_warnings-> push_back ( validation_none) ;
260
258
}
261
259
}
262
260
return root;
263
261
}
264
262
265
- std::string validate_node (const YAML::Node &node, const nlohmann::json& schema={} )
263
+ void validate_node (const YAML::Node &node, const nlohmann::json& schema, std::vector<std::string> *schema_warnings )
266
264
{
267
265
// Validate the yaml against our json schema
268
266
valijson::Schema schemaDef;
@@ -277,16 +275,18 @@ class yaml_helper
277
275
{
278
276
valijson::ValidationResults::Error error;
279
277
// report only the top-most error
280
- if (validationResults.popError (error))
278
+ while (validationResults.popError (error))
281
279
{
282
- return std::string (validation_failed + " for " )
280
+ schema_warnings-> push_back ( std::string (validation_failed + " for " )
283
281
+ std::accumulate (error.context .begin (), error.context .end (), std::string (" " ))
284
282
+ " : "
285
- + error.description ;
283
+ + error.description ) ;
286
284
}
287
- return validation_failed;
288
285
}
289
- return validation_ok;
286
+ else
287
+ {
288
+ schema_warnings->push_back (validation_ok);
289
+ }
290
290
}
291
291
292
292
/*
0 commit comments