SpringDoc Problem With Methods With Different Query Parameters

Viewed 304

I want to do something like create two method for same url pattern with different arguments

@RequestMapping(value = "/searchUser", params = "userID")
public String searchUserById(@RequestParam long userID, Model model) {
  // ...
}

@RequestMapping(value = "/searchUser", params = "userName")
public ModelAndView searchUserByName(@RequestParam String userName) {
  // ...
}

Spring supports this and it works fine. SpringDoc does not. It creates a single endpoint with 2 parameters.Is this a known issue?

1 Answers

This is supported, but you will have to use swagger @Operation to describe your methods in one path.

One of the OpenAPI 3 rules.

Two POST methods for the same path are not allowed – even if they have different parameters (parameters have no effect on uniqueness).

More details are available on OpenAPI 3 site.

This has been explained here: https://github.com/springdoc/springdoc-openapi/issues/580

Related