问题
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