|
|
@@ -17,6 +17,7 @@
|
|
|
#include <jvalidate/detail/number.h>
|
|
|
#include <jvalidate/detail/pointer.h>
|
|
|
#include <jvalidate/detail/scoped_state.h>
|
|
|
+#include <jvalidate/detail/string_adapter.h>
|
|
|
#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/schema.h>
|
|
|
#include <jvalidate/status.h>
|
|
|
@@ -45,11 +46,13 @@
|
|
|
} while (false)
|
|
|
|
|
|
namespace jvalidate {
|
|
|
+JVALIDATE_TRIBOOL_TYPE(StoreResults, ForValid, ForInvalid, ForAnything);
|
|
|
+
|
|
|
template <Adapter A, RegexEngine RE>
|
|
|
class ValidationVisitor : public constraint::ConstraintVisitor {
|
|
|
private:
|
|
|
+ template <Adapter, RegexEngine> friend class ValidationVisitor;
|
|
|
using VisitedAnnotation = std::tuple<std::unordered_set<size_t>, std::unordered_set<std::string>>;
|
|
|
- JVALIDATE_TRIBOOL_TYPE(StoreResults, ForValid, ForInvalid, ForAnything);
|
|
|
|
|
|
private:
|
|
|
A document_;
|
|
|
@@ -505,8 +508,8 @@ public:
|
|
|
Status rval = Status::Accept;
|
|
|
for (auto const & [key, _] : document_.as_object()) {
|
|
|
// TODO(samjaffe): Should we prefer a std::string adapter like valijson?
|
|
|
- typename A::value_type key_json{key};
|
|
|
- rval &= validate_subschema_on(cons.key_schema, A(key_json), std::string("$$key"));
|
|
|
+ rval &=
|
|
|
+ validate_subschema_on(cons.key_schema, detail::StringAdapter(key), std::string("$$key"));
|
|
|
}
|
|
|
return rval;
|
|
|
}
|
|
|
@@ -650,7 +653,7 @@ private:
|
|
|
if (not result_) {
|
|
|
return false;
|
|
|
}
|
|
|
- switch (tracking_) {
|
|
|
+ switch (*tracking_) {
|
|
|
case StoreResults::ForAnything:
|
|
|
return stat != Status::Noop;
|
|
|
case StoreResults::ForValid:
|
|
|
@@ -739,15 +742,16 @@ private:
|
|
|
* @return The status of validating the current instance against the
|
|
|
* subschema.
|
|
|
*/
|
|
|
- template <typename K>
|
|
|
- Status validate_subschema_on(schema::Node const * subschema, A const & document,
|
|
|
+ template <Adapter A2, typename K>
|
|
|
+ Status validate_subschema_on(schema::Node const * subschema, A2 const & document,
|
|
|
K const & key) const {
|
|
|
ValidationResult result;
|
|
|
|
|
|
- ValidationVisitor next = *this;
|
|
|
- next.where_ /= key;
|
|
|
- std::tie(next.document_, next.schema_, next.result_, next.visited_) =
|
|
|
- std::forward_as_tuple(document, subschema, result_ ? &result : nullptr, nullptr);
|
|
|
+ ValidationVisitor<A2, RE> next{document, *subschema, cfg_, regex_cache_,
|
|
|
+ result_ ? &result : nullptr};
|
|
|
+ next.where_ = where_ / key;
|
|
|
+ next.schema_path_ = schema_path_;
|
|
|
+ next.tracking_ = tracking_;
|
|
|
|
|
|
auto status = next.validate();
|
|
|
if (status == Status::Accept and visited_) {
|