diff --git a/lib/validation.js b/lib/validation.js index e1e1b96..175fb49 100644 --- a/lib/validation.js +++ b/lib/validation.js @@ -176,11 +176,23 @@ module.exports.process = function (validationModel, req, options) { keys.splice(index, 1); } }); - if (options.forbidUndefinedVariables === true) { - keys.forEach(function(key) { - addError(_createError(realScope, key, { name: "undefinedVariable" })); - }); - } + if (options.forbidUndefinedVariables === true) { + keys.forEach(function(key) { + var invalid = true; + + // check if key exist in some other scope in the validationModel + _.each(validationModel, function (validationModelScope) { + if (key in validationModelScope) { + invalid = false; + } + }); + + // flag key as undefined if it didn't show up in another scope + if (invalid) { + addError(_createError(realScope, key, { name: "undefinedVariable" })); + } + }); + } } }); return errors;