From 222054b3db0de620ac0c513f97c61adb18ebbd85 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Sun, 15 Sep 2019 12:01:11 -0700 Subject: [PATCH 1/2] rename `listCheck` -> `arrayListCheck` --- src/core/utils.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index 0be1f097dda..d528d31aeea 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -523,7 +523,7 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec // These checks should evaluate to true if there is a parameter let stringCheck = type === "string" && value let arrayCheck = type === "array" && Array.isArray(value) && value.length - let listCheck = type === "array" && Im.List.isList(value) && value.count() + let arrayListCheck = type === "array" && Im.List.isList(value) && value.count() let fileCheck = type === "file" && value instanceof win.File let booleanCheck = type === "boolean" && (value || value === false) let numberCheck = type === "number" && (value || value === 0) @@ -543,7 +543,7 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec // } const allChecks = [ - stringCheck, arrayCheck, listCheck, fileCheck, booleanCheck, + stringCheck, arrayCheck, arrayListCheck, fileCheck, booleanCheck, numberCheck, integerCheck, objectCheck, objectStringCheck, ] @@ -605,7 +605,7 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec } else if ( type === "array" ) { let itemType - if ( !listCheck || !value.count() ) { return errors } + if ( !arrayListCheck || !value.count() ) { return errors } itemType = paramDetails.getIn(["items", "type"]) From c93814693f55ffd9b7a9daed87f14ab0a83a2c71 Mon Sep 17 00:00:00 2001 From: Kyle Shockey Date: Sun, 15 Sep 2019 12:04:26 -0700 Subject: [PATCH 2/2] allow non-empty strings to quality a required array value --- src/core/utils.js | 5 +++-- test/mocha/core/utils.js | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/core/utils.js b/src/core/utils.js index d528d31aeea..f410d249bc4 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -524,6 +524,7 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec let stringCheck = type === "string" && value let arrayCheck = type === "array" && Array.isArray(value) && value.length let arrayListCheck = type === "array" && Im.List.isList(value) && value.count() + let arrayStringCheck = type === "array" && typeof value === "string" && value let fileCheck = type === "file" && value instanceof win.File let booleanCheck = type === "boolean" && (value || value === false) let numberCheck = type === "number" && (value || value === 0) @@ -543,8 +544,8 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec // } const allChecks = [ - stringCheck, arrayCheck, arrayListCheck, fileCheck, booleanCheck, - numberCheck, integerCheck, objectCheck, objectStringCheck, + stringCheck, arrayCheck, arrayListCheck, arrayStringCheck, fileCheck, + booleanCheck, numberCheck, integerCheck, objectCheck, objectStringCheck, ] const passedAnyCheck = allChecks.some(v => !!v) diff --git a/test/mocha/core/utils.js b/test/mocha/core/utils.js index fa26a38f22b..8372b9c0615 100644 --- a/test/mocha/core/utils.js +++ b/test/mocha/core/utils.js @@ -602,6 +602,14 @@ describe("utils", function() { } value = [] assertValidateParam(param, value, ["Required field is not provided"]) + + // invalid (empty) array, represented as a string + param = { + required: true, + type: "array" + } + value = "" + assertValidateParam(param, value, ["Required field is not provided"]) // invalid (not an array) param = { @@ -629,6 +637,14 @@ describe("utils", function() { } value = [1] assertValidateParam(param, value, []) + + // valid array, with no 'type' for items, represented as a string + param = { + required: true, + type: "array" + } + value = "[1]" + assertValidateParam(param, value, []) // valid array, items match type param = {