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:

  1. Fill the blanks for the /api/v1/profile request
  2. Make the request
  3. 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

Most upvoted comments

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.