Description
A numeric field can pass schema validation even when it falls below the API’s permitted range, such as a negative item count.
Potential impact
If the server accepts the value, calculations or later processing can fail.
Remediation
If your API sets a lower bound, enforce it on the server. Add minimum for that field unless an enum or referenced schema already supplies the bound. The minimum can be negative.
Examples
The example sets minimum: 0 on code, so zero is valid and negative integers are rejected.
Before
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32"
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"minimum": 0
}
}
}
}
}
}