OpenAPITools / OpenAPITools/openapi-generator
[REQ] Java Retrofit2 RxJava return Single and Maybe types
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.
I would like my generated client interface to return more advanced types than Observables when using RxJava with the Java Retrofit2 generator. By that I mean return a Single or a Maybe, which to me makes way more sense since an HTTP request is always gonna be followed by a single response (or error). Otherwise I'll always be handling the response by with a firstElement().
Describe the solution you'd like
I would like the Java Retrofit2 generator to return a Single in most cases, when using RxJava(3) instead of Observables. Returning a Maybe would also be great in cases where a response body can be returned or not.
For example, I have a service that returns a 200 status code with a response body. But the very same service can also return a 204 status code with no response body.
The Retrofit2 generator is already handling Completables, which is awesome, for services that do not return response bodies.
Describe alternatives you've considered
I've considered just using a custom mustache template for my use, in case not everyone feels the need for this new feature.
I'm facing a challenge though, as I'm not an expert in either Mustaches or OpenAPI Generator. The difficulty resides in identifying which endpoint should return a Maybe.
I've taken a look at the available variables when working with mustaches, but I haven't found what could help me in this task. I've thought of one thing so far, which is analyzing the responses array in a given operation, and see if it contains both a response with parameters "is2xx": true and a non null dataType and a response with parameters "is2xx": true and a null dataType, which would mean the service can either respond with a response body or an empty body.
But I have no clue how to write this in a mustache or if it's even possible.
I'm open to suggestions to tackle this problem on my mustache.
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 at the Java Retrofit2 generator and its Mustache variables, focusing on the operation responses array and the existing Completable handling. Determine how generated interfaces should distinguish single-response and optional-body cases, then verify that generated return types match those cases while preserving current Observable and Completable behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100