When i generate code for Spring
from my swagger yaml , usually controller layer is generated using delegate
pattern , such that for a single model three files are generated . For example , if i defined a model named Person
in my swagger/open API yaml file , three files get generated as :
- PersonApi (interface that contains signatures of all person operations/methods)
- PersonApiDelegate ( interface that provides default implementation of all PersonApi methods . Meant to be overriden )
- PersonApiController (Which has a reference to PersonApiDelegate so that any implementation can override and provide custom implementation)
My question is for anyone who is familiar with building swagger/openapi generated code based apis that what is the significance of having such a pattern , instead of just exposing your service endpoints using a PersonController class , and not going through a PersonApi interface and then to a PersonApiDelegate and finally exposing the service through a PersonApiController ?
What is the valuable design extensibility we gain through this pattern ? I tried to find information from other resources on internet , but couldn't find a good answer in context of swagger first API development approach . Any insights on this will be really helpful .