Swagger enum values not getting displayed in drop down?

↘锁芯ラ 提交于 2021-01-01 08:13:38

问题


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) 

This is my enum ReviewsSortBy

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

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.

NOTE : Swagger version 2.9.2

Here is the screenshot for the same.


回答1:


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.

Text Inputs

  @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 

Enum Dropdowns

  @PostMapping(value = "/items/{uuid}/images",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  @PreAuthorize(Scopes.PUBLISH)
  public ImageMetadataDTO upload(@PathVariable @Uuid String 
      @RequestParam(value = "graphicType") GraphicType 


来源:https://stackoverflow.com/questions/56075653/swagger-enum-values-not-getting-displayed-in-drop-down

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!