Skip to content

Change how Generated Clients are registered. #218

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 6 commits into from
May 30, 2023
Merged

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented May 29, 2023

  • Make HttpApiProvider a functional interface
  • now generates a GeneratedComponent class that adds HttpApiProviders to DHttpApi
  • no longer generates a provider nested class. (the generated client constructor is used as an HttpApiProvider)
  • client processor test for easier debugging of issues
  • can reflectively retrieve implementations using HttpClient as well as HttpClientContext.

fixes #217

this is how the generated component looks

@Generated("avaje-client-generator")
public class GeneratedHttpComponent implements HttpClient.GeneratedComponent {
  @Override
  public void register(Map<Class<?>, HttpApiProvider<?>> providerMap) {
    providerMap.put(ApiClient.class, ApiClientHttpClient::new);
  }
}

@rob-bygrave
Copy link
Contributor

It does not look like this supports "partial compilation" yet? That is, avaje-jsonb has io.avaje.jsonb.generator.ComponentReader ... that reads an existing GeneratedComponent and if exists reads the meta data (in this case factories). Currently it looks like with a partial compile we can effectively lose factories (when they are not included in the compilation).

@SentryMan
Copy link
Collaborator Author

oh so that's what that does

@SentryMan
Copy link
Collaborator Author

do we also need a metadata annotation to make this work as well? I never actually understood their purpose in Jsonb.

@rob-bygrave
Copy link
Contributor

metadata annotation to make this work as well?

Yes.

If there was no such thing as "partial compile" then we would not need the meta data annotations that we use for json and inject. The main purpose of those "meta annotations" is to support partial compilation where (typically via IDE) a compilation occurs that say only includes a new http client and does not include some http clients that already exist. For this compile, the processing reads the "meta annotations" (looks up meta-inf services file, finds that element, if exists reads those meta annotations) ... that this tells it that when it generates the GeneratedComponent to include those http clients that already exist.

For jsonb we previously didn't need this because in theory we generated a meta-inf services entry per http client [but it looks to me like we have a bug there in that technically we should APPEND an entry in there for each http client and it looks like it OVERRIDES instead ... so it looks like we have a similar'ish bug in there today]

@SentryMan
Copy link
Collaborator Author

I no longer get the this class will not be subject to annotation processing warning so we should be good?

@rbygrave
Copy link
Contributor

Yes, it looks all good as I see it - I'll merge it in.

I should be able to manually test partial compile via IntelliJ (I'll likely manually bump up some logging while I do that etc). Opps, dinner first ...

@rbygrave rbygrave added this to the 1.40 milestone May 30, 2023
@rbygrave rbygrave merged commit 4bf12e6 into avaje:master May 30, 2023
@SentryMan SentryMan deleted the client branch May 30, 2023 11:33
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.

Make registering http client interfaces easier for modular applications
3 participants