mirror of
https://github.com/tristanpenman/valijson.git
synced 2024-12-13 10:32:58 +01:00
Implement draft 3 divisibleBy constraint based on draft 4 multipleOf constraint
This commit is contained in:
parent
04cebebcfd
commit
1ea6c9b185
@ -102,6 +102,14 @@ public:
|
||||
schema.addConstraint(makeDependenciesConstraint(itr->second, deref));
|
||||
}
|
||||
|
||||
if ((itr = object.find("divisibleBy")) != object.end()) {
|
||||
if (version == kDraft3) {
|
||||
schema.addConstraint(makeMultipleOfConstraint(itr->second));
|
||||
} else {
|
||||
throw std::runtime_error("'divisibleBy' constraint not valid after draft 3");
|
||||
}
|
||||
}
|
||||
|
||||
if ((itr = object.find("enum")) != object.end()) {
|
||||
schema.addConstraint(makeEnumConstraint(itr->second));
|
||||
}
|
||||
@ -168,7 +176,11 @@ public:
|
||||
}
|
||||
|
||||
if ((itr = object.find("multipleOf")) != object.end()) {
|
||||
schema.addConstraint(makeMultipleOfConstraint(itr->second));
|
||||
if (version == kDraft3) {
|
||||
throw std::runtime_error("'multipleOf' constraint not available in draft 3");
|
||||
} else {
|
||||
schema.addConstraint(makeMultipleOfConstraint(itr->second));
|
||||
}
|
||||
}
|
||||
|
||||
if ((itr = object.find("not")) != object.end()) {
|
||||
@ -785,7 +797,7 @@ private:
|
||||
/**
|
||||
* @brief Make a new MultipleOfConstraint object.
|
||||
*
|
||||
* @param node JSON node containing an integer value that a value must
|
||||
* @param node JSON node containing an numeric value that a value must
|
||||
* be divisible by.
|
||||
*
|
||||
* @return pointer to a new MultipleOfConstraint that belongs to the
|
||||
|
@ -634,7 +634,9 @@ public:
|
||||
if (!target.asDouble(d)) {
|
||||
if (results) {
|
||||
results->pushError(context, "Value could not be converted "
|
||||
"to a number for multipleOf check");
|
||||
"to a number to check if it is a multiple of " +
|
||||
boost::lexical_cast<std::string>(
|
||||
constraint.multipleOf));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -643,7 +645,9 @@ public:
|
||||
if (!target.asInteger(i)) {
|
||||
if (results) {
|
||||
results->pushError(context, "Value could not be converted "
|
||||
"to a number for multipleOf check");
|
||||
"to a number to check if it is a multiple of " +
|
||||
boost::lexical_cast<std::string>(
|
||||
constraint.multipleOf));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -139,6 +139,11 @@ TEST_F(TestValidator, Draft3_Dependencies)
|
||||
processDraft3TestFile(TEST_SUITE_DIR "draft3/dependencies.json");
|
||||
}
|
||||
|
||||
TEST_F(TestValidator, Draft3_DivisibleBy)
|
||||
{
|
||||
processDraft3TestFile(TEST_SUITE_DIR "draft3/divisibleBy.json");
|
||||
}
|
||||
|
||||
TEST_F(TestValidator, Draft3_Enum)
|
||||
{
|
||||
processDraft3TestFile(TEST_SUITE_DIR "draft3/enum.json");
|
||||
|
Loading…
Reference in New Issue
Block a user