【问题标题】:Swagger enum values not getting displayed in drop down?Swagger 枚举值没有显示在下拉列表中?
【发布时间】:2023-04-05 06:34:01
【问题描述】:

这是我接受枚举的控制器方法

@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

这是相同的屏幕截图。

【问题讨论】:

    标签: java spring-boot swagger swagger-ui swagger-2.0


    【解决方案1】:

    看起来您正在使用带有 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 
    

    【讨论】:

    • 明确提及是否显示,在代码的第一部分明确提及&标题是文本输入
    猜你喜欢
    • 2021-08-19
    • 2021-10-03
    • 1970-01-01
    • 2013-09-15
    • 1970-01-01
    • 2011-11-27
    • 2016-09-29
    • 1970-01-01
    • 2021-11-11
    相关资源
    最近更新 更多