Skip to content

[http-client] Copy Annotations to Generated Clients #216

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

Merged
merged 8 commits into from
Apr 30, 2023

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Apr 29, 2023

Given a Client like this:

@Singleton
@Client
public interface ApiClient {

  @Get("/bcVQzeZ.png")
  @Butterfly(kind=MOONLIGHT, status = "it floats down")
  HttpResponse<InputStream> call(@Header("Accept") String accept);
}

The non avaje-http annotations are copied to the generated implementation.

@Generated("avaje-http-client-generator")
@jakarta.inject.Singleton()
public class ApiClientHttpClient implements ApiClient {

  private final HttpClient client;

  public ApiClientHttpClient(HttpClient client) {
    this.client = client;
  }

  // GET /bcVQzeZ.png
  @Override
@com.jojo.javalin.api.aspect.Butterfly(kind=com.jojo.javalin.api.enums.Custom.MOONLIGHT, status = "it floats down")
  public HttpResponse<InputStream> call(String accept) {
    return client.request()
      .header("Accept", accept)
      .path("bcVQzeZ.png")
      .GET()
      .asInputStream();
  }

  public static class Provider implements HttpApiProvider<ApiClient> {
    @Override
    public Class<ApiClient> type() {
      return ApiClient.class;
    }
    @Override
    public ApiClient provide(HttpClient client) {
      return new ApiClientHttpClient(client);
    }
  }
}

Fixes #215

Relies on avaje/avaje-inject#340

@rob-bygrave rob-bygrave added this to the 1.39 milestone Apr 30, 2023
@rob-bygrave rob-bygrave merged commit fca319d into avaje:master Apr 30, 2023
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 this pull request may close these issues.

Support avaje-inject aspects on generated http-client interfaces.
2 participants