|
|
@@ -214,6 +214,21 @@ public:
|
|
|
return &local.errors.at(name);
|
|
|
}
|
|
|
|
|
|
+ ValidationResult only_errors() const {
|
|
|
+ ValidationResult rval;
|
|
|
+ rval.valid_ = valid_;
|
|
|
+
|
|
|
+ for (auto const & [doc, results] : results_) {
|
|
|
+ for (auto const & [schema, result] : results) {
|
|
|
+ if (!result.valid && !result.errors.empty()) {
|
|
|
+ rval.results_[doc][schema] = result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return rval;
|
|
|
+ }
|
|
|
+
|
|
|
private:
|
|
|
/**
|
|
|
* @brief Transfer the contents of another ValidationResult into this one using
|
|
|
@@ -263,7 +278,7 @@ private:
|
|
|
if (std::visit([](auto const & v) { return v.empty(); }, message)) {
|
|
|
return;
|
|
|
}
|
|
|
- std::visit([](auto &msg) { sanitize(msg); }, message);
|
|
|
+ std::visit([](auto & msg) { sanitize(msg); }, message);
|
|
|
results_[where][schema_path].errors.emplace(name, std::move(message));
|
|
|
}
|
|
|
|
|
|
@@ -281,11 +296,11 @@ private:
|
|
|
if (std::visit([](auto const & v) { return v.empty(); }, message)) {
|
|
|
return;
|
|
|
}
|
|
|
- std::visit([](auto &msg) { sanitize(msg); }, message);
|
|
|
+ std::visit([](auto & msg) { sanitize(msg); }, message);
|
|
|
results_[where][schema_path].annotations.emplace(name, std::move(message));
|
|
|
}
|
|
|
|
|
|
- static void sanitize(std::string &message) {
|
|
|
+ static void sanitize(std::string & message) {
|
|
|
for (auto it = message.begin(); it != message.end(); ++it) {
|
|
|
if (*it == '"' || *it == '\\') {
|
|
|
it = ++message.insert(it, '\\');
|
|
|
@@ -293,8 +308,8 @@ private:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- static void sanitize(std::vector<std::string> &message) {
|
|
|
- std::ranges::for_each(message, [](std::string &val) { sanitize(val); });
|
|
|
+ static void sanitize(std::vector<std::string> & message) {
|
|
|
+ std::ranges::for_each(message, [](std::string & val) { sanitize(val); });
|
|
|
}
|
|
|
};
|
|
|
}
|