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

Incorrect request body when 'multipart/mixed' is used #2473

Open
plamen-dzhorev opened this issue Feb 23, 2022 · 1 comment
Open

Incorrect request body when 'multipart/mixed' is used #2473

plamen-dzhorev opened this issue Feb 23, 2022 · 1 comment

Comments

@plamen-dzhorev
Copy link

plamen-dzhorev commented Feb 23, 2022

Q&A (please complete the following information)

  • OS: Windows, macOS
  • Environment: Nodejs 12, any browser
  • Method of installation: npm
  • Swagger-Client version: 3.18
  • Swagger/OpenAPI version: OpenAPI 3.0

Content & configuration

Swagger/OpenAPI definition:

    requestBody:
        description: .....
        content:
          application/json:
            schema:
              $ref: 'certificate.yaml#/Certificate'
          multipart/mixed; boundary=BOUNDARY:
            schema:
              type: object
              properties:
                CertificateBody:
                  $ref: '#/Certificate'
                CerificateContent:
                  type: string
                  format: binary
          required: true

Swagger-Client usage:
Default configuration, just use a definition containing multipart/mixed

Describe the bug you're encountering

Multipart/mixed request is broken. When used, the request body is JSON and not multipart. It was working prior to version 3.10.6. All later versions including the latest have the same behavior.

To reproduce...

Steps to reproduce the behavior:

  1. Compose a yaml using OpenAPI 3.0 and use multipart/mixed content type. Use two parts - one JSON, and the other string/binary.
  2. Add the yaml in swagger url
  3. Fill the JSON/file parts of the request and execute

Expected behavior

The request body should be multipart.

Current behavior

The request body is JSON and the request fails.

Screenshots

Additional context or thoughts

I think the issue is caused by this commit: 651e857
The condition for multipart/ is changed to 'multipart/form-data' which results in non-working multipart/mixed.

@char0n
Copy link
Member

char0n commented Oct 9, 2023

Hi @plamen-dzhorev,

Could you please show the code you used to issue a multipart/mixed request?

According to my research it never worker with proper syntax nor semantics.

This is test on [email protected]:

      const client = await SwaggerClient({ url: "https://gist.githubusercontent.com/char0n/26963c407fbc6c053913e903132c3ace/raw/af0b57672f0820971664ab8c0aef69101f65ba7e/openapi.yaml" });
      const result = await client.apis.pet.addPet({}, {
        requestContentType: 'multipart/mixed; boundary=BOUNDARY',
        requestBody: {
          CertificateBody: 'body',
          CertificateContent: 'binary content',
        }
      });

This would just create a request with content type of multipart/mixed; boundary=BOUNDARY, but the proper MIME boundaries were never generated and made the request invalid multipart/mixed requets.

@plamen-dzhorev please correct me if I'm wrong on these asumptions.

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

No branches or pull requests

2 participants