Cloud Code validator issue with required: false (#7353)

* Only check the type of a parameter in the validator when the parameter is set to required or is not null

* Added test cases. Don't check type or options if required=false and no default value is set

* Added test cases. Don't check type or options if required=false and no default value is set

* Update const optional
This commit is contained in:
Rikard Teodorsson
2021-04-19 07:22:23 +02:00
committed by GitHub
parent 25690ad515
commit 64fc04cc26
2 changed files with 122 additions and 8 deletions

View File

@@ -724,15 +724,18 @@ async function builtInTriggerValidator(options, request, auth) {
if (opt.required) {
requiredParam(key);
}
if (opt.type) {
const type = getType(opt.type);
const valType = Array.isArray(val) ? 'array' : typeof val;
if (valType !== type) {
throw `Validation failed. Invalid type for ${key}. Expected: ${type}`;
const optional = !opt.required && val === undefined;
if (!optional) {
if (opt.type) {
const type = getType(opt.type);
const valType = Array.isArray(val) ? 'array' : typeof val;
if (valType !== type) {
throw `Validation failed. Invalid type for ${key}. Expected: ${type}`;
}
}
if (opt.options) {
optionPromises.push(validateOptions(opt, key, val));
}
}
if (opt.options) {
optionPromises.push(validateOptions(opt, key, val));
}
}
}