Skip to content

Commit 6517917

Browse files
committed
[Java][Vertx] Add option to generate methods that return Futures
1 parent 4fc46cb commit 6517917

4 files changed

Lines changed: 30 additions & 2 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
101101
public static final String WEBCLIENT_BLOCKING_OPERATIONS = "webclientBlockingOperations";
102102
public static final String USE_ENUM_CASE_INSENSITIVE = "useEnumCaseInsensitive";
103103
public static final String FAIL_ON_UNKNOWN_PROPERTIES = "failOnUnknownProperties";
104+
public static final String SUPPORT_VERTX_FUTURE = "supportVertxFuture";
104105

105106
public static final String SERIALIZATION_LIBRARY_GSON = "gson";
106107
public static final String SERIALIZATION_LIBRARY_JACKSON = "jackson";
@@ -243,6 +244,7 @@ public JavaClientCodegen() {
243244
cliOptions.add(CliOption.newBoolean(SUPPORT_URL_QUERY, "Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries."));
244245
cliOptions.add(CliOption.newBoolean(USE_ENUM_CASE_INSENSITIVE, "Use `equalsIgnoreCase` when String for enum comparison", useEnumCaseInsensitive));
245246
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
247+
cliOptions.add(CliOption.newBoolean(SUPPORT_VERTX_FUTURE, "Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater."));
246248

247249
supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1");
248250
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1");

modules/openapi-generator/src/main/resources/Java/libraries/vertx/api.mustache

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import {{invokerPackage}}.ApiClient;
55
{{/imports}}
66
import io.vertx.core.AsyncResult;
77
import io.vertx.core.Handler;
8+
{{#supportVertxFuture}}
9+
import io.vertx.core.Future;
10+
import io.vertx.core.Promise;
11+
{{/supportVertxFuture}}
812
import io.vertx.core.json.JsonObject;
913

1014
import java.util.*;
@@ -18,11 +22,33 @@ public interface {{classname}} {
1822
{{/isDeprecated}}
1923
void {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}Handler<AsyncResult<{{{returnType}}}{{^returnType}}Void{{/returnType}}>> handler);
2024

25+
{{#supportVertxFuture}}
26+
{{#isDeprecated}}
27+
@Deprecated
28+
{{/isDeprecated}}
29+
default Future<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}){
30+
Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}> promise = Promise.promise();
31+
{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}promise);
32+
return promise.future();
33+
}
34+
35+
{{/supportVertxFuture}}
2136
{{#isDeprecated}}
2237
@Deprecated
2338
{{/isDeprecated}}
2439
void {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}ApiClient.AuthInfo authInfo, Handler<AsyncResult<{{{returnType}}}{{^returnType}}Void{{/returnType}}>> handler);
2540

41+
{{#supportVertxFuture}}
42+
{{#isDeprecated}}
43+
@Deprecated
44+
{{/isDeprecated}}
45+
default Future<{{{returnType}}}{{^returnType}}Void{{/returnType}}> {{operationId}}({{#allParams}}{{>nullable_var_annotations}} {{{dataType}}} {{paramName}}, {{/allParams}}ApiClient.AuthInfo authInfo){
46+
Promise<{{{returnType}}}{{^returnType}}Void{{/returnType}}> promise = Promise.promise();
47+
{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}authInfo, promise);
48+
return promise.future();
49+
}
50+
51+
{{/supportVertxFuture}}
2652
{{/operation}}
2753
{{/operations}}
2854
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ ext {
3232
swagger_annotations_version = "1.5.21"
3333
jackson_version = "2.17.1"
3434
jackson_databind_version = "2.17.1"
35-
vertx_version = "3.5.2"
35+
vertx_version = "{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}"
3636
junit_version = "5.10.3"
3737
{{#openApiNullable}}
3838
jackson_databind_nullable_version = "0.2.6"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@
299299

300300
<properties>
301301
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
302-
<vertx-version>3.5.2</vertx-version>
302+
<vertx-version>{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}</vertx-version>
303303
{{#swagger1AnnotationLibrary}}
304304
<swagger-annotations-version>1.6.6</swagger-annotations-version>
305305
{{/swagger1AnnotationLibrary}}

0 commit comments

Comments
 (0)