|
@@ -3,6 +3,7 @@
|
|
|
#include <regex>
|
|
#include <regex>
|
|
|
#include <unordered_map>
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
+#include <jvalidate/detail/on_block_exit.h>
|
|
|
#include <jvalidate/forward.h>
|
|
#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/status.h>
|
|
#include <jvalidate/status.h>
|
|
|
#include <jvalidate/validation_config.h>
|
|
#include <jvalidate/validation_config.h>
|
|
@@ -92,6 +93,7 @@ public:
|
|
|
bool validate(A const & json, ValidationResult * result = nullptr) {
|
|
bool validate(A const & json, ValidationResult * result = nullptr) {
|
|
|
EXPECT_M(not cfg_.construct_default_values,
|
|
EXPECT_M(not cfg_.construct_default_values,
|
|
|
"Cannot perform mutations on an immutable JSON Adapter");
|
|
"Cannot perform mutations on an immutable JSON Adapter");
|
|
|
|
|
+ detail::OnBlockExit _ = [&result, this]() { post_process(result); };
|
|
|
return static_cast<bool>(
|
|
return static_cast<bool>(
|
|
|
ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
|
}
|
|
}
|
|
@@ -111,6 +113,7 @@ public:
|
|
|
* schema to provide a record of all of the failures.
|
|
* schema to provide a record of all of the failures.
|
|
|
*/
|
|
*/
|
|
|
template <MutableAdapter A> bool validate(A const & json, ValidationResult * result = nullptr) {
|
|
template <MutableAdapter A> bool validate(A const & json, ValidationResult * result = nullptr) {
|
|
|
|
|
+ detail::OnBlockExit _ = [&result, this]() { post_process(result); };
|
|
|
return static_cast<bool>(
|
|
return static_cast<bool>(
|
|
|
ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
ValidationVisitor(schema_, cfg_, regex_, extension_, result).validate(json));
|
|
|
}
|
|
}
|
|
@@ -133,5 +136,15 @@ public:
|
|
|
bool validate(JSON & json, ValidationResult * result = nullptr) {
|
|
bool validate(JSON & json, ValidationResult * result = nullptr) {
|
|
|
return validate(adapter::AdapterFor<JSON>(json), result);
|
|
return validate(adapter::AdapterFor<JSON>(json), result);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+private:
|
|
|
|
|
+ void post_process(ValidationResult *& result) const {
|
|
|
|
|
+ if (result == nullptr) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (cfg_.only_return_results_with_error) {
|
|
|
|
|
+ *result = result->only_errors();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
};
|
|
};
|
|
|
}
|
|
}
|