swagger-ui: 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: test@swagger.com
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": "myemail@test.com",
"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": "myemail@test.com",
"name": "my name"
}
------WebKitFormBoundaryaSzepCtBw5Aiaiue--
Check that the profile attribute contains it’s content-type as “application/json”.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 39
- Comments: 15 (4 by maintainers)
Commits related to this issue
- feat(http): respect Encoding Object while building requests (#3078) This change affects building requests from OpenAPI 3.x.y definitions. Refs https://github.com/swagger-api/swagger-ui/issues/5356... — committed to swagger-api/swagger-js by char0n a year ago
- feat: respect Encoding Object while building requests This change fixes both: 1. making multipart/form-data requests with content-type header for every individual boundary 2. generating correct C... — committed to swagger-api/swagger-ui by char0n a year ago
- feat: respect Encoding Object while building requests (#9105) This change fixes both: 1. making multipart/form-data requests with content-type header for every individual boundary 2. generati... — committed to swagger-api/swagger-ui by char0n a year ago
Same issue, please solve it
Hello,
Same here. In fact it seems that All the “encoding definition” is NOT taken into account by swagger editor 😦
I have the same issue, please solve this.