I'm generating controller code from openapi3 spec using gradle openapi generator plugin 6.3.0. Generate, compile works fine, but getting a runtime error:
Caused by: java.lang.IllegalStateException: Ambiguous mapping. Cannot map 'orderApiController' method
com.ab.it.api.OrderApiController#create(OrderReq)
to {POST [/v1/api/orders], consumes [application/json], produces [application/json]}: There is already 'com.ab.it.api.OrderApiController' bean method
com.ab.it.api.OrderApiController#create(OrderReq) mapped.
at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping$MappingRegistry.validateMethodMapping(AbstractHandlerMethodMapping.java:669) ~[spring-webmvc-5.3.27.jar:5.3.27]
This seems unlikely as both beans 'orderApiController' and 'com.ab.it.api.OrderApiController', seems same, there is no other controller defining 'create' method, or mapping to 'POST [/v1/api/orders]'.
The controller implementing an api interface as:
@RequestMapping(
method = RequestMethod.POST,
value = "/api/orders",
produces = { "application/json" },
consumes = { "application/json" }
)
public interface OrderApi { ...
@Controller
@RequestMapping("/v1}")
public class OrderApiController implements OrderApi { ...
What can cause this?
At this point not sure if this is a problem with the generated code or a spring dependency issue.
Using spring boot 2.7.12
id "org.openapi.generator" version "6.3.0"
id 'org.springframework.boot' version '2.7.11'
// spring boot
implementation platform("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
implementation "org.springframework.boot:spring-boot-starter-web"
implementation "org.springframework:spring-webmvc"
Searched for same method name, and same mapping, did not find any in API spec. Also changed the method name in API spec, but gave the same error.