Description
In OpenAPI 2.0, body and formData both describe the request body. An operation must choose one.
Potential impact
Mixing the two can cause validation to fail or clients to send a body the server cannot read.
Remediation
For a form, use in: formData for each field, specify its type, and set consumes to the form encoding the server accepts. For a structured body, use a single in: body parameter with a schema.
Examples
Both examples specify application/x-www-form-urlencoded. The revision makes limit2 an integer form field alongside minlimit.
Before
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
},
"parameters": [
{
"name": "limit2",
"in": "body",
"description": "max records to return",
"required": true,
"schema": {
"type": "object"
}
},
{
"name": "minlimit",
"in": "formData",
"description": "min records to return",
"required": true,
"type": "integer"
}
],
"consumes": [
"application/x-www-form-urlencoded"
]
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "formData",
"description": "max records to return",
"required": true,
"type": "integer"
}
}
}
After
json
{
"swagger": "2.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0"
},
"paths": {
"/": {
"post": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response"
}
},
"parameters": [
{
"name": "limit2",
"in": "formData",
"description": "max records to return",
"required": true,
"type": "integer"
},
{
"name": "minlimit",
"in": "formData",
"description": "min records to return",
"required": true,
"type": "integer"
}
],
"consumes": [
"application/x-www-form-urlencoded"
]
}
}
},
"parameters": {
"limitParam": {
"name": "limit",
"in": "formData",
"description": "max records to return",
"required": true,
"type": "integer"
}
}
}