Description
OpenAPI 2.0 file parameters use form encodings. The specification permits multipart/form-data and application/x-www-form-urlencoded.
Potential impact
If consumes advertises the wrong media type, generated clients may send uploads the server rejects.
Remediation
Set in: formData on the file parameter. Choose the encoding the server accepts, usually multipart/form-data for files. An operation’s consumes overrides the global setting.
Examples
The revised POST changes consumes from application/json to multipart/form-data for the File field.
Before
json
{
"paths": {
"/": {
"post": {
"parameters": [
{
"name": "File",
"type": "file",
"in": "formData"
}
],
"consumes": [
"application/json"
]
}
}
}
}
After
json
{
"paths": {
"/": {
"post": {
"parameters": [
{
"name": "File",
"type": "file",
"in": "formData"
}
],
"consumes": [
"multipart/form-data"
]
}
}
}
}