OpenAPITools / OpenAPITools/openapi-generator

[BUG] maven plugin with Java generator generates 2 classes that still use okhttp2

Open
#3,346 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Bug Report Checklist
Description

When updating the openapi-generator-maven-plugin from 3.3.4 (which generates okhttp2-dependent code) to 4.0.3 (which uses okhttp3) running the 'generate' goal with the java generator generates 2 classes which are still dependent on okhttp2, OauthOkhttpClient and RetryingOauth in the ${invokername}.auth package. This means that I now have to include 2 versions of Okhttp as a dependency, which should be unneccesary, since replacing the imports should fix this. Also the other classes in the .auth package already use okhttp3.

openapi-generator version

4.0.3

OpenAPI declaration file content or url

this bug is not yaml related, it's about the OKhttp -related code. any valid open Auth yaml file will do

Command line used for generation

mvn generate-sources

Steps to reproduce
  1. create a maven project
  2. add any valid openApi yaml to the project
  3. add the following plugin config to the project pom

<plugin> <groupId>org.openapitools</groupId> <artifactId>openapi-generator-maven-plugin</artifactId> <version>4.0.3</version> <executions> <execution> <id>generate-sourcecode</id> <phase>generate-resources</phase> <goals> <goal>generate</goal> </goals> <configuration> <inputSpec>{ANY yaml will do}</inputSpec> <generatorName>java</generatorName> <sourceFolder>${basedir}/src/main/java</sourceFolder> <output>${project.build.directory}/generated-sources</output> <apiPackage>${default.client.package}.handler</apiPackage> <modelPackage>${default.client.package}.model</modelPackage> <invokerPackage>${default.client.package}.invoker</invokerPackage> <generateApiTests>false</generateApiTests> <generateApiDocumentation>false</generateApiDocumentation> <generateModelTests>false</generateModelTests> <generateModelDocumentation>false</generateModelDocumentation> <configOptions> <dateLibrary>java8</dateLibrary> </configOptions> </configuration> </execution> </executions> </plugin>
4) add the following dependencies to the pom:
<dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>${okhttp3.version}</version> </dependency> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>logging-interceptor</artifactId> <version>${okhttp3.version}</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-annotations</artifactId> <version>${swagger-annotations.version}</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>${gson.version}</version> </dependency> <dependency> <groupId>io.gsonfire</groupId> <artifactId>gson-fire</artifactId> <version>${gson-fire.version}</version> </dependency> <dependency> <groupId>org.apache.oltu.oauth2</groupId> <artifactId>org.apache.oltu.oauth2.client</artifactId> <version>${oauth2.version}</version> </dependency>

  1. add the following properties to the pom:

<swagger-annotations.version>1.5.22</swagger-annotations.version> <okhttp.version>2.7.5</okhttp.version> <gson.version>2.8.5</gson.version> <gson-fire.version>1.8.3</gson-fire.version> <oauth2.version>1.0.1</oauth2.version> <okhttp3.version>3.14.2</okhttp3.version> <default.module.package>(any package name will do)</default.module.package> <default.client.package>${default.module.package}.client</default.client.package>

  1. Result after running mvn generate-sources:
    Code of OAuthOkHttpClient and RetryingOAuth does not compile because of missing okhttp2 dependency.

used
java8 64 update 191
maven 3.5.4
Windows 10 64 bit environment

Suggest a fix

update the generated code of OAuthOkHttpClient and RetryingOauth in such a way that it
includes

import okhttp3.OkHttpClient; import okhttp3.MediaType; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response;

instead of com.squareup.okhttp....

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

Reproduce the issue with the Java generator and Maven command mvn generate-sources, then inspect the generated auth package, especially OAuthOkHttpClient and RetryingOAuth. Compare their imports with the other auth classes and verify that generation no longer leaves okhttp2 references and the generated code compiles with the listed okhttp3 dependencies.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.