|
|
@@ -5,6 +5,7 @@
|
|
|
#include <map>
|
|
|
#include <ostream>
|
|
|
#include <string>
|
|
|
+#include <unordered_map>
|
|
|
#include <utility>
|
|
|
#include <variant>
|
|
|
#include <vector>
|
|
|
@@ -40,15 +41,15 @@ public:
|
|
|
*/
|
|
|
struct LocalResult {
|
|
|
bool valid = true;
|
|
|
- std::map<std::string, Annotation> errors;
|
|
|
- std::map<std::string, Annotation> annotations;
|
|
|
+ std::unordered_map<std::string, Annotation> errors;
|
|
|
+ std::unordered_map<std::string, Annotation> annotations;
|
|
|
};
|
|
|
|
|
|
static auto indent(size_t depth) { return std::string(depth * 2, ' '); }
|
|
|
|
|
|
private:
|
|
|
bool valid_;
|
|
|
- std::map<DocPointer, std::map<SchemaPointer, LocalResult>> results_;
|
|
|
+ std::unordered_map<DocPointer, std::unordered_map<SchemaPointer, LocalResult>> results_;
|
|
|
|
|
|
public:
|
|
|
/**
|
|
|
@@ -86,11 +87,14 @@ public:
|
|
|
* }
|
|
|
*/
|
|
|
friend std::ostream & operator<<(std::ostream & os, ValidationResult const & result) {
|
|
|
+ auto sorted = []<typename K, typename V>(std::unordered_map<K, V> const & container) {
|
|
|
+ return std::map<K, V const &>(container.begin(), container.end());
|
|
|
+ };
|
|
|
char const * div = "\n";
|
|
|
os << "{\n" << indent(1) << R"("valid": )" << (result.valid_ ? "true" : "false") << ',' << '\n';
|
|
|
os << indent(1) << R"("details": [)";
|
|
|
- for (auto const & [doc_path, by_schema] : result.results_) {
|
|
|
- for (auto const & [schema_path, local] : by_schema) {
|
|
|
+ for (auto const & [doc_path, by_schema] : sorted(result.results_)) {
|
|
|
+ for (auto const & [schema_path, local] : sorted(by_schema)) {
|
|
|
os << std::exchange(div, ",\n") << indent(2) << '{' << '\n';
|
|
|
os << indent(3) << R"("valid": )" << (local.valid ? "true" : "false") << ',' << '\n';
|
|
|
os << indent(3) << R"("evaluationPath": ")" << schema_path << '"' << ',' << '\n';
|
|
|
@@ -103,8 +107,7 @@ public:
|
|
|
return os << '\n' << indent(1) << ']' << '\n' << '}';
|
|
|
}
|
|
|
|
|
|
- static void print(std::ostream & os, std::map<std::string, Annotation> const & named,
|
|
|
- std::string_view name, int const depth) {
|
|
|
+ static void print(std::ostream & os, auto const & named, std::string_view name, int const depth) {
|
|
|
if (named.empty()) {
|
|
|
return;
|
|
|
}
|