Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extended support for Spring Controller interfaces #1115

Open
vghero opened this issue May 10, 2022 · 5 comments
Open

Extended support for Spring Controller interfaces #1115

vghero opened this issue May 10, 2022 · 5 comments

Comments

@vghero
Copy link

vghero commented May 10, 2022

Hey,
I'm using Enunciate 2.11.1 together with a Spring 5 WebMVC REST app. I'm separating the REST controllers via interfaces from its implementation, so that the interface can be reused by client generation like Feign. Recently Feign dropped support for @RequestMapping on Controller interfaces and so I dropped it as well, moving the path to e.g. @GetMapping on method level. Then I also wanted to cleanup @RestController on the interface, as it's already contained on my impl. But then it seemed that enunciate wasn't able to pickup the endpoints anymore on the interface - which I use for "scanning".

Now I'm wondering if there's a way for Enunciate to detect that the interface actually IS a RestController without having that annotation set on it directly - but maybe looking at the implementation class which has it? Does the internal metamodel in Enunciate already has this kind of information?

@stoicflame
Copy link
Owner

If there are no annotations on the interface itself, how would Enunciate determine whether the interface is actually a controller or if it's just a common interface that multiple controllers want to share?

@vghero
Copy link
Author

vghero commented May 11, 2022

I agree it's a bit "tricky" and surely does not make it less complex. Naive me thought just looking for the implementation class of the interface. But if we have multiple impls I would expect that all of them will be selected as a target for documentation generation. Similar to what happens with referenced DTOs in an interface - they are also picked up although maybe lying out of the provided package to scan. If this is a bigger thing todo it's maybe not worth the effort....

@stoicflame
Copy link
Owner

I can take a closer look, but let me summarize to make sure I understand what you'd like to see.

  • Currently impl controller classes are getting picked up for documentation by Enunciate, but interfaces are only getting picked up if they're annotated with @RestController.
  • You'd like to see Enunciate pick up interfaces as controllers if they have @[Method]Mapping annotations on their methods and if they have an impl class that is annotated with @RestController.

Is that accurate?

@vghero
Copy link
Author

vghero commented May 11, 2022

Yes, that is accurate :).

@stoicflame
Copy link
Owner

Okay. We'll probably have to make this a config option, though, because some people use interfaces to support common parameters and patters across multiple controllers and it doesn't imply that the interface is a controller.

For example, if I want my GET method to have the same signature on Resource1Controller, Resource2Controller, etc., then I might define an interface that enforces that GET method signature and is annotated with @GetMapping, even though the interface was never intended to be a controller itself.

@stoicflame stoicflame added this to the 2.15.0 milestone May 11, 2022
@stoicflame stoicflame removed this from the 2.15.0 milestone Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants