You don't need to use delegatePattern to add your business logic. You need to implement generated *Api classes and put @RestController annotation on the class declaration level. Generated *Controller classes are just stubs for "default" behavior. If you implement your own controller, it will be prioritized during the autowiring.
Generated stub-controller:
@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", comments = "Generator version: 7.8.0")
@RestController
@RequestMapping("${openapi.swaggerPetstore.base-path:/v1}")
public class PetsApiController implements PetsApi {
}
Your controller implementation:
@RestController
@RequestMapping("${openapi.swaggerPetstore.base-path:/v1}")
class MyPetsApiController implements PetsApi {
private final PetsService petsService;
@Override
public Flux<Pet> listPets(Integer limit, ServerWebExchange exchange) {
return petsService.listPets(limit)
}
...
}
If you get the following error:
Caused by: org.springframework.context.annotation.ConflictingBeanDefinitionException: Annotation-specified bean name 'petsApiController' for bean class [com.example.PetsApiController] conflicts with existing, non-compatible bean definition of same name and class [com.example.PetsApiController]
...you have various options here. I'll list two of them:
You can exclude generated stub from the component scan:
@SpringBootApplication
@ComponentScan(
basePackages = "com.example",
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = PetsApiController.class)
)
public class Application
You can skip generation of the stub controller. Set interfaceOnly to false: https://openapi-generator.tech/docs/generators/spring/. Now openapi-generator won't create any @Controller classes; you can make it yourself.
I would suggest to use the second option.