Skip to content
Open
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
11 changes: 11 additions & 0 deletions src/core/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,17 @@ export const validateParam = (param, value, { isOAS3 = false, bypassRequiredChec
parameterContentMediaType
} = getParameterSchema(param, { isOAS3 })

// Compose anyOf/oneOf schemas: if the schema lacks a direct type but has
// anyOf or oneOf, derive the type from the first sub-schema so that
// type-specific validation applies correctly.
if (paramDetails && !paramDetails.get("type")) {
const firstCompositeType =
paramDetails.getIn(["anyOf", 0, "type"]) || paramDetails.getIn(["oneOf", 0, "type"])
if (firstCompositeType) {
paramDetails = paramDetails.set("type", firstCompositeType)
}
}

return validateValueBySchema(value, paramDetails, paramRequired, bypassRequiredCheck, parameterContentMediaType, isOAS3)
}

Expand Down
69 changes: 69 additions & 0 deletions test/unit/core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,75 @@ describe("utils", () => {
value = undefined
assertValidateParam(param, value, ["Required field is not provided"])
})

it("validates required OAS3 parameters with anyOf schema", () => {
// missing value with anyOf should report required error
param = {
required: true,
schema: {
anyOf: [
{ type: "integer" },
{ type: "string" }
]
}
}
value = undefined
assertValidateOas3Param(param, value, ["Required field is not provided"])

// valid integer value with anyOf
param = {
required: true,
schema: {
anyOf: [
{ type: "integer" },
{ type: "string" }
]
}
}
value = 123
assertValidateOas3Param(param, value, [])

// valid string value with anyOf (matches second sub-schema type via first)
param = {
required: true,
schema: {
anyOf: [
{ type: "string" },
{ type: "integer" }
]
}
}
value = "hello"
assertValidateOas3Param(param, value, [])
})

it("validates required OAS3 parameters with oneOf schema", () => {
// missing value with oneOf should report required error
param = {
required: true,
schema: {
oneOf: [
{ type: "integer" },
{ type: "string" }
]
}
}
value = undefined
assertValidateOas3Param(param, value, ["Required field is not provided"])

// valid integer value with oneOf
param = {
required: true,
schema: {
oneOf: [
{ type: "integer" },
{ type: "string" }
]
}
}
value = 123
assertValidateOas3Param(param, value, [])
})
})

describe("fromJSOrdered", () => {
Expand Down