Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/samples-java-client-jdk11.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ jobs:
- samples/client/petstore/java/webclient-swagger2
- samples/client/petstore/java/webclient-useSingleRequestParameter
- samples/client/petstore/java/vertx
- samples/client/petstore/java/vertx5
- samples/client/petstore/java/vertx-no-nullable
- samples/client/petstore/java/vertx-supportVertxFuture
- samples/client/petstore/java/jersey2-java8-localdatetime
Expand Down
11 changes: 11 additions & 0 deletions bin/configs/java-vertx5.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
generatorName: java
outputDir: samples/client/petstore/java/vertx5
Comment thread
sjw2547 marked this conversation as resolved.
library: vertx
inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml
templateDir: modules/openapi-generator/src/main/resources/Java
useVertx5: "true"
useRxJava3: "true"
additionalProperties:
artifactId: petstore-vertx5
hideGenerationTimestamp: "true"
dateLibrary: java8
1 change: 1 addition & 0 deletions docs/generators/java-microprofile.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
|useVertx5|Whether to use Vert.x 5 syntax.| |false|
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
Expand Down
1 change: 1 addition & 0 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useSingleRequestParameter|Setting this property to "true" will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter. ONLY native, jersey2, jersey3, okhttp-gson, microprofile, Spring RestClient, Spring WebClient support this option. Setting this property to "static" does the same as "true", but also makes the generated arguments class static with single parameter instantiation.| |false|
|useSpringBoot4|Generate code and provide dependencies for use with Spring Boot 4.x.| |false|
|useUnaryInterceptor|If true it will generate ResponseInterceptors using a UnaryOperator. This can be usefull for manipulating the request before it gets passed, for example doing your own decryption| |false|
|useVertx5|Whether to use Vert.x 5 syntax.| |false|
|webclientBlockingOperations|Making all WebClient operations blocking(sync). Note that if on operation 'x-webclient-blocking: false' then such operation won't be sync| |false|
|withAWSV4Signature|whether to include AWS v4 signature support (only available for okhttp-gson library)| |false|
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@ public static enum ENUM_PROPERTY_NAMING_TYPE {camelCase, PascalCase, snake_case,
public static final String USE_SINGLE_REQUEST_PARAMETER = "useSingleRequestParameter";
public static final String USE_SINGLE_REQUEST_PARAMETER_DESC = "Setting this property to true will generate functions with a single argument containing all API endpoint parameters instead of one argument per parameter.";

public static final String USE_VERTX_5 = "useVertx5";
public static final String USE_VERTX_5_DESC = "Setting this property to true will generate Vert.x 5 specific callbacks using Callables.";

public static final String DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT = "disallowAdditionalPropertiesIfNotPresent";
public static final String DISALLOW_ADDITIONAL_PROPERTIES_IF_NOT_PRESENT_DESC =
"If false, the 'additionalProperties' implementation (set to true by default) is compliant with the OAS and JSON schema specifications. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String USE_RX_JAVA2 = "useRxJava2";
public static final String USE_RX_JAVA3 = "useRxJava3";
public static final String DO_NOT_USE_RX = "doNotUseRx";
public static final String USE_VERTX_5 = "useVertx5";
public static final String USE_PLAY_WS = "usePlayWS";
public static final String ASYNC_NATIVE = "asyncNative";
public static final String CONFIG_KEY = "configKey";
Expand Down Expand Up @@ -130,6 +131,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
protected boolean useRxJava = false;
protected boolean useRxJava2 = false;
protected boolean useRxJava3 = false;
@Setter protected boolean useVertx5 = false;
// backwards compatibility for openapi configs that specify neither rx1 nor rx2
// (mustache does not allow for boolean operators so we need this extra field)
@Setter protected boolean doNotUseRx = true;
Expand Down Expand Up @@ -243,6 +245,7 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA2, "Whether to use the RxJava2 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated."));
cliOptions.add(CliOption.newBoolean(USE_RX_JAVA3, "Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated."));
cliOptions.add(CliOption.newBoolean(PARCELABLE_MODEL, "Whether to generate models for Android that implement Parcelable with the okhttp-gson library."));
cliOptions.add(CliOption.newBoolean(USE_VERTX_5, "Whether to use Vert.x 5 syntax."));
cliOptions.add(CliOption.newBoolean(USE_PLAY_WS, "Use Play! Async HTTP client (Play WS API)"));
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
Expand Down Expand Up @@ -424,6 +427,8 @@ public void processOpts() {
convertPropertyToBooleanAndWriteBack(USE_RX_JAVA3, this::setUseRxJava3);
convertPropertyToBooleanAndWriteBack(USE_RX_JAVA2, this::setUseRxJava2);
}
convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_VERTX_5, this::setUseVertx5);

convertPropertyToStringAndWriteBack(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, this::setUseSingleRequestParameter);
convertPropertyToBooleanAndWriteBack(USE_SEALED_ONE_OF_INTERFACES, this::setUseSealedOneOfInterfaces);
convertPropertyToBooleanAndWriteBack(USE_UNARY_INTERCEPTOR, this::setUseUnaryInterceptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,25 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
return contentTypes[0];
}

