Reputation: 3901
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?
Upvotes: 8
Views: 14353
Reputation: 2307
For one of my same kind of concern !!!
I had to modify the input type to requested endpoint method.
Note- It might not address all type of requirements, but few can definitely be benefitted from this
Before:
/myEndpoint( @RequestBody RequestModelName requestModelName )
where RequestModelName has properties and getter/setter...
By this I could NOT see File option in swagger.
After:
/myEndpoint( @RequestParam MultipartFile file, @RequestParam String otherProp )
And then I could see File option in swagger...
Upvotes: 0
Reputation: 135
Try with
content:
image/png:
schema:
properties:
file:
type: string
format: binary
Upvotes: -2
Reputation: 97609
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.
Upvotes: 4