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 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({

Loading…
Cancel
Save