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

@RestClient - the current @Target is wrong #257

Closed
mkouba opened this issue Mar 9, 2020 · 6 comments · Fixed by #258
Closed

@RestClient - the current @Target is wrong #257

mkouba opened this issue Mar 9, 2020 · 6 comments · Fixed by #258

Comments

@mkouba
Copy link

mkouba commented Mar 9, 2020

The current value is @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD}).

  1. It's not possible to inject a rest client into a method or a constructor parameter (missing ElementType.PARAMETER).
  2. It's not possible to define test mocks for rest client interfaces (missing ElementType.TYPE).

CDI qualifiers typically define the target as follows: @Target({METHOD, FIELD, PARAMETER, TYPE}). ElementType.CONSTRUCTOR is completely useless.

@mkouba
Copy link
Author

mkouba commented Mar 9, 2020

This issue follows up on #232.

@andreas-eberle
Copy link
Contributor

@mkouba: I created a PR to add the missing ElementType.PARAMETER. Besides that, I was wondering if ElementType.CONSTRUCTOR should be in that list.

@mkouba
Copy link
Author

mkouba commented Mar 9, 2020

I believe that the correct value is @Target({METHOD, FIELD, PARAMETER, TYPE}), i.e. no ElementType.CONSTRUCTOR (qualifiers declared on a constructor are ignored) and add ElementType.TYPE.

@andreas-eberle
Copy link
Contributor

andreas-eberle commented Mar 9, 2020

@mkouba: Why do you think ElementType.TYPE should be added? Do you have an example?

@mkouba
Copy link
Author

mkouba commented Mar 9, 2020

It could be useful when creating mocks:

@Path("/echo")
@RegisterRestClient
public interface EchoClient {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    @Consumes(MediaType.TEXT_PLAIN)
    String echo(@QueryParam("message") String message);
}

@Priority(1)
@Alternative // Takes precedence over the bean provided by the MP Rest Client impl
@RestClient
class MockEchoClient implements EchoClient {
    public String echo(String message) {
       return "mock!";
   }
}

@andreas-eberle
Copy link
Contributor

Good idea. I added it to my PR. Thanks for the input!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants