-
Notifications
You must be signed in to change notification settings - Fork 72
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
@Path annotation not used if inherited from an interface #262
Comments
Hi @michael-schnell , thanks for opening this issue. We try to follow JAX-RS's lead where possible, and in section 3.6 of the JAX-RS Spec, it talks about annotation inheritance - specifically:
So for MP Rest Client, implementations should support annotation inheritance on methods, but not on interfaces. That said, I don't see that this is documented in the MP Rest Client specification - and I don't think there are any TCK tests for this. So, if you don't mind, I'd like to keep this issue open to clarify this behavior in the spec/TCK. Thanks again! |
The feature would be quite handy espcially for the JAXS-RS client part. It allows to keep the client fully aligned with the server, but without putting the // JAX-RS server interface
// Full definition of functionality (including "path")
@Path("/persons")
public interface PersonResource {
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Person> getAll();
}
// JAX-RS client interface
// Used by external parties
@RegisterRestClient(configKey = "person-service")
public interface PersonService extends PersonResource {
}
// JAXS-RS server class
// Uses the server interface (not the client one!)
public class PersonResourceImpl implements PersonResource {
@Inject
EntityManager em;
@Override
public List<TenantListEntry> getAll() {
return em.createNamedQuery(GET_ALL, Personclass).getResultList();
}
} Maybe it could be worth to adjust the MP Rest Client specification, because it is a little bit different from what is appropriate for the server side. |
But defining it in the spec would result in a contradiction. MP Rest client is based on top of JAX-RS where it is defined as it CANNOT inherit class-level annotations. Defining it in MP Rest client that it must inherit result in a conflict for the ALL MP implementations. They MUST and MUST NOT inherit the class-level annotations on an interface or superclass. This must be addressed first at the Jakarta Rest specification to make a change. |
You are right. Unfortunately the client works actually "the other way round". The usage is simply slightly different from what is fine for the server. Therefore it would be a good idea to change the specification and clarify the differences between "server side" and "client side". |
I am a bit confused on this. The annotation |
You can simply put "PersonService" and "PersonResource" interfaces into a separate "client.jar". This way the client has the necessary information to build it's MP Rest Client instance, but it does not see any implementation code. There is a clean separaration of the layers. Then you'll have a "server.jar" that depends on "client.jar" and has the "PersonResourceImpl" class that implements "PersonResource" (not "PersonService" which has the The main problem with the "client proxy" approach taken by libraries like MP Rest Client is to keep server & client aligned. By sharing the same interface it cannot diverge by accident. And yes, the "PersonService" should not have the |
I faced the same issue with the Quarkus extension for mp-rest-client (the discovery is done here: https://github.com/quarkusio/quarkus/blob/0d5e73bcb70bbf7b1d102384a01df44e5b3ea1c6/extensions/rest-client/deployment/src/main/java/io/quarkus/restclient/deployment/RestClientProcessor.java#L180-L187) In a schema-first workflow, the interface for REST client (and server) can be generated from the OpenAPI schema (via a tool like https://github.com/OpenAPITools/openapi-generator ). But today you need to generate differently for a REST client or REST server, the REST client needing this extra |
Coming back to this now. I'm not sure what we can do with this in the MP Rest Client, but I wonder if this might be something we could bring the the Jakarta REST folks - to enable class-level path inheritance. |
Sounds good |
I am facing the same issues right now.
|
The
@Path
annotation is not used if it is inherited from an interface.Example for a base interface:
The client interface now inherits from the above one:
This will lead to the following (wrong) call:
Adding a superfluous
@Path
on the rest client interface makes it work correctly:This will lead to the following (correct) call:
The expected behaviour would be, that the
@Path
annotation is correctly used from the parent interface and there is no need to duplicate it.The text was updated successfully, but these errors were encountered: