swagger-api / swagger-api/swagger-client

Ability to upload file streams (along with existing buffer capability) using multipart/form-data request

Open
#4,111 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
2.7k
Forks
765
Avg merge
1d 1h
Merged PRs (30d)
6

Description

Content & configuration

Swagger/OpenAPI definition:

openapi: 3.0.3
info:
 title: File Upload API
 version: 1.0.0
 description: API to upload a file using multipart/form-data
paths:
 /upload:
   post:
     summary: Upload a file
     description: Uploads a file to the server
     operationId: uploadFile
     requestBody:
       required: true
       content:
         multipart/form-data:
           schema:
             type: object
             properties:
               file:
                 type: string
                 format: binary
                 description: The file to upload
               description:
                 type: string
                 description: Optional description of the file
     responses:
       '200':
         description: File uploaded successfully
         content:
           application/json:
             schema:
               type: object
               properties:
                 fileName:
                   type: string
                 fileSize:
                   type: integer
                 message:
                   type: string
       '400':
         description: Bad request (e.g., file missing)
       '500':
         description: Internal server error

Swagger-Client usage:

SwaggerClient({
 operationId: 'uploadFile',
   requestBody: {
     file: fileStream,           // 👈 Pass the stream here
     description: 'Uploaded via stream'
   },
})
Is your feature request related to a problem?
Whenever the stream is passed instead of a buffered file for the above multipart/form-data request, swaggerClient doesn't recognize it as a stream and converts it to '[object, object]' at [this]([https://github.com/swagger-api/swagger-js/blob/ef68516156527f8c2812d193a6f7cda2c2b553f5/src/http/serializers/request/index.js#L4]) method and the request body itself becomes incorrect due to this
Describe the solution you'd like
  • If the stream is passed in a multipart/form-data request it should be passed on as is in the final paylod
Describe alternatives you've considered
Additional context

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/http/serializers/request/index.js, the request serialization method identified in the issue. Trace how multipart/form-data requestBody values are converted, then verify that a supplied file stream is forwarded unchanged rather than converted to '[object, object]'. Done means the generated upload request preserves the stream while existing buffered-file support continues to work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.