I have a Spring Boot application with a rest controller defined like.
The Swagger API doc generated looks something like this.
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.
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).
It's normal since you didn't specify the difference between the two endpoints, so they both have /Home
as the parent path but then you need to add the specific path.
So it depends on your endpoint purpose and your implementation 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.