Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding attribute is not respected on the request #5356

Closed
alejandrofloresm opened this issue May 17, 2019 · 15 comments
Closed

Encoding attribute is not respected on the request #5356

alejandrofloresm opened this issue May 17, 2019 · 15 comments

Comments

@alejandrofloresm
Copy link

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".

@sungtaek
Copy link

I have the same issue, please solve this.

@hkosova
Copy link
Contributor

hkosova commented Sep 2, 2019

Related (or duplicate): #4826, #6462

@kargath
Copy link

kargath commented Nov 26, 2019

Any ETA on when will this be fixed?

@webron
Copy link
Contributor

webron commented Nov 26, 2019

PRs welcome.

@RomanOrlov2
Copy link

Same issue, please solve it

@XhstormR
Copy link

Have same issue.

@Legion2
Copy link

Legion2 commented Nov 25, 2020

Is there a workaround?

@Warkanlock
Copy link

Same issue here

@dprincethg
Copy link

Hello,

Same here.
In fact it seems that All the "encoding definition" is NOT taken into account by swagger editor :(

@tamis-laan
Copy link

Same problem here :(

@nikhilraj6692
Copy link

Refer this workaround:
#6462

@LouCastaldo
Copy link

We are having same problem. Has this been resolved in SwaggerHub Cloud Enterprise ??

@char0n
Copy link
Member

char0n commented Aug 1, 2023

Hi everybody,

This issue has been addressed upstream in swagger-api/swagger-js#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.

@char0n char0n self-assigned this Aug 1, 2023
char0n added a commit to swagger-api/swagger-js that referenced this issue Aug 1, 2023
This change affects building requests from OpenAPI 3.x.y definitions.

Refs swagger-api/swagger-ui#5356
Refs swagger-api/swagger-ui#4826
Refs #2954
char0n added a commit that referenced this issue Aug 1, 2023
This change fixes both:

1. making multipart/form-data requests with content-type
   header for every individual boundary
2. generating correct CURL command for multipart/form-data
   request, allowing specifying content-type header for every
   individual boundary

Refs #4826
Refs #5356
@char0n
Copy link
Member

char0n commented Aug 1, 2023

Addressed by #9105

@char0n char0n closed this as completed Aug 1, 2023
char0n added a commit that referenced this issue Aug 1, 2023
This change fixes both:

1. making multipart/form-data requests with content-type
   header for every individual boundary
2. generating correct CURL command for multipart/form-data
   request, allowing specifying content-type header for every
   individual boundary

Refs #4826
Refs #5356
@LaFrimousse
Copy link

LaFrimousse commented Feb 13, 2024

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)

swagger-ui-version
Screenshot 2024-02-13 at 10 37 37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests