Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

File upload on Swagger Editor OpenAPI 3 not showing the file browser when trying it out

I'm using Swagger Editor with OpenAPI 3.0. I need to document a route which consists of uploading an image. When attempting to "Try it out", I don't get the file browser to choose the image to upload in the request body, all I get is a JSON string with the name and type of parameter.

File Upload "Try it out" screenshot

This is the YAML description of the route:

openapi: 3.0.0
...
paths:
  /media/upload/thumbnail:
    post:
      tags:
        - media
        - publications
      security:
        - bearerAuth: []
      summary: upload a kid's publication
      operationId: uploadPublication
      requestBody:
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                upload:
                  type: string
                  format: binary
      responses:
        '200':
          description: Successful operation
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: string
                    description: ObjectId of the uploaded file in db (original size)
                    example: 5a6048b3fad06019afe44f24
                  filename:
                    type: string
                    example: myPainting.png
                  thumbnail:
                    type: string
                    description: ObjectId of the uploaded file in db (thumbnai size)
                    example: 5a6048b3fad06019afe44f26
        '400':
          description: Authentication failed

What am I missing here?

like image 336
Abu Romaïssae Avatar asked Oct 17 '22 23:10

Abu Romaïssae


1 Answers

Your definition is correct.

Support for file upload for multipart/form-data requests in OpenAPI 3.0 definitions has been added in Swagger Editor 3.5.7 and Swagger UI 3.16.0. Make sure you are using a version that supports file upload.

like image 180
Helen Avatar answered Oct 21 '22 01:10

Helen