swagger-js icon indicating copy to clipboard operation
swagger-js copied to clipboard

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

Open ujjwal-ab opened this issue 2 months ago • 0 comments

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

ujjwal-ab avatar Oct 25 '25 19:10 ujjwal-ab