{{#useVertx5}}
public Future<HttpResponse<Buffer>> sendBody(HttpRequest<Buffer> request,
Object body) {
if (body instanceof byte[]) {
Buffer buffer = Buffer.buffer((byte[]) body);
return request.sendBuffer(buffer);
} else if (body instanceof AsyncFile) {
AsyncFile file = (AsyncFile) body;
return request.sendStream(file);
} else {
try {
return request.sendBuffer(Buffer.buffer(this.objectMapper.writeValueAsBytes(body)));
} catch (JsonProcessingException jsonProcessingException) {
return Future.failedFuture(jsonProcessingException);
}
}
}
{{/useVertx5}}
{{^useVertx5}}
public void sendBody(HttpRequest<Buffer> request,
Handler<AsyncResult<HttpResponse<Buffer>>> responseHandler,
Object body) {
Expand All @@ -450,6 +469,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
}
}
}
{{/useVertx5}}

/**
* Invoke API by sending HTTP request with the given options.
Expand Down Expand Up @@ -514,13 +534,28 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

Handler<AsyncResult<HttpResponse<Buffer>>> responseHandler = buildResponseHandler(returnType, resultHandler);
if (body != null) {
{{#useVertx5}}
sendBody(request, body).onComplete(responseHandler::handle);
{{/useVertx5}}
{{^useVertx5}}
sendBody(request, responseHandler, body);
{{/useVertx5}}
} else if (formParams != null && !formParams.isEmpty()) {
Map<String, String> formMap = formParams.entrySet().stream().collect(toMap(Map.Entry::getKey, entry -> parameterToString(entry.getValue())));
MultiMap form = MultiMap.caseInsensitiveMultiMap().addAll(formMap);
{{#useVertx5}}
request.sendForm(form).onComplete(responseHandler::handle);
{{/useVertx5}}
{{^useVertx5}}
request.sendForm(form, responseHandler);
{{/useVertx5}}
} else {
{{#useVertx5}}
request.send().onComplete(responseHandler::handle);
{{/useVertx5}}
{{^useVertx5}}
request.send(responseHandler);
{{/useVertx5}}
}
}

Expand Down Expand Up @@ -577,6 +612,19 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {

String filename = generateFilename(response.headers());
Consumer<String> fileHandler = directory -> {
{{#useVertx5}}
fs.open(directory + filename, FILE_DOWNLOAD_OPTIONS).onComplete(asyncFileResult -> {
if (asyncFileResult.succeeded()) {
AsyncFile asyncFile = asyncFileResult.result();
asyncFile.write(response.bodyAsBuffer());
//noinspection unchecked
handler.handle(Future.succeededFuture((T) asyncFile));
} else {
handler.handle(ApiException.fail(asyncFileResult.cause()));
}
});
{{/useVertx5}}
{{^useVertx5}}
fs.open(directory + filename, FILE_DOWNLOAD_OPTIONS, asyncFileResult -> {
if (asyncFileResult.succeeded()) {
AsyncFile asyncFile = asyncFileResult.result();
Expand All @@ -587,14 +635,22 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} {
handler.handle(ApiException.fail(asyncFileResult.cause()));
}
});
{{/useVertx5}}
};

String dir = getDownloadsDir();
if (dir != null && !dir.isEmpty()) {
{{#useVertx5}}
fs.mkdirs(dir).onComplete(mkdirResult -> {
String sanitizedFolder = dir.endsWith("/") ? dir : dir + "/";
fileHandler.accept(sanitizedFolder);
});
{{/useVertx5}}
{{^useVertx5}}
fs.mkdirs(dir, mkdirResult -> {
String sanitizedFolder = dir.endsWith("/") ? dir : dir + "/";
fileHandler.accept(sanitizedFolder);
});
{{/useVertx5}}
} else {
fileHandler.accept("");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ repositories {
apply plugin: 'java'
apply plugin: 'maven-publish'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
sourceCompatibility = {{#useVertx5}}JavaVersion.VERSION_11{{/useVertx5}}{{^useVertx5}}JavaVersion.VERSION_1_8{{/useVertx5}}
targetCompatibility = {{#useVertx5}}JavaVersion.VERSION_11{{/useVertx5}}{{^useVertx5}}JavaVersion.VERSION_1_8{{/useVertx5}}

publishing {
publications {
Expand All @@ -32,7 +32,7 @@ ext {
swagger_annotations_version = "1.5.21"
jackson_version = "2.19.2"
jackson_databind_version = "2.19.2"
vertx_version = "{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}"
vertx_version = "{{#useVertx5}}5.0.11{{/useVertx5}}{{#supportVertxFuture}}{{^useVertx5}}4.0.0{{/useVertx5}}{{/supportVertxFuture}}{{^supportVertxFuture}}{{^useVertx5}}3.5.2{{/useVertx5}}{{/supportVertxFuture}}"
junit_version = "5.10.3"
{{#openApiNullable}}
jackson_databind_nullable_version = "0.2.10"
Expand All @@ -44,7 +44,7 @@ dependencies {
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
implementation "com.google.code.findbugs:jsr305:3.0.2"
implementation "io.vertx:vertx-web-client:$vertx_version"
implementation "io.vertx:vertx-rx-java:$vertx_version"
implementation "io.vertx:{{#useRxJava3}}vertx-rx-java3{{/useRxJava3}}{{#useRxJava2}}vertx-rx-java2{{/useRxJava2}}{{^useRxJava3}}{{^useRxJava2}}vertx-rx-java{{/useRxJava2}}{{/useRxJava3}}:$vertx_version"
implementation "com.fasterxml.jackson.core:jackson-core:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-annotations:$jackson_version"
implementation "com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
<!-- Vertx -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-rx-java</artifactId>
<artifactId>{{#useRxJava3}}vertx-rx-java3{{/useRxJava3}}{{^useRxJava3}}vertx-rx-java{{/useRxJava3}}</artifactId>
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
<version>${vertx-version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -299,7 +299,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<vertx-version>{{#supportVertxFuture}}4.0.0{{/supportVertxFuture}}{{^supportVertxFuture}}3.5.2{{/supportVertxFuture}}</vertx-version>
<vertx-version>{{#useVertx5}}5.0.11{{/useVertx5}}{{#supportVertxFuture}}{{^useVertx5}}4.0.0{{/useVertx5}}{{/supportVertxFuture}}{{^supportVertxFuture}}{{^useVertx5}}3.5.2{{/useVertx5}}{{/supportVertxFuture}}</vertx-version>
{{#swagger1AnnotationLibrary}}
<swagger-annotations-version>1.6.6</swagger-annotations-version>
{{/swagger1AnnotationLibrary}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ import {{invokerPackage}}.ApiClient;

import java.util.*;

{{#useRxJava3}}
import io.reactivex.rxjava3.core.Single;
import io.vertx.rxjava3.SingleHelper;
{{/useRxJava3}}
{{#useRxJava2}}
import io.reactivex.Single;
import io.vertx.reactivex.SingleHelper;
{{/useRxJava2}}
{{^useRxJava2}}{{^useRxJava3}}
import rx.Single;
{{/useRxJava3}}{{/useRxJava2}}
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Expand Down Expand Up @@ -60,9 +70,18 @@ public class {{classname}} {
* @return Asynchronous result handler (RxJava Single)
*/
public Single<{{{returnType}}}{{^returnType}}Void{{/returnType}}> rx{{operationIdCamelCase}}({{#allParams}}{{{dataType}}} {{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
{{#useRxJava2}}
return SingleHelper.toSingle(fut ->
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}fut));
{{/useRxJava2}}
{{#useRxJava3}}
return SingleHelper.toSingle(fut -> delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}fut));
{{/useRxJava3}}
{{^useRxJava2}}{{^useRxJava3}}
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut ->
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}fut)
));
{{/useRxJava3}}{{/useRxJava2}}
}

