To take default values into account, set them before check
This commit is contained in:
parent
0dca07bdf8
commit
f76274122b
@ -814,6 +814,17 @@ class object : public schema
|
|||||||
|
|
||||||
void validate(const json::json_pointer &ptr, json &instance, error_handler &e) const override
|
void validate(const json::json_pointer &ptr, json &instance, error_handler &e) const override
|
||||||
{
|
{
|
||||||
|
// reverse search
|
||||||
|
for (auto const &prop : properties_) {
|
||||||
|
const auto finding = instance.find(prop.first);
|
||||||
|
if (instance.end() == finding) { // if the prop is not in the instance
|
||||||
|
const auto &defaultValue = prop.second->defaultValue(ptr, instance, e);
|
||||||
|
if (!defaultValue.empty()) { // if default value is available
|
||||||
|
instance[prop.first] = defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (maxProperties_.first && instance.size() > maxProperties_.second)
|
if (maxProperties_.first && instance.size() > maxProperties_.second)
|
||||||
e.error(ptr, instance, "too many properties");
|
e.error(ptr, instance, "too many properties");
|
||||||
|
|
||||||
@ -857,17 +868,6 @@ class object : public schema
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// reverse search
|
|
||||||
for (auto const &prop : properties_) {
|
|
||||||
const auto finding = instance.find(prop.first);
|
|
||||||
if (instance.end() == finding) { // if the prop is not in the instance
|
|
||||||
const auto &defaultValue = prop.second->defaultValue(ptr, instance, e);
|
|
||||||
if (!defaultValue.empty()) { // if default value is available
|
|
||||||
instance[prop.first] = defaultValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (auto &dep : dependencies_) {
|
for (auto &dep : dependencies_) {
|
||||||
auto prop = instance.find(dep.first);
|
auto prop = instance.find(dep.first);
|
||||||
if (prop != instance.end()) // if dependency-property is present in instance
|
if (prop != instance.end()) // if dependency-property is present in instance
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user