Description
Use the optional format field when the client and server need to agree on numeric size or precision.
Potential impact
Tools can otherwise generate different types, leading to truncated values or differences in serialization.
Remediation
Choose int32 or int64 for an integer, or float or double for a number. Check the types your tools generate. Set the field’s permitted range with minimum and maximum.
Examples
The example adds int32 to code. Its permitted range stays 0 through 50.
Before
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"minimum": 0,
"maximum": 50
}
}
}
}
}
}
After
json
{
"openapi": "3.0.0",
"components": {
"schemas": {
"GeneralError": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"format": "int32",
"minimum": 0,
"maximum": 50
}
}
}
}
}
}