/**
Expand All @@ -75,9 +94,19 @@ public class {{classname}} {
* @return Asynchronous result handler (RxJava Single)
*/
public Single<{{{returnType}}}{{^returnType}}Void{{/returnType}}> rx{{operationIdCamelCase}}({{#allParams}}{{{dataType}}} {{paramName}}, {{/allParams}}ApiClient.AuthInfo authInfo) {
{{#useRxJava2}}
return SingleHelper.toSingle(fut ->
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}authInfo, fut));
{{/useRxJava2}}
{{#useRxJava3}}
return SingleHelper.toSingle(fut ->
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}authInfo, fut));
{{/useRxJava3}}
{{^useRxJava2}}{{^useRxJava3}}
return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut ->
delegate.{{operationId}}({{#allParams}}{{paramName}}, {{/allParams}}authInfo, fut)
));
{{/useRxJava3}}{{/useRxJava2}}
}
{{/operation}}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ protected <T> void handleFileDownload(HttpResponse<Buffer> response, Handler<Asy
}
});
};

String dir = getDownloadsDir();
if (dir != null && !dir.isEmpty()) {
fs.mkdirs(dir, mkdirResult -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

import java.util.*;


import rx.Single;

import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;

Expand Down Expand Up @@ -54,9 +56,11 @@ public void call123testSpecialTags(UUID uuidTest, Client body, ApiClient.AuthInf
* @return Asynchronous result handler (RxJava Single)
*/
public Single<Client> rxCall123testSpecialTags(UUID uuidTest, Client body) {

return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut ->
delegate.call123testSpecialTags(uuidTest, body, fut)
));

}

/**
Expand All @@ -68,9 +72,11 @@ public Single<Client> rxCall123testSpecialTags(UUID uuidTest, Client body) {
* @return Asynchronous result handler (RxJava Single)
*/
public Single<Client> rxCall123testSpecialTags(UUID uuidTest, Client body, ApiClient.AuthInfo authInfo) {

return Single.create(new io.vertx.rx.java.SingleOnSubscribeAdapter<>(fut ->
delegate.call123testSpecialTags(uuidTest, body, authInfo, fut)
));

}

public static AnotherFakeApi newInstance(org.openapitools.client.api.AnotherFakeApi arg) {
Expand Down
Loading
Loading