java - Swagger 枚举值没有显示在下拉列表中?
问题描述
这是我接受枚举的控制器方法
@GetMapping("/{sortBy}/{page}/{size}")
public ResponseDto<ReviewsResponseDto, Void> searchAllReviews(
@PathVariable(value = "sortBy") ReviewsSortBy sortBy,
@PathVariable Integer page, @PathVariable Integer size)
这是我的枚举 ReviewsSortBy
@Getter
@ToString
public enum ReviewsSortBy {
DEFAULT,
FEATURED,
RECENT;
}
现在的问题是,swagger 不会在下拉列表中显示枚举的可能值,而是仅将“ReviewsSortBy()”显示为相同下拉列表中的唯一可选值。
注意:Swagger 版本 2.9.2
解决方案
看起来您正在使用带有 springfox 的 springboot。我有一个类似的问题,但不是相同的问题。使用 Spring 的请求映射注释的属性显式指定允许的内容类型consumes
会导致 Swagger 中的枚举下拉字段成为文本框。
文本输入
@PostMapping(value = "/items/{uuid}/images",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@PreAuthorize(Scopes.PUBLISH)
public ImageMetadataDTO upload(@PathVariable @Uuid String
@RequestParam(value = "graphicType") GraphicType
枚举下拉菜单
@PostMapping(value = "/items/{uuid}/images",
produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@PreAuthorize(Scopes.PUBLISH)
public ImageMetadataDTO upload(@PathVariable @Uuid String
@RequestParam(value = "graphicType") GraphicType
推荐阅读
- opencv - import cv2 在使用 python 3.6 的 jupyter notebook 中返回错误
- css - 数据表中的Vuetify选择下拉菜单创建位置问题
- php - AJAX:如何发回成功/错误消息
- c# - 如何关闭停靠面板中每个选项卡上的按钮
- sparql - DELETE WHERE 不使用属性路径序列 sparql
- java - 关于如何在 Java 中创建对象的困惑
- ruby-on-rails - 不使用设计 gem,在 ruby 中 x 分钟后自动注销
- rust - 为具有反序列化特征绑定的泛型派生反序列化时无法推断类型参数的类型
- postgresql - 从 DatabaseMetaData.getIndexInfo() 中为 Postgres 发现索引“nulls first|last”
- nlp - CUDA 错误:调用 `cublasCreate(handle)` 时出现 CUBLAS_STATUS_ALLOC_FAILED