diff --git a/core/server/api/shared/validators/input/all.js b/core/server/api/shared/validators/input/all.js index fd0153b732..0b060f214c 100644 --- a/core/server/api/shared/validators/input/all.js +++ b/core/server/api/shared/validators/input/all.js @@ -38,6 +38,11 @@ const validate = (config, attrs) => { _.each(attrs, (value, key) => { debug(key, value); + if (GLOBAL_VALIDATORS[key]) { + debug('global validation'); + errors = errors.concat(validation.validate(value, key, GLOBAL_VALIDATORS[key])); + } + if (config && config[key]) { const allowedValues = Array.isArray(config[key]) ? config[key] : config[key].values; @@ -53,9 +58,6 @@ const validate = (config, attrs) => { errors.push(new common.errors.ValidationError()); } } - } else if (GLOBAL_VALIDATORS[key]) { - debug('global validation'); - errors = errors.concat(validation.validate(value, key, GLOBAL_VALIDATORS[key])); } }); diff --git a/core/test/unit/api/shared/validators/input/all_spec.js b/core/test/unit/api/shared/validators/input/all_spec.js index ff10c6ed59..3c7124a07c 100644 --- a/core/test/unit/api/shared/validators/input/all_spec.js +++ b/core/test/unit/api/shared/validators/input/all_spec.js @@ -38,6 +38,29 @@ describe('Unit: api/shared/validators/input/all', function () { }); }); + it('should run global validations on an type that has validation defined', function () { + const frame = { + options: { + slug: 'not a valid slug %%%%% http://', + } + }; + + const apiConfig = { + options: { + slug: { + required: true + } + } + }; + + return shared.validators.input.all.all(apiConfig, frame) + .then(() => { + throw new Error('Should not resolve'); + }, (err) => { + should.exist(err); + }); + }); + it('default include array notation', function () { const frame = { options: {