Description
OpenAPI 3.0 encoding specifies per-property serialization for multipart or application/x-www-form-urlencoded request bodies. Each encoding key must name a property in the relevant schema. A setting for an absent property cannot describe the intended input.
Potential impact
- Required media type or serialization settings may not be applied to the input property.
- Tool validation may fail, or clients and servers may handle the input differently.
Remediation
Match each encoding key to a name in the schema’s properties. Remove unused entries and update related encodings and examples when properties are renamed. Check that actual requests use the intended serialization.
Examples
These excerpts define a reusable multipart request body. Connect the operation’s requestBody reference separately.
Before
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"contact": {
"name": "contact",
"url": "https://www.google.com/",
"email": "user@gmail.c"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"requestBodies": {
"ResponseExample": {
"description": "Upload body",
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"code": {
"type": "string",
"format": "binary"
},
"message": {
"type": "string"
}
},
"type": "object"
},
"encoding": {
"profileImage": {
"contentType": "image/png, image/jpeg"
}
}
}
}
}
}
}
}
After
{
"openapi": "3.0.0",
"info": {
"title": "Simple API Overview",
"version": "1.0.0",
"contact": {
"name": "contact",
"url": "https://www.google.com/",
"email": "user@gmail.c"
}
},
"paths": {
"/": {
"get": {
"operationId": "listVersionsv2",
"summary": "List API versions",
"responses": {
"200": {
"description": "200 response",
"content": {
"application/json": {
"examples": {
"foo": {
"value": {
"versions": [
{
"status": "CURRENT",
"updated": "2011-01-21T11:33:21Z",
"id": "v2.0",
"links": [
{
"href": "http://127.0.0.1:8774/v2/",
"rel": "self"
}
]
}
]
}
}
}
}
}
}
}
}
}
},
"components": {
"requestBodies": {
"ResponseExample": {
"description": "Upload body",
"content": {
"multipart/form-data": {
"schema": {
"properties": {
"code": {
"type": "string",
"format": "binary"
},
"message": {
"type": "string"
}
},
"type": "object"
},
"encoding": {
"code": {
"contentType": "image/png, image/jpeg"
}
}
}
}
}
}
}
}
The second example applies encoding to code instead of the absent profileImage property. It controls that multipart request property, not JSON responses.