Description
A value listed in enum must also match the schema’s type to pass validation. An OpenAPI 3.0 schema that declares its type can also accept a null value if it sets nullable: true and includes null in enum.
Potential impact
- A request or response can fail validation even when it uses a listed value.
- Documentation or generated clients may suggest values the schema rejects.
Remediation
Update enum or type to match the values the API accepts or returns. Check that those values also satisfy any other constraints.
Examples
These excerpts show an OpenAPI 3.0 response schema and omit info. The first schema requires a number and lists only the string "black", so no value passes validation.
Before
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"201": {
"description": "Created",
"content": {
"text/html": {
"schema": {
"type": "number",
"enum": [
"black"
]
}
}
}
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"paths": {
"/": {
"get": {
"responses": {
"201": {
"description": "Created",
"content": {
"text/html": {
"schema": {
"type": "number",
"enum": [
1,
2,
3
]
}
}
}
}
}
}
}
}
}
The revised schema accepts the numbers 1, 2 and 3.