diff --git a/src/core/utils.js b/src/core/utils.js index fce58316f91..814737cb5b6 100644 --- a/src/core/utils.js +++ b/src/core/utils.js @@ -429,11 +429,12 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe let minItems = schema.get("minItems") let pattern = schema.get("pattern") - const needsExplicitConstraintValidation = type === "array" const schemaRequiresValue = requiredByParam || requiredBySchema const hasValue = value !== undefined && value !== null const isValidEmpty = !schemaRequiresValue && !hasValue + const needsExplicitConstraintValidation = hasValue && type === "array" + const requiresFurtherValidation = schemaRequiresValue || needsExplicitConstraintValidation diff --git a/test/unit/core/utils.js b/test/unit/core/utils.js index e567f93a33c..a22891e3dcf 100644 --- a/test/unit/core/utils.js +++ b/test/unit/core/utils.js @@ -772,6 +772,39 @@ describe("utils", () => { value = [] assertValidateParam(param, value, []) + // valid, empty array, with validation constraint + param = { + required: false, + schema: { + type: "array", + minItems: 1 + } + } + value = undefined + assertValidateOas3Param(param, value, []) + + // invalid, empty array, with minItems validation constraint + param = { + required: false, + schema: { + type: "array", + minItems: 2 + } + } + value = ["12"] + assertValidateOas3Param(param, value, ["Array must contain at least 2 items"]) + + // valid, valid array with satisfied minItems validation constraint + param = { + required: false, + schema: { + type: "array", + minItems: 1 + } + } + value = ["probe"] + assertValidateOas3Param(param, value, []) + // invalid, items do not match correct type param = { required: false,