|
@@ -14,6 +14,7 @@
|
|
|
#include <jvalidate/constraint/object_constraint.h>
|
|
#include <jvalidate/constraint/object_constraint.h>
|
|
|
#include <jvalidate/constraint/string_constraint.h>
|
|
#include <jvalidate/constraint/string_constraint.h>
|
|
|
|
|
|
|
|
|
|
+#include <jvalidate/detail/enumerate.h>
|
|
|
#include <jvalidate/detail/expect.h>
|
|
#include <jvalidate/detail/expect.h>
|
|
|
#include <jvalidate/detail/parser_context.h>
|
|
#include <jvalidate/detail/parser_context.h>
|
|
|
#include <jvalidate/detail/vocabulary.h>
|
|
#include <jvalidate/detail/vocabulary.h>
|
|
@@ -190,8 +191,7 @@ public:
|
|
|
std::vector<schema::Node const *> children;
|
|
std::vector<schema::Node const *> children;
|
|
|
|
|
|
|
|
std::set<adapter::Type> types;
|
|
std::set<adapter::Type> types;
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
if (subschema.type() != adapter::Type::String) {
|
|
if (subschema.type() != adapter::Type::String) {
|
|
|
children.push_back(context.child(subschema, index).node());
|
|
children.push_back(context.child(subschema, index).node());
|
|
|
} else if (subschema.as_string() == "any") {
|
|
} else if (subschema.as_string() == "any") {
|
|
@@ -199,16 +199,15 @@ public:
|
|
|
} else {
|
|
} else {
|
|
|
types.insert(to_type(subschema.as_string()));
|
|
types.insert(to_type(subschema.as_string()));
|
|
|
}
|
|
}
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return constraint::PolyConstraint::AnyOf(
|
|
|
|
|
- std::make_unique<constraint::TypeConstraint>(types),
|
|
|
|
|
- std::make_unique<constraint::AnyOfConstraint>(children));
|
|
|
|
|
|
|
+ auto rval = std::make_unique<constraint::AnyOfConstraint>(children);
|
|
|
|
|
+ rval->children.push_back(std::make_unique<constraint::TypeConstraint>(types));
|
|
|
|
|
+ return rval;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static pConstraint disallowDraft3(detail::ParserContext<A> const & context) {
|
|
static pConstraint disallowDraft3(detail::ParserContext<A> const & context) {
|
|
|
- return constraint::PolyConstraint::Not(typeDraft3(context));
|
|
|
|
|
|
|
+ return std::make_unique<constraint::NotConstraint>(typeDraft3(context));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static pConstraint extendsDraft3(detail::ParserContext<A> const & context) {
|
|
static pConstraint extendsDraft3(detail::ParserContext<A> const & context) {
|
|
@@ -218,10 +217,8 @@ public:
|
|
|
children.push_back(context.node());
|
|
children.push_back(context.node());
|
|
|
break;
|
|
break;
|
|
|
case adapter::Type::Array: {
|
|
case adapter::Type::Array: {
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto const & subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
children.push_back(context.child(subschema, index).node());
|
|
children.push_back(context.child(subschema, index).node());
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -265,10 +262,8 @@ public:
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
|
|
std::vector<schema::Node const *> rval;
|
|
std::vector<schema::Node const *> rval;
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return std::make_unique<constraint::AllOfConstraint>(rval);
|
|
return std::make_unique<constraint::AllOfConstraint>(rval);
|
|
@@ -278,10 +273,8 @@ public:
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
|
|
std::vector<schema::Node const *> rval;
|
|
std::vector<schema::Node const *> rval;
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return std::make_unique<constraint::AnyOfConstraint>(rval);
|
|
return std::make_unique<constraint::AnyOfConstraint>(rval);
|
|
@@ -291,10 +284,8 @@ public:
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
|
|
std::vector<schema::Node const *> rval;
|
|
std::vector<schema::Node const *> rval;
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return std::make_unique<constraint::OneOfConstraint>(rval);
|
|
return std::make_unique<constraint::OneOfConstraint>(rval);
|
|
@@ -401,10 +392,8 @@ public:
|
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
EXPECT(context.schema.type() == adapter::Type::Array);
|
|
|
|
|
|
|
|
std::vector<schema::Node const *> rval;
|
|
std::vector<schema::Node const *> rval;
|
|
|
- size_t index = 0;
|
|
|
|
|
- for (auto subschema : context.schema.as_array()) {
|
|
|
|
|
|
|
+ for (auto const & [index, subschema] : detail::enumerate(context.schema.as_array())) {
|
|
|
rval.push_back(context.child(subschema, index).node());
|
|
rval.push_back(context.child(subschema, index).node());
|
|
|
- ++index;
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return std::make_unique<constraint::TupleConstraint>(rval);
|
|
return std::make_unique<constraint::TupleConstraint>(rval);
|
|
@@ -521,8 +510,11 @@ public:
|
|
|
if (required.empty()) {
|
|
if (required.empty()) {
|
|
|
return properties(context);
|
|
return properties(context);
|
|
|
}
|
|
}
|
|
|
- return constraint::PolyConstraint::AllOf(
|
|
|
|
|
- properties(context), std::make_unique<constraint::RequiredConstraint>(std::move(required)));
|
|
|
|
|
|
|
+
|
|
|
|
|
+ std::vector<pConstraint> rval;
|
|
|
|
|
+ rval.push_back(properties(context));
|
|
|
|
|
+ rval.push_back(std::make_unique<constraint::RequiredConstraint>(std::move(required)));
|
|
|
|
|
+ return std::make_unique<constraint::AllOfConstraint>(std::move(rval));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static auto propertyNames(detail::ParserContext<A> const & context) {
|
|
static auto propertyNames(detail::ParserContext<A> const & context) {
|