Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions test/unit/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down