swagger-ui
swagger-ui copied to clipboard
Encoding attribute is not respected on the request
Q&A
- OS: macOS
- Browser: chrome
- Version: 74
- Method of installation: composer
- Swagger-UI version: 3.10.0
- Swagger/OpenAPI version: OpenAPI 3.0
Content & configuration
Example Swagger/OpenAPI definition:
openapi: 3.0.0
info:
title: 'Test Swagger'
description: 'Test Swagger'
contact:
email: [email protected]
version: '1'
paths:
/api/v1/profile:
post:
tags:
- Profile
summary: 'profile of the user user'
requestBody:
description: 'Profile that needs to be stored'
content:
multipart/mixed:
schema:
properties:
avatar_image:
description: avatar_image
type: file
profile:
type: object
$ref: '#/components/schemas/Profile'
type: object
encoding:
profile:
contentType: application/json
responses:
201:
description: 'Profile that was registered.'
content:
application/json:
schema:
type: object
422:
description: 'Unprocessable Entity.'
content:
application/json:
schema:
type: object
security:
-
passport:
- '*'
components:
schemas:
Profile:
title: Profile
description: 'profile model'
required:
- email
- telephone
properties:
email:
schema: Profile
description: 'Email of the profile'
type: string
name:
schema: Profile
description: 'Name of the profile'
type: string
type: object
securitySchemes:
passport:
type: oauth2
description: 'Laravel passport oauth2 security.'
in: header
scheme: http
flows:
password:
authorizationUrl: 'http://swagger.test/oauth/authorize'
tokenUrl: 'http://swagger.test/oauth/token'
refreshUrl: 'http://swagger.test/token/refresh'
scopes: { }
tags:
-
name: Profile
description: 'Operations for the user profile'
Describe the bug you're encountering
To reproduce...
Steps to reproduce the behavior:
- Fill the blanks for the /api/v1/profile request
- Make the request
- The requests sends the following payload:
------WebKitFormBoundaryaSzepCtBw5Aiaiue
Content-Disposition: form-data; name="avatar_image"; filename="the-avatar_image.png"
Content-Type: image/png
------WebKitFormBoundaryaSzepCtBw5Aiaiue
Content-Disposition: form-data; name="profile"
{
"email": "[email protected]",
"name": "my name"
}
------WebKitFormBoundaryaSzepCtBw5Aiaiue--
Expected behavior
The payload should be
------WebKitFormBoundaryaSzepCtBw5Aiaiue
Content-Disposition: form-data; name="avatar_image"; filename="the-avatar_image.png"
Content-Type: image/png
------WebKitFormBoundaryaSzepCtBw5Aiaiue
Content-Disposition: form-data; name="profile"
Content-Type: application/json
{
"email": "[email protected]",
"name": "my name"
}
------WebKitFormBoundaryaSzepCtBw5Aiaiue--
Check that the profile attribute contains it's content-type as "application/json".
I have the same issue, please solve this.
Related (or duplicate): #4826, #6462
Any ETA on when will this be fixed?
PRs welcome.
Same issue, please solve it
Have same issue.
Is there a workaround?
Same issue here
Hello,
Same here. In fact it seems that All the "encoding definition" is NOT taken into account by swagger editor :(
Same problem here :(
Refer this workaround: https://github.com/swagger-api/swagger-ui/issues/6462
We are having same problem. Has this been resolved in SwaggerHub Cloud Enterprise ??
Hi everybody,
This issue has been addressed upstream in https://github.com/swagger-api/swagger-js/pull/3078
OpenAPI 3.x.y definition:
{
"openapi": "3.0.0",
"paths": {
"/upload/": {
"post": {
"tags": [
"upload"
],
"operationId": "upload",
"requestBody": {
"required": true,
"content": {
"multipart/form-data": {
"schema": {
"type": "object",
"properties": {
"options": {
"type": "object",
"properties": {
"some_array": {
"type": "array",
"items": {
"type": "string"
}
},
"max_bar": {
"type": "integer",
"default": 300
}
}
}
}
},
"encoding": {
"options": {
"contentType": "application/json; charset=utf-8"
}
}
}
}
}
}
}
}
}
Here is how the multipart/form-data request looked BEFORE:
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="options"
{"some_array":["string"],"max_bar":300}
Here is how the multipart/form-data request looked AFTER:
POST / HTTP/1.1
Content-Type: multipart/form-data; boundary=---------------------------9051914041544843365972754266
-----------------------------9051914041544843365972754266
Content-Disposition: form-data; name="options"; filename="blob"
Content-Type: application/json
{"some_array":["string"],"max_bar":300}
Every boundary now contains specific Content-Type header if defined. Note that filename is also present in every Content-Disposition header and always contains value of blob. This inclusion of filename cannot be avoided as this is the only way how to assign specific Content-Type for every boundary.
Addressed by https://github.com/swagger-api/swagger-ui/pull/9105
Addressed by #9105
Hi everybody.
Is any of you still experiencing the issue ? I am using org.webjars:swagger-ui:5.10.3 and the problem does not seem to be resolved. (Should have been fixed in version v5.3.0)