From 4ebbc042aeec9a7db2edcee1d742e734fe4ddeb6 Mon Sep 17 00:00:00 2001 From: kyle Date: Mon, 2 Sep 2019 10:06:55 -0700 Subject: [PATCH] fix: 2.0 object parameter validation (#5583) --- src/core/utils.js | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 767c81af89e..0be1f097dda 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -498,6 +498,7 @@ export const validatePattern = (val, rxPattern) => { // validation of parameters before execute export const validateParam = (param, value, { isOAS3 = false, bypassRequiredCheck = false } = {}) => { + let errors = [] let required = param.get("required") @@ -527,31 +528,23 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec let booleanCheck = type === "boolean" && (value || value === false) let numberCheck = type === "number" && (value || value === 0) let integerCheck = type === "integer" && (value || value === 0) - - let oas3ObjectCheck = false - - if(isOAS3 && type === "object") { - if(typeof value === "object" && value !== null) { - oas3ObjectCheck = true - } else if(typeof value === "string") { - oas3ObjectCheck = true - } - // Disabled because `validateParam` doesn't consider the MediaType of the - // `Parameter.content` hint correctly. - // } else if(typeof value === "string") { - // try { - // JSON.parse(value) - // oas3ObjectCheck = true - // } catch(e) { - // errors.push("Parameter string value must be valid JSON") - // return errors - // } - // } - } + let objectCheck = type === "object" && typeof value === "object" && value !== null + let objectStringCheck = type === "object" && typeof value === "string" && value + + // if(type === "object" && typeof value === "string") { + // // Disabled because `validateParam` doesn't consider the MediaType of the + // // `Parameter.content` hint correctly. + // try { + // JSON.parse(value) + // } catch(e) { + // errors.push("Parameter string value must be valid JSON") + // return errors + // } + // } const allChecks = [ stringCheck, arrayCheck, listCheck, fileCheck, booleanCheck, - numberCheck, integerCheck, oas3ObjectCheck + numberCheck, integerCheck, objectCheck, objectStringCheck, ] const passedAnyCheck = allChecks.some(v => !!v)