Make sure to include extraneous properties in the result value, when allowed

master
Sven Slootweg 4 years ago
parent a933fce273
commit c3812585b9

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

Loading…
Cancel
Save