Skip to content

Commit fddec73

Browse files
committed
Added HttpClient5 flavour to Java OpenFeign client generator.
1 parent 7881152 commit fddec73

6 files changed

Lines changed: 50 additions & 2 deletions

File tree

bin/configs/java-feign-hc5.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
generatorName: java
2+
outputDir: samples/client/petstore/java/feign-hc5
3+
library: feign-hc5
4+
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
5+
templateDir: modules/openapi-generator/src/main/resources/Java
6+
additionalProperties:
7+
booleanGetterPrefix: is
8+
artifactId: petstore-feign-hc5
9+
hideGenerationTimestamp: "true"

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
7878
public static final String ERROR_OBJECT_TYPE = "errorObjectType";
7979

8080
public static final String FEIGN = "feign";
81+
public static final String FEIGN_HC5 = "feign-hc5";
8182
public static final String GOOGLE_API_CLIENT = "google-api-client";
8283
public static final String JERSEY2 = "jersey2";
8384
public static final String JERSEY3 = "jersey3";
@@ -246,6 +247,7 @@ public JavaClientCodegen() {
246247
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1");
247248
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1");
248249
supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 13.2.1. JSON processing: Jackson 2.17.1 or Gson 2.10.1");
250+
supportedLibraries.put(FEIGN_HC5, "HTTP client: OpenFeign 13.2.1/HttpClient5 5.4.2. JSON processing: Jackson 2.17.1 or Gson 2.10.1");
249251
supportedLibraries.put(OKHTTP_GSON, "[DEFAULT] HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
250252
supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 4.11.0. JSON processing: Gson 2.10.1 (Retrofit 2.5.0) or Jackson 2.17.1. Enable the RxJava adapter using '-DuseRxJava[2/3]=true'. (RxJava 1.x or 2.x or 3.x)");
251253
supportedLibraries.put(RESTTEMPLATE, "HTTP client: Spring RestTemplate 5.3.33 (6.1.5 if `useJakartaEe=true`). JSON processing: Jackson 2.17.1");
@@ -325,7 +327,7 @@ public void processOpts() {
325327

326328
// determine and cache client library type once
327329
final boolean libApache = isLibrary(APACHE);
328-
final boolean libFeign = isLibrary(FEIGN);
330+
final boolean libFeign = isLibrary(FEIGN) || isLibrary(FEIGN_HC5);
329331
final boolean libGoogleApiClient = isLibrary(GOOGLE_API_CLIENT);
330332
final boolean libJersey2 = isLibrary(JERSEY2);
331333
final boolean libJersey3 = isLibrary(JERSEY3);
@@ -745,6 +747,14 @@ public void processOpts() {
745747
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
746748
break;
747749
}
750+
751+
if (isLibrary(FEIGN)) {
752+
additionalProperties.put("feign-okhttp", "true");
753+
} else if (isLibrary(FEIGN_HC5)) {
754+
additionalProperties.put("feign-hc5", "true");
755+
setTemplateDir(FEIGN);
756+
setLibrary(FEIGN);
757+
}
748758

749759
// authentication related files
750760
// has OAuth defined
@@ -825,7 +835,7 @@ public int compare(CodegenParameter one, CodegenParameter another) {
825835
}
826836

827837
// camelize path variables for Feign client
828-
if (isLibrary(FEIGN)) {
838+
if (isLibrary(FEIGN) || isLibrary(FEIGN_HC5)) {
829839
OperationMap operations = objs.getOperations();
830840
List<CodegenOperation> operationList = operations.getOperation();
831841
Pattern methodPattern = Pattern.compile("^(.*):([^:]*)$");

modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ import java.util.logging.Level;
99
import java.util.logging.Logger;
1010

1111
{{#jackson}}
12+
{{#feign-okhttp}}
1213
import feign.okhttp.OkHttpClient;
14+
{{/feign-okhttp}}
15+
{{#feign-hc5}}
16+
import feign.hc5.ApacheHttp5Client;
17+
{{/feign-hc5}}
1318
import com.fasterxml.jackson.databind.DeserializationFeature;
1419
import com.fasterxml.jackson.databind.ObjectMapper;
1520
import com.fasterxml.jackson.databind.SerializationFeature;
@@ -71,7 +76,12 @@ public class ApiClient {
7176
{{#jackson}}
7277
objectMapper = createObjectMapper();
7378
feignBuilder = Feign.builder()
79+
{{#feign-okhttp}}
7480
.client(new OkHttpClient())
81+
{{/feign-okhttp}}
82+
{{#feign-hc5}}
83+
.client(new ApacheHttp5Client())
84+
{{/feign-hc5}}
7585
.encoder(new FormEncoder(new JacksonEncoder(objectMapper)))
7686
.decoder(new ApiResponseDecoder(objectMapper))
7787
{{#hasOAuthMethods}}

modules/openapi-generator/src/main/resources/Java/libraries/feign/build.gradle.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,12 @@ dependencies {
127127
implementation "io.github.openfeign:feign-jackson:$feign_version"
128128
{{/jackson}}
129129
implementation "io.github.openfeign:feign-slf4j:$feign_version"
130+
{{#feign-okhttp}}
130131
implementation "io.github.openfeign:feign-okhttp:$feign_version"
132+
{{/feign-okhttp}}
133+
{{#feign-hc5}}
134+
implementation "io.github.openfeign:feign-hc5:$feign_version"
135+
{{/feign-hc5}}
131136
implementation "io.github.openfeign.form:feign-form:$feign_form_version"
132137
{{#jackson}}
133138
{{#joda}}

modules/openapi-generator/src/main/resources/Java/libraries/feign/build.sbt.mustache

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ lazy val root = (project in file(".")).
1717
{{/jackson}}
1818
"io.github.openfeign" % "feign-slf4j" % "13.5" % "compile",
1919
"io.github.openfeign.form" % "feign-form" % "3.8.0" % "compile",
20+
{{#feign-okhttp}}
2021
"io.github.openfeign" % "feign-okhttp" % "13.5" % "compile",
22+
{{/feign-okhttp}}
23+
{{#feign-hc5}}
24+
"io.github.openfeign" % "feign-hc5" % "13.5" % "compile",
25+
{{/feign-hc5}}
2126
{{#jackson}}
2227
"com.fasterxml.jackson.core" % "jackson-core" % "2.17.1" % "compile",
2328
"com.fasterxml.jackson.core" % "jackson-annotations" % "2.17.1" % "compile",

modules/openapi-generator/src/main/resources/Java/libraries/feign/pom.mustache

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,20 @@
265265
<artifactId>feign-form</artifactId>
266266
<version>${feign-form-version}</version>
267267
</dependency>
268+
{{#feign-okhttp}}
268269
<dependency>
269270
<groupId>io.github.openfeign</groupId>
270271
<artifactId>feign-okhttp</artifactId>
271272
<version>${feign-version}</version>
272273
</dependency>
274+
{{/feign-okhttp}}
275+
{{#feign-hc5}}
276+
<dependency>
277+
<groupId>io.github.openfeign</groupId>
278+
<artifactId>feign-hc5</artifactId>
279+
<version>${feign-version}</version>
280+
</dependency>
281+
{{/feign-hc5}}
273282

274283
{{#jackson}}
275284
<!-- JSON processing: jackson -->

0 commit comments

Comments
 (0)