diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index aab0fa37f64f..db3dbd9415a5 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -55,6 +55,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen public static final String DO_NOT_USE_RX = "doNotUseRx"; public static final String USE_PLAY_WS = "usePlayWS"; public static final String PLAY_VERSION = "playVersion"; + public static final String FEIGN_HTTP_CLIENT = "feignHttpClient"; + public static final String FEIGN_DEFAULT_HTTP_CLIENT = "default"; + public static final String FEIGN_APACHE_HTTP_CLIENT = "apacheHttpClient"; + public static final String[] FEIGN_SUPPORTED_HTTP_CLIENTS = new String[]{FEIGN_DEFAULT_HTTP_CLIENT, FEIGN_APACHE_HTTP_CLIENT}; public static final String ASYNC_NATIVE = "asyncNative"; public static final String PARCELABLE_MODEL = "parcelableModel"; public static final String USE_RUNTIME_EXCEPTION = "useRuntimeException"; @@ -98,6 +102,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen protected String playVersion = PLAY_26; protected String microprofileFramework = MICROPROFILE_DEFAULT; + protected String feignHttpClient = FEIGN_DEFAULT_HTTP_CLIENT; protected boolean asyncNative = false; protected boolean parcelableModel = false; protected boolean useBeanValidation = false; @@ -146,6 +151,7 @@ public JavaClientCodegen() { cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests")); cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception")); cliOptions.add(CliOption.newBoolean(ASYNC_NATIVE, "If true, async handlers will be used, instead of the sync version")); + cliOptions.add(CliOption.newBoolean(FEIGN_HTTP_CLIENT, "Use an alternative httpClient module in the FeignClient: " + Arrays.toString(FEIGN_SUPPORTED_HTTP_CLIENTS))); cliOptions.add(CliOption.newBoolean(USE_REFLECTION_EQUALS_HASHCODE, "Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact.")); cliOptions.add(CliOption.newBoolean(CASE_INSENSITIVE_RESPONSE_HEADERS, "Make API response's headers case-insensitive. Available on " + OKHTTP_GSON + ", " + JERSEY2 + " libraries")); cliOptions.add(CliOption.newString(MICROPROFILE_FRAMEWORK, "Framework for microprofile. Possible values \"kumuluzee\"")); @@ -270,6 +276,15 @@ public void processOpts() { } additionalProperties.put(MICROPROFILE_FRAMEWORK, microprofileFramework); + // OpenFeign httpClient + if (additionalProperties.containsKey(FEIGN_HTTP_CLIENT)) { + this.setFeignHttpClient(additionalProperties.get(FEIGN_HTTP_CLIENT).toString()); + if (!Arrays.asList(FEIGN_SUPPORTED_HTTP_CLIENTS).contains(feignHttpClient)){ + throw new RuntimeException("Invalid feignOption '" + feignHttpClient + "'. Valid options are: " + Arrays.toString(FEIGN_SUPPORTED_HTTP_CLIENTS)); + } + } + additionalProperties.put("useApacheHttpClient", feignHttpClient.equals(FEIGN_APACHE_HTTP_CLIENT)); + if (additionalProperties.containsKey(ASYNC_NATIVE)) { this.setAsyncNative(convertPropertyToBooleanAndWriteBack(ASYNC_NATIVE)); } @@ -899,6 +914,10 @@ public void setPlayVersion(String playVersion) { this.playVersion = playVersion; } + public void setFeignHttpClient(String feignHttpClient) { + this.feignHttpClient = feignHttpClient; + } + public void setAsyncNative(boolean asyncNative) { this.asyncNative = asyncNative; } diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache index 691f337c7c5f..b43767d98918 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache @@ -31,6 +31,9 @@ import com.fasterxml.jackson.datatype.threetenbp.ThreeTenModule; import feign.Feign; import feign.RequestInterceptor; import feign.form.FormEncoder; +{{#useApacheHttpClient}} +import feign.httpclient.ApacheHttpClient; +{{/useApacheHttpClient}} import feign.jackson.JacksonDecoder; import feign.jackson.JacksonEncoder; import feign.slf4j.Slf4jLogger; @@ -52,6 +55,9 @@ public class ApiClient { objectMapper = createObjectMapper(); apiAuthorizations = new LinkedHashMap(); feignBuilder = Feign.builder() + {{#useApacheHttpClient}} + .client(new ApacheHttpClient()) + {{/useApacheHttpClient}} .encoder(new FormEncoder(new JacksonEncoder(objectMapper))) .decoder(new JacksonDecoder(objectMapper)) .logger(new Slf4jLogger()); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache index 3f9664b221a4..02ab7d477bfa 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache @@ -130,6 +130,9 @@ ext { {{/threetenbp}} feign_version = "10.11" feign_form_version = "3.8.0" + {{#useApacheHttpClient}} + feign_httpclient_version = "10.11" + {{/useApacheHttpClient}} junit_version = "4.13.1" oltu_version = "1.0.1" } @@ -141,6 +144,9 @@ dependencies { compile "io.github.openfeign:feign-jackson:$feign_version" compile "io.github.openfeign:feign-slf4j:$feign_version" compile "io.github.openfeign.form:feign-form:$feign_form_version" + {{#useApacheHttpClient}} + compile "io.github.openfeign:feign-httpclient:$feign_httpclient_version" + {{/useApacheHttpClient}} compile "com.fasterxml.jackson.core:jackson-core:$jackson_version" compile "com.fasterxml.jackson.core:jackson-annotations:$jackson_version" compile "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version" diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache index 322abb2a5cb6..b458b2759dfb 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache @@ -13,6 +13,9 @@ lazy val root = (project in file(".")). "io.github.openfeign" % "feign-core" % "10.11" % "compile", "io.github.openfeign" % "feign-jackson" % "10.11" % "compile", "io.github.openfeign" % "feign-slf4j" % "10.11" % "compile", + {{#useApacheHttpClient}} + "io.github.openfeign" % "feign-httpclient" % "10.11" % "compile", + {{/useApacheHttpClient}} "io.github.openfeign.form" % "feign-form" % "3.8.0" % "compile", "com.fasterxml.jackson.core" % "jackson-core" % "2.10.3" % "compile", "com.fasterxml.jackson.core" % "jackson-annotations" % "2.10.3" % "compile", diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache index e9abe7dbaad9..b9f064cd8f1a 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache @@ -252,6 +252,13 @@ feign-slf4j ${feign-version} + {{#useApacheHttpClient}} + + io.github.openfeign + feign-httpclient + ${feign-httpclient-version} + + {{/useApacheHttpClient}} io.github.openfeign.form feign-form @@ -352,6 +359,9 @@ 1.5.24 10.11 3.8.0 + {{#useApacheHttpClient}} + 10.11 + {{/useApacheHttpClient}} 2.10.3 {{#openApiNullable}} 0.2.1