OpenAPITools / OpenAPITools/openapi-generator
[REQ] CompletableFuture implementation of ApiCallback?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
This is regarding the Java client.
The problem is one of expressiveness. I'm using the generator pretty heavily in a few projects and want to utilize the async methods, but am concerned about how much more bootstrapping it'll take to make my calls asynchronous.
Describe the solution you'd like
Would be nice to have a call back implementation already in the generated api class with an option to write async methods like so:
contactApi.getContactAsync(id)
.thenApply(contact -> {
LOG.info("Received contact: {}", contact);
});
Describe alternatives you've considered
We've considered writing our own ApiCallBack future implementation, but it still doesn't read as well as if the implementation was baked into the generated api class.
// Implementation
class ApiCallBackImpl<T> implements ApiCallback<T> {
...
public CompletionStage<T> getFuture() {} // returns future
}
// Usage
ApiCallBackImpl<Contact> callback = new ApiCallBackImpl<>();
contactApi.getContactAsync(id, callback);
callback.getFuture()
.thenApply(contact -> {
LOG.info("Received contact: {}", contact);
});
Additional context
CompletableFuture would not offer ability to track upload/download progress, but I think a majority of usecases would not require that.
Would appreciate any thoughts on this.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the Java client’s generated API classes and the existing ApiCallback async methods. Compare the requested CompletableFuture or CompletionStage usage with the current callback flow and consider the stated limitation around upload and download progress. Done means the generator can optionally produce async methods supporting the proposed future-based usage without removing callback functionality.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100