Description
A numeric field can pass schema validation even when it exceeds the quantity or amount your API accepts.
Potential impact
If the server accepts the value, calculations can produce incorrect results or fail.
Remediation
If your API sets an upper bound, enforce it on the server. Add maximum for that field unless an enum or referenced schema already supplies the bound.
Examples
The example adds maximum: 50 to code, which already has a minimum of 0.
Before
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"minimum": 0
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"minimum": 0,
"maximum": 50
}
}
}
}
}
}