问题
I'm using the last (and only)
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
with spring boot
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
I would like to have ability to upload file and model in one controller, so I created one:
in this case on swagger-ui I see only file uploading without model:
I tried this case in postman and it works fine
Is it a bug? Or should I add some other annotations to make it work?
回答1:
The problem was in Configuration class, in Docket Bean. Here I'm defining route to my Controllers to exclude others from swagger-ui. The problem was in DocumentationType, OpenApi3.0 is maintaining multitype files uploading, and Swagger2 don't.
Next problem which I faced was:
415 Unsupported Media Type
Resolution:
First way: If you will use postman/javaScript framework -> you have to define media-type of every RequestPart (actually don't need for file, for file it will be set automatically). example in POSTMAN:
Second way: is implement maintaining of octet-stream, because spring set it by default in AbstractMessageConverterMethodArgumentResolver.class
if there is no content-type header in request part.
(I'm using spring-boot-starter-parent 2.4.1 -> spring-webmvc 5.3.2
)
So here is 2 cases I found (to map response JSON to DTO):
1 case (not recommended): Set supporting to JSON converter:
2 case:
Define new Converter class which will work definitely for needed classes (in my case it is MDVersionDTO.class
) and definitely when it comes like octet-stream, to implement it, ovveride canRead()
method.
来源:https://stackoverflow.com/questions/65666648/is-it-any-ability-to-upload-multipartfile-with-model-in-swagger-in-comment-415