OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Java] RxJava2CallAdapterFactory should not be used & io.reactivex.Observable / io.reactivex.Completable not imported when useRxJava2: 'false'

Open
#7,758 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Retrofit Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

When using useRxJava2: 'false', then the com.squareup.retrofit2:adapter-rxjava2 dependency (and due to & through it transitively its own dependency org.reactivestreams:reactive-streams) are still required - even though they should not be used in the generated code with that configuration.

The reason for that is that the generated ApiClient has an import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory because createDefaultAdapter() does a .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) - which, of course, isn't actually needed when using useRxJava2: 'false'. Similarly, all classes generated into the apiPackage folder always have an import io.reactivex.Observable; and a import io.reactivex.Completable; even though, again, they are not used anywhere with useRxJava2: 'false'.

The templates could thus be improved to skip those lines for users who don't need Rx.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the Java templates that generate ApiClient and the classes in the apiPackage, then inspect createDefaultAdapter() and the RxJava imports. Generate a client with useRxJava set to false and verify that the RxJava adapter, Observable, and Completable imports and dependencies are no longer required.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.