|
|
|
@ -54,18 +54,23 @@ module.exports = function hasShape(rules) {
|
|
|
|
|
let errors = [];
|
|
|
|
|
let newObject = {};
|
|
|
|
|
|
|
|
|
|
for (let [ key, rule ] of Object.entries(rules)) {
|
|
|
|
|
let value = object[key];
|
|
|
|
|
for (let [ key, value ] of Object.entries(object)) {
|
|
|
|
|
let rule = rules[key];
|
|
|
|
|
|
|
|
|
|
let { errors: keyErrors, newValue } = applyValidators(value, rule);
|
|
|
|
|
if (rule != null) {
|
|
|
|
|
let { errors: keyErrors, newValue } = applyValidators(value, rule);
|
|
|
|
|
|
|
|
|
|
let annotatedErrors = annotateErrors({
|
|
|
|
|
pathSegments: [ key ],
|
|
|
|
|
errors: keyErrors
|
|
|
|
|
});
|
|
|
|
|
let annotatedErrors = annotateErrors({
|
|
|
|
|
pathSegments: [ key ],
|
|
|
|
|
errors: keyErrors
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
errors.push(... annotatedErrors);
|
|
|
|
|
newObject[key] = newValue;
|
|
|
|
|
errors.push(... annotatedErrors);
|
|
|
|
|
newObject[key] = newValue;
|
|
|
|
|
} else {
|
|
|
|
|
// Extraneous property
|
|
|
|
|
newObject[key] = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return validationResult({
|
|
|
|
|