diff --git a/src/json-validator.cpp b/src/json-validator.cpp index 9b8ab13..ee85e35 100644 --- a/src/json-validator.cpp +++ b/src/json-validator.cpp @@ -814,6 +814,17 @@ class object : public schema 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) 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_) { auto prop = instance.find(dep.first); if (prop != instance.end()) // if dependency-property is present in instance