In Spring Boot project with Swagger 3 OpenAPI.
Have a POST
method with Multipart
file as RequestPart
.
In swagger-ui
ideally it should ask for file upload but only shows file as a String
.
Kindly help me get file upload instead of String
in swagger-ui
.
My RestController
:
@RestController
public class HelloController {
@RequestMapping(method = RequestMethod.GET, value = "/api")
public String sayHello() {
return "Swagger Hello World";
}
@RequestMapping(method = RequestMethod.POST, value = "/fileUpload")
public String fileUpload(
@RequestPart(value = "file", required = false ) MultipartFile file,
@RequestPart(value = "userName", required = false ) String userName
) {
return "added successfully";
}
}
File pom.xml
:
<modelVersion>4.0.0</modelVersion>
<groupId>com.poc</groupId>
<artifactId>springboot-swagger-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.12</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
On swagger-ui
: