Swagger3中 exmple示例值失效的一次记录
pom
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.4.0</version>
</dependency>
controller如下
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
@PostMapping(value = "/add", consumes = {"multipart/form-data"})
@Operation(summary = "Add a new show")
public WebResult<WebResponseBody<Long>> addShow(
@Parameter(description = "showName", example = "The Great Show", required = true) String showName,
@Parameter(description = "Type of the show", example = "100", required = true) Integer showType,
@Parameter(description = "Number of sessions", example = "5", required = true) Integer sessionNum,
@Parameter(description = "Time of the first session", example = "2022-11-01 23:24:12", required = true)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime firstSessionTime,
@Parameter(description = "Time of the last session", example = "2022-11-01 23:24:12", required = true)
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime lastSessionTime,
@Parameter(description = "Duration of the show in minutes", example = "ssad", required = true) Integer showDuration,
@Parameter(description = "Description of the show", example = "This is an epic show of drama and performance.", required = true) String showDescription,
@Parameter(description = "Venue ID", example = "adsad", required = true) Long venueId,
@Parameter(description = "Show poster file name", example = "example.jpg", required = true) MultipartFile poster
) {
AddShowDto addShowDto = new AddShowDto();
addShowDto.setShowName(showName);
addShowDto.setShowType(showType);
addShowDto.setSessionNum(sessionNum);
addShowDto.setFirstSessionTime(firstSessionTime);
addShowDto.setLastSessionTime(lastSessionTime);
addShowDto.setShowDuration(showDuration);
addShowDto.setShowDescription(showDescription);
addShowDto.setVenueId(venueId);
addShowDto.setPoster(poster);
// Assume service call to process addShowDto and return result
Long result = showService.addShow(addShowDto);
return WebResult.success(result);
}
问题:在swagger-ui中,只有Integer类型的example(示例值生效,且为必填项)
解决: 加多一个@RequestParam注解,为了统一,正常显示Integer类型也加了该注解。