spring-bootswaggeropenapiswagger-ui

Only displays one endpoint when multiple endpoints of the same type are present with different Accept header values


I have a Spring Boot application with a rest controller defined like.

enter image description here

The Swagger API doc generated looks something like this. enter image description here

As you can see, only the deprecated endpoint shows up on UI as it appears first in the java code. However, my requirement is that I need both of these endpoints to show up in the UI. Swagger is not able to differentiate between them because the only differentiating factor is the Consumes tag.

Is there a way to achieve this ?

Similar question has already been asked here but it had no responses, hence I'm asking this again here.

P.S. Already tried AI assistants, they're unable to come up with a working solution.


Solution

  • Swagger Doesn’t Support Multiple Endpoints with the Same Path and Method:

    Even though you have two different versions (based on the content type), both endpoints map to the same path (/home) and use the same HTTP method (GET). Swagger only sees one endpoint per unique combination of path + HTTP method, causing it to register only one of them (likely the second newEndpoint). Its normal since you didnt specify the diffrence between the two endpoints, So they both have /Home as the parent path but then you need to add the specific path.

    so it dependend on your endpoint purpose and your implimentation logic.

    in your case you can try using this :

    @RequestMapping(path = "/home", method = RequestMethod.GET, produces = "application/vnd.example.v1+json")
    

    there is a lot of other methods but this one is by far the most simple one .