0

I have a GET method in Controller that takes as one of a parameters (@PathVariable) an Enum. This Enum has several values and when it is being generated by Swagger/OpenApi, in the Swagger UI when testing/try out the endpoint, list of possible parameter values coming from Enum, is displayed. However it is being displayed in the order in which values are typed in Enum. I would like to order the list alphabetically, to be displayed in Swagger UI. I cannot simply sort the Enum as it is coming from external library.

@GetMapping("/{id}/status/{enumStatus}/validate")
public ResponseEntity<RootElement> getMethod(@PathVariable("id") final String id, @PathVariable("status") final StatusEnum enumStatus) {
        return myRestService.validate(id, enumStatus);
    }

    private enum StatusEnum {
        B_STATUS, A_STATUS, NO_STATUS, CC_STATUS
    }

I was hoping for something similar but I was not able to get specific PathVariable: How do I write a custom sorter to sort my springdoc swagger tags by name in the UI?

I don't know if this sorting is possible at all..

beatarjn
  • 1
  • 1

1 Answers1

0

Swagger UI does not have an option to sort enums.

One possible solution is to fork the Swagger UI repository, modify the code responsible for displaying enums (at least here and here, possibly elsewhere), rebuild it, and use your custom fork in your app.

Helen
  • 87,344
  • 17
  • 243
  • 314