5

I am using the OpenAPI generator to generate the server side implementation for spring-boot starting from an OAI specification.

I noticed that with the configuration that I was using, the generator was not using the delegate pattern in the controller. For example, a controller looked like:

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.context.request.NativeWebRequest;
import java.util.Optional;

@Controller
@RequestMapping("${openapi.someresourceLibrary.base-path:/some-resource/v1}")
public class SomeResourcesApiController implements SomeResourcesApi {

    private final NativeWebRequest request;

    @org.springframework.beans.factory.annotation.Autowired
    public SomeResourcesApiController(NativeWebRequest request) {
        this.request = request;
    }

    @Override
    public Optional<NativeWebRequest> getRequest() {
        return Optional.ofNullable(request);
    }

}

I know that I can, in my pom.xml file, set the configuration delegatePattern to true to enable the use of the delegate pattern.

I am wondering if someone knows why by default the tool is not using the delegate pattern that seems the most natural for this use case.

If I decide to use the default pattern, how am I supposed to provide my implementation? Should I extend the controller ?

Marco Altieri
  • 3,726
  • 2
  • 33
  • 47
  • What does your pom look like? It's possible you are specifying delegatePattern in an incorrect way. – jmpyle771 Dec 16 '20 at 14:28
  • 1
    @jmpyle771 Setting delegatePattern to true works. I was trying to understand the default implementation that does not seem very useful. It is not clear how I am supposed to extends that implementation. – Marco Altieri Dec 19 '20 at 22:01
  • 1
    @MarcoAltieri Thank you for kicking this discussion. could you please share with me any use case where I can see how the delegate pattern is implemented with controllers and how that is useful? any git or documentation is very welcomed. in my case, we are using the delegate pattern but we have only one implementation. I really want to see a case where the delegate comes to play with controllers. Thank you. – BSL Dec 31 '20 at 06:29
  • see duplicate [here](https://stackoverflow.com/a/66296299/8709958) – Patrick L Apr 12 '22 at 14:29
  • interesting read – Shridutt Kothari Nov 15 '22 at 13:29

0 Answers0