quarkus: Interface with RegisterRestClient doesn't inherit parent annotations.
Describe the bug When using an interface to describe a rest API, interfaces that inherit that API and are annotated with RegisterRestClient, don’t appear to inherit the API’s definition. When adding a Path annotation to the client interface, the test passes instead of throwing 404.
Expected behavior It should be possible to inherit API definitions and for the injected client to respect them, so they are only defined in one place. For example, this is the code I expect to behave correctly:
@Path("/api")
interface GreetingAPI {
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/hello")
fun hello(): String
}
@RegisterRestClient
interface GreetingClient : GreetingAPI
With the following test:
@QuarkusTest
open class GreetingEndpointTest {
@Inject
@field: RestClient
lateinit var client: GreetingClient
@Test
fun testHelloEndpoint() {
val response = client.hello()
assert(response == "hello")
}
}
In order to get this example to work, I have to apply the Path annotation to the client interface like so. Without the Path annotation it throws a 404.
@Path("/api")
@RegisterRestClient
interface GreetingClient : GreetingAPI
Environment (please complete the following information): Linux tbox-kubuntu 5.0.0-32-generic #34-Ubuntu SMP Wed Oct 2 02:06:48 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux openjdk version “11.0.4” 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu219.04) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu219.04, mixed mode, sharing)
About this issue
- Original URL
- State: open
- Created 5 years ago
- Comments: 19 (8 by maintainers)
Hi We solved the problem by creating producer classes which use the RestClientBuilder manually. This way we have more control about the created proxies and can use any interface without modification. Best regards Markus Ritter
Hi. Experiencing the same problem. We generate interface from openapi spec and would be really happy if we could use these interfaces for server AND client but for adding @RegisterRestClient you need to extend the interface or is there another way? Best regards Markus
It would be good to fix this. It’s a useful pattern to be able to separate API from server and client implementations, and share a common definition across both.
@yuhaibohotmail thanks for for the Java test.