fix: array constraint validation only if value was provided (#7112)
This commit is contained in:
@@ -429,11 +429,12 @@ function validateValueBySchema(value, schema, requiredByParam, bypassRequiredChe
|
|||||||
let minItems = schema.get("minItems")
|
let minItems = schema.get("minItems")
|
||||||
let pattern = schema.get("pattern")
|
let pattern = schema.get("pattern")
|
||||||
|
|
||||||
const needsExplicitConstraintValidation = type === "array"
|
|
||||||
const schemaRequiresValue = requiredByParam || requiredBySchema
|
const schemaRequiresValue = requiredByParam || requiredBySchema
|
||||||
const hasValue = value !== undefined && value !== null
|
const hasValue = value !== undefined && value !== null
|
||||||
const isValidEmpty = !schemaRequiresValue && !hasValue
|
const isValidEmpty = !schemaRequiresValue && !hasValue
|
||||||
|
|
||||||
|
const needsExplicitConstraintValidation = hasValue && type === "array"
|
||||||
|
|
||||||
const requiresFurtherValidation =
|
const requiresFurtherValidation =
|
||||||
schemaRequiresValue
|
schemaRequiresValue
|
||||||
|| needsExplicitConstraintValidation
|
|| needsExplicitConstraintValidation
|
||||||
|
|||||||
@@ -772,6 +772,39 @@ describe("utils", () => {
|
|||||||
value = []
|
value = []
|
||||||
assertValidateParam(param, 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
|
// invalid, items do not match correct type
|
||||||
param = {
|
param = {
|
||||||
required: false,
|
required: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user