|
@@ -11,6 +11,7 @@
|
|
|
#include <jvalidate/constraint/visitor.h>
|
|
#include <jvalidate/constraint/visitor.h>
|
|
|
#include <jvalidate/detail/expect.h>
|
|
#include <jvalidate/detail/expect.h>
|
|
|
#include <jvalidate/detail/iostream.h>
|
|
#include <jvalidate/detail/iostream.h>
|
|
|
|
|
+#include <jvalidate/detail/number.h>
|
|
|
#include <jvalidate/detail/pointer.h>
|
|
#include <jvalidate/detail/pointer.h>
|
|
|
#include <jvalidate/forward.h>
|
|
#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/schema.h>
|
|
#include <jvalidate/schema.h>
|
|
@@ -20,7 +21,8 @@
|
|
|
|
|
|
|
|
#define VISITED(type) std::get<std::unordered_set<type>>(*visited_)
|
|
#define VISITED(type) std::get<std::unordered_set<type>>(*visited_)
|
|
|
|
|
|
|
|
-#define NOOP_UNLESS_TYPE(etype) RETURN_UNLESS(adapter::Type::etype & document_.type(), Status::Noop)
|
|
|
|
|
|
|
+#define NOOP_UNLESS_TYPE(etype) \
|
|
|
|
|
+ RETURN_UNLESS(adapter::Type::etype == document_.type(), Status::Noop)
|
|
|
|
|
|
|
|
#define BREAK_EARLY_IF_NO_RESULT_TREE() \
|
|
#define BREAK_EARLY_IF_NO_RESULT_TREE() \
|
|
|
do { \
|
|
do { \
|
|
@@ -57,7 +59,14 @@ public:
|
|
|
Status visit(constraint::TypeConstraint const & cons) const {
|
|
Status visit(constraint::TypeConstraint const & cons) const {
|
|
|
adapter::Type const type = document_.type();
|
|
adapter::Type const type = document_.type();
|
|
|
for (adapter::Type const accept : cons.types) {
|
|
for (adapter::Type const accept : cons.types) {
|
|
|
- if (accept & type) {
|
|
|
|
|
|
|
+ if (type == accept) {
|
|
|
|
|
+ return Status::Accept;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (accept == adapter::Type::Number && type == adapter::Type::Integer) {
|
|
|
|
|
+ return Status::Accept;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (accept == adapter::Type::Integer && type == adapter::Type::Number &&
|
|
|
|
|
+ detail::is_json_integer(document_.as_number())) {
|
|
|
return Status::Accept;
|
|
return Status::Accept;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -181,7 +190,9 @@ public:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Status visit(constraint::MultipleOfConstraint const & cons) const {
|
|
Status visit(constraint::MultipleOfConstraint const & cons) const {
|
|
|
- NOOP_UNLESS_TYPE(Number);
|
|
|
|
|
|
|
+ adapter::Type const type = document_.type();
|
|
|
|
|
+ RETURN_UNLESS(type == adapter::Type::Number || type == adapter::Type::Integer, Status::Noop);
|
|
|
|
|
+
|
|
|
if (double value = document_.as_number(); not cons(value)) {
|
|
if (double value = document_.as_number(); not cons(value)) {
|
|
|
add_error("number ", value, " is not a multiple of ", cons.value);
|
|
add_error("number ", value, " is not a multiple of ", cons.value);
|
|
|
return false;
|
|
return false;
|