Swagger 枚举值未显示在下拉列表中? [英] Swagger enum values not getting displayed in drop down?

查看:49
本文介绍了Swagger 枚举值未显示在下拉列表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This is my controller method where the enum is accepted

@GetMapping("/{sortBy}/{page}/{size}")
    public ResponseDto<ReviewsResponseDto, Void> searchAllReviews(
            @PathVariable(value = "sortBy") ReviewsSortBy sortBy,
            @PathVariable Integer page, @PathVariable Integer size) 

这是我的枚举 ReviewsSortBy

This is my enum ReviewsSortBy

@Getter
@ToString
public enum ReviewsSortBy {
      DEFAULT,
      FEATURED,
      RECENT;
}

现在的问题是 swagger 不会在下拉列表中显示枚举的可能值,而是仅将ReviewsSortBy()"显示为相同下拉列表中唯一的可选值.

Now the problem is that swagger doesnt display the possible values of enum in dropdown, instead it just displays "ReviewsSortBy()" as the only selectable value in the dropdown list of the same.

注意:Swagger 2.9.2 版

NOTE : Swagger version 2.9.2

这是相同的屏幕截图.

推荐答案

看起来您正在使用带有 springfox 的 springboot.我有一个类似的问题,但不是相同的问题.使用 Spring 的请求映射注释的 consumes 属性显式指定允许的内容类型会导致 Swagger 中的枚举下拉字段成为文本框.

It looks like you are using springboot w/ springfox. I had a similar issue but not identical issue. Explicitly specifying an allowable content-type using the consumes property of Spring's request mapping annotations results in enum dropdown fields in Swagger becoming text boxes.

  @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 

这篇关于Swagger 枚举值未显示在下拉列表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