Support @RequestPart annotation
See original GitHub issueTLDR: @RequestPart
parameters should have paramType
of form
and models should be generated for @RequestPart
annotated parameters.
When using the @RequestPart
annotation, the paramType attribute for that parameter is incorrect (unless the parameter is a MultipartFile
). When making an api operation that uses a file upload, we can no longer use @RequestBody
, instead it must be @RequestPart
, which means the overall request Content-Type
becomes mulitpart/form-data
.
While this all works fine if the if the file upload is the only parameter, once you try to add additional parameters (i.e. pieces that will be included in its own boundary), it no longer works (at least not with swagger-ui, because the spec is incorrect).
The other issue is the parameters annotated as @RequestPart
do not have their models added to the generated spec files.
So given the following example, swagger-ui should create a form that takes a text input and file input (which it does), however the request parameter is using paramType ‘body’, and when the form is submitted, only the file gets submitted in the request.
@ApiOperation(value = "")
@RequestMapping(value = "/issue", method = RequestMethod.POST)
@ResponseBody
public MyResponse issueRequest(
@ApiParam(required = true) @RequestPart MyRequest request,
@ApiParam(required = true) @RequestPart MultipartFile document)
Using the custom annotation readers, I am able to work around the paramType issue, but not adding the model to the spec issue.
Issue Analytics
- State:
- Created 9 years ago
- Comments:7 (2 by maintainers)
Someone solved the problem described by @ndorigatti? i have the same scenario and I don’t know how to fix it
Hello, i see again this issue in springfox-boot-starter:3.0.0
I have an endpoint with both Pojo and Multipart file. I can successfully call the endpoint with Postman tool if I set it:
@PostMapping(value = "/sito", consumes = {MediaType.MULTIPART_FORM_DATA_VALUE}) public void insertSito(@RequestPart(name = "edifici", required = false) MultipartFile file, @RequestPart(name="sito") CreateSitoDTO creationRequest) {
But swagger shows ONLY the file part (that is the only optional one btw…). If i switch the json part to @RequestBody, swagger shows both the elements, but fails to call the endpoint, what i get is:
org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver: Resolved [org.springframework.web.HttpMediaTypeNotSupportedException: Content type 'multipart/form-data;boundary=----WebKitFormBoundaryr6riTHMZjZyrkhQI;charset=UTF-8' not supported]
I’m currently using spring-boot 2.5.7 and springfox-boot-starter 3.0.0 (NOT snapshot)