Springdoc-openapi: Generated MultipartFile schema in JSON/YAML does not work in UI

Created on 1 Aug 2019  路  4Comments  路  Source: springdoc/springdoc-openapi

Hi,

I have a service defined like :
@PostMapping(path = "/documents") public ResponseEntity<String> uploadDocuments( @RequestParam("doc") List<MultipartFile> multipartFiles, @RequestParam(value = "mode", required = false, defaultValue = edit) String mode)

Generated YAML file contains MultipartFile schema :

schemas: MultipartFile: type: object properties: name: type: string empty: type: boolean bytes: type: array items: type: string format: byte resource: $ref: '#/components/schemas/Resource' size: type: integer format: int64 inputStream: type: object contentType: type: string originalFilename: type: string Resource: type: object properties: open: type: boolean file: type: string format: binary readable: type: boolean description: type: string uri: type: string format: uri filename: type: string url: type: string format: url inputStream: type: object

So the UI doesn't recognize the field as binary so I can't upload images.

SwaggerUI

YAML THAT WORKS
If the schema was :
schemas: MultipartFile: type: string format: binary

SwaggerUISuccess

How can I override this generated MultipartFile? Or there is some other solution I'm missing?

I'm using:
`

  • springdoc-openapi-core, version 1.1.4
  • springdoc-openapi-ui, version 1.1.4

Most helpful comment

Hello,

Your swagger shows the file is passed as @RequestParam,.
For the file upload, just use @RequestPart instead, which is more appropriate in the spring. And it should work.

@PostMapping (path = "/documents") public ResponseEntityString> upload Documents (@RequestPart ("doc") ListMultipartFile> multipartFiles, @RequestParam (value = "mode", required = false, defaultValue = edit) String mode)

Or even without any annotations, just giving the parameter the right name. ("doc" in your case)

@PostMapping (path = "/documents") public ResponseEntityString> upload Documents (ListMultipartFile> doc, @RequestParam (value = "mode", required = false, defaultValue = edit) String mode)

All 4 comments

Hi,

File upload was not handled by the springdoc-openapi-core.

  • springdoc-openapi-core, version 1.1.6 now handles it

Hey, I tried it. Now I'm getting YAML part looking like :

parameters: - name: doc in: query required: true schema: type: object properties: files: type: array items: type: string format: binary

And it still doesn't show good in UI.

YAML THAT WORKS

parameters: - name: doc in: query required: true schema: type: array items: type: string format: binary

I'm using springdoc-openapi-core and springdoc-openapi-ui version 1.1.6

Hello,

Your swagger shows the file is passed as @RequestParam,.
For the file upload, just use @RequestPart instead, which is more appropriate in the spring. And it should work.

@PostMapping (path = "/documents") public ResponseEntityString> upload Documents (@RequestPart ("doc") ListMultipartFile> multipartFiles, @RequestParam (value = "mode", required = false, defaultValue = edit) String mode)

Or even without any annotations, just giving the parameter the right name. ("doc" in your case)

@PostMapping (path = "/documents") public ResponseEntityString> upload Documents (ListMultipartFile> doc, @RequestParam (value = "mode", required = false, defaultValue = edit) String mode)

Thanx, you are right! Changed it to "@RequestParam" but also in "@PostMapping" added option consumes = "multipart/form-data". And it looks good

Screen Shot 2019-08-02 at 9 58 15 AM

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bfs-natewallman picture bfs-natewallman  路  4Comments

andygoossens picture andygoossens  路  6Comments

Orxcle-xx picture Orxcle-xx  路  4Comments

danielbecs picture danielbecs  路  4Comments

urswiss picture urswiss  路  5Comments