|
|
@@ -12,6 +12,7 @@
|
|
|
#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/schema.h>
|
|
|
#include <jvalidate/status.h>
|
|
|
+#include <jvalidate/validation_config.h>
|
|
|
#include <jvalidate/validation_result.h>
|
|
|
|
|
|
#define NOOP_UNLESS_TYPE(etype) \
|
|
|
@@ -23,15 +24,19 @@ class ValidationVisitor : public constraint::ConstraintVisitor {
|
|
|
private:
|
|
|
A document_;
|
|
|
detail::Pointer where_;
|
|
|
+
|
|
|
schema::Node const & schema_;
|
|
|
+
|
|
|
ValidationResult * result_;
|
|
|
ValidationResult * local_result_;
|
|
|
+
|
|
|
+ ValidationConfig const & cfg_;
|
|
|
std::unordered_map<std::string, RE> & regex_cache_;
|
|
|
|
|
|
public:
|
|
|
- ValidationVisitor(A const & json, schema::Node const & schema,
|
|
|
+ ValidationVisitor(A const & json, schema::Node const & schema, ValidationConfig const & cfg,
|
|
|
std::unordered_map<std::string, RE> & regex_cache, ValidationResult * result)
|
|
|
- : ValidationVisitor(json, schema, {}, regex_cache, result) {}
|
|
|
+ : ValidationVisitor(json, schema, cfg, regex_cache, {}, result) {}
|
|
|
|
|
|
Status visit(constraint::TypeConstraint const & cons) const {
|
|
|
return cons.types.contains(document_.type());
|
|
|
@@ -42,9 +47,11 @@ public:
|
|
|
}
|
|
|
|
|
|
Status visit(constraint::EnumConstraint const & cons) const {
|
|
|
+ auto is_equal = [this](auto const & frozen) {
|
|
|
+ return document_.equals(frozen, cfg_.strict_equality);
|
|
|
+ };
|
|
|
for (auto const & option : cons.enumeration) {
|
|
|
- // TODO(samjaffe): Strictness
|
|
|
- if (option->apply([this](auto const & frozen) { return document_.equals(frozen); })) {
|
|
|
+ if (option->apply(is_equal)) {
|
|
|
return Status::Accept;
|
|
|
}
|
|
|
}
|
|
|
@@ -389,7 +396,7 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Status validate() const {
|
|
|
+ Status validate() {
|
|
|
if (schema_.rejects_all()) {
|
|
|
return Status::Reject;
|
|
|
}
|
|
|
@@ -421,14 +428,17 @@ public:
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- ValidationVisitor(A const & json, detail::Pointer const & where, schema::Node const & schema,
|
|
|
- std::unordered_map<std::string, RE> & regex_cache, ValidationResult * result,
|
|
|
+ ValidationVisitor(A const & json, schema::Node const & schema, ValidationConfig const & cfg,
|
|
|
+ std::unordered_map<std::string, RE> & regex_cache,
|
|
|
+ detail::Pointer const & where, ValidationResult * result,
|
|
|
ValidationResult * local_result = nullptr)
|
|
|
- : document_(json), where_(where), schema_(schema), regex_cache_(regex_cache), result_(result),
|
|
|
- local_result_(local_result ?: result_) {}
|
|
|
+ : document_(json), where_(where), schema_(schema), cfg_(cfg), regex_cache_(regex_cache),
|
|
|
+ result_(result), local_result_(local_result ?: result_) {}
|
|
|
|
|
|
Status validate_subschema(schema::Node const * subschema) const {
|
|
|
- return CRTP(document_, *subschema, where_, regex_cache_, result_, local_result_).validate();
|
|
|
+ return ValidationVisitor(document_, *subschema, cfg_, regex_cache_, where_, result_,
|
|
|
+ local_result_)
|
|
|
+ .validate();
|
|
|
}
|
|
|
|
|
|
template <typename K>
|
|
|
@@ -437,7 +447,8 @@ private:
|
|
|
ValidationResult next;
|
|
|
ValidationResult * pnext = result_ ? &next : nullptr;
|
|
|
|
|
|
- auto status = CRTP(document, *subschema, where_ / key, regex_cache_, pnext).validate();
|
|
|
+ auto status =
|
|
|
+ ValidationVisitor(document, *subschema, cfg_, regex_cache_, where_ / key, pnext).validate();
|
|
|
if (status != Status::Noop and local_result_) {
|
|
|
local_result_->record(key);
|
|
|
}
|