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.
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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With