Skip to content

Commit 4c08ff8

Browse files
authored
[Java][Vertx] Add option to generate methods that return Futures (#21083)
* [Java][Vertx] Add option to generate methods that return Futures * run scripts * update sample config and github workflow * generate samples * rerun script * add vertx-no-nullable to samples workflow
1 parent c67b113 commit 4c08ff8

File tree

229 files changed

+28323
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

229 files changed

+28323
-2
lines changed

.github/workflows/samples-java-client-jdk11.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ jobs:
6161
- samples/client/petstore/java/webclient-swagger2
6262
- samples/client/petstore/java/webclient-useSingleRequestParameter
6363
- samples/client/petstore/java/vertx
64+
- samples/client/petstore/java/vertx-no-nullable
65+
- samples/client/petstore/java/vertx-supportVertxFuture
6466
- samples/client/petstore/java/jersey2-java8-localdatetime
6567
- samples/client/petstore/java/google-api-client
6668
- samples/client/petstore/java/rest-assured
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
generatorName: java
2+
outputDir: samples/client/petstore/java/vertx-supportVertxFuture
3+
library: vertx
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+
artifactId: petstore-vertx-supportvertxfuture
8+
hideGenerationTimestamp: "true"
9+
dateLibrary: java8
10+
supportVertxFuture: "true"

docs/generators/java-microprofile.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8787
|sourceFolder|source folder for generated code| |src/main/java|
8888
|supportStreaming|Support streaming endpoint (beta)| |false|
8989
|supportUrlQuery|Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries.| |false|
90+
|supportVertxFuture|Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.| |false|
9091
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
9192
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
9293
|useBeanValidation|Use BeanValidation API annotations| |false|

docs/generators/java.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8787
|sourceFolder|source folder for generated code| |src/main/java|
8888
|supportStreaming|Support streaming endpoint (beta)| |false|
8989
|supportUrlQuery|Generate toUrlQueryString in POJO (default to true). Available on `native`, `apache-httpclient` libraries.| |false|
90+
|supportVertxFuture|Also generate api methods that return a vertx Future instead of taking a callback. Only `vertx` supports this option. Requires vertx 4 or greater.| |false|
9091
|testOutput|Set output folder for models and APIs tests| |${project.build.directory}/generated-test-sources/openapi|
9192
|useAbstractionForFiles|Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries| |false|
9293
|useBeanValidation|Use BeanValidation API annotations| |false|

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}}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
3+
#
4+
# This file is auto-generated by OpenAPI Generator (https://openapi-generator.tech)
5+
6+
name: Java CI with Maven
7+
8+
on:
9+
push:
10+
branches: [ main, master ]
11+
pull_request:
12+
branches: [ main, master ]
13+
14+
jobs:
15+
build:
16+
name: Build OpenAPI Petstore
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
java: [ 17, 21 ]
21+
steps:
22+
- uses: actions/checkout@v4
23+
- name: Set up JDK
24+
uses: actions/setup-java@v4
25+
with:
26+
java-version: ${{ matrix.java }}
27+
distribution: 'temurin'
28+
cache: maven
29+
- name: Build with Maven
30+
run: mvn -B package --no-transfer-progress --file pom.xml
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.jar
8+
*.war
9+
*.ear
10+
11+
# exclude jar for gradle wrapper
12+
!gradle/wrapper/*.jar
13+
14+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
15+
hs_err_pid*
16+
17+
# build files
18+
**/target
19+
target
20+
.gradle
21+
build

0 commit comments

Comments
 (0)