Skip to content
Open
Show file tree
Hide file tree
Changes from all 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 docs/generators/java-microprofile.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|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|
|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|
|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 @@ -105,6 +105,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|useRxJava3|Whether to use the RxJava3 adapter with the retrofit2 library. IMPORTANT: This option has been deprecated.| |false|
|useSealedOneOfInterfaces|Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.| |false|
|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|
|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|
|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 @@ -105,6 +105,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String FAIL_ON_UNKNOWN_PROPERTIES = "failOnUnknownProperties";
public static final String SUPPORT_VERTX_FUTURE = "supportVertxFuture";
public static final String USE_SEALED_ONE_OF_INTERFACES = "useSealedOneOfInterfaces";
public static final String USE_UNARY_INTERCEPTOR = "useUnaryInterceptor";

// Internal configurations
public static final String SINGLE_REQUEST_PARAMETER = "singleRequestParameter";
Expand Down Expand Up @@ -149,6 +150,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
@Getter @Setter protected boolean failOnUnknownProperties = false;
@Setter protected boolean supportVertxFuture = false;
@Setter protected boolean useSealedOneOfInterfaces = false;
@Setter protected boolean useUnaryInterceptor = false;
protected String authFolder;
/**
* Serialization library.
Expand Down Expand Up @@ -260,6 +262,7 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(FAIL_ON_UNKNOWN_PROPERTIES, "Fail Jackson de-serialization on unknown properties", this.failOnUnknownProperties));
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.", this.supportVertxFuture));
cliOptions.add(CliOption.newBoolean(USE_SEALED_ONE_OF_INTERFACES, "Generate the oneOf interfaces as sealed interfaces. Only supported for WebClient and RestClient.", this.useSealedOneOfInterfaces));
cliOptions.add(CliOption.newBoolean(USE_UNARY_INTERCEPTOR, "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", this.useUnaryInterceptor));

supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.17.1");
supportedLibraries.put(JERSEY3, "HTTP client: Jersey client 3.1.1. JSON processing: Jackson 2.17.1");
Expand Down Expand Up @@ -376,6 +379,7 @@ public void processOpts() {
}
convertPropertyToStringAndWriteBack(CodegenConstants.USE_SINGLE_REQUEST_PARAMETER, this::setUseSingleRequestParameter);
convertPropertyToBooleanAndWriteBack(USE_SEALED_ONE_OF_INTERFACES, this::setUseSealedOneOfInterfaces);
convertPropertyToBooleanAndWriteBack(USE_UNARY_INTERCEPTOR, this::setUseUnaryInterceptor);
writePropertyBack(SINGLE_REQUEST_PARAMETER, getSingleRequestParameter());
writePropertyBack(STATIC_REQUEST, getStaticRequest());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import java.util.Objects;
import java.util.zip.GZIPOutputStream;
{{/useGzipFeature}}
import java.util.stream.Collectors;

{{#useUnaryInterceptor}}import java.util.function.UnaryOperator;{{/useUnaryInterceptor}}
import static java.nio.charset.StandardCharsets.UTF_8;

/**
Expand All @@ -64,8 +64,15 @@ public class ApiClient {
protected int port;
protected String basePath;
protected Consumer<HttpRequest.Builder> interceptor;
{{#useUnaryInterceptor}}
protected UnaryOperator<HttpResponse<InputStream>> responseInterceptor;
protected UnaryOperator<HttpResponse<InputStream>> asyncResponseInterceptor;
{{/useUnaryInterceptor}}
{{^useUnaryInterceptor}}
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
protected Consumer<HttpResponse<InputStream>> asyncResponseInterceptor;
{{/useUnaryInterceptor}}

protected Duration readTimeout;
protected Duration connectTimeout;

Expand Down Expand Up @@ -361,12 +368,12 @@ public class ApiClient {
* Set a custom response interceptor.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
*/
public ApiClient setResponseInterceptor(Consumer<HttpResponse<InputStream>> interceptor) {
public ApiClient setResponseInterceptor({{#useUnaryInterceptor}}UnaryOperator{{/useUnaryInterceptor}}{{^useUnaryInterceptor}}Consumer{{/useUnaryInterceptor}}<HttpResponse<InputStream>> interceptor) {
this.responseInterceptor = interceptor;
return this;
}
Expand All @@ -376,20 +383,20 @@ public class ApiClient {
*
* @return The custom interceptor that was set, or null if there isn't any.
*/
public Consumer<HttpResponse<InputStream>> getResponseInterceptor() {
public {{#useUnaryInterceptor}}UnaryOperator{{/useUnaryInterceptor}}{{^useUnaryInterceptor}}Consumer{{/useUnaryInterceptor}}<HttpResponse<InputStream>> getResponseInterceptor() {
return responseInterceptor;
}

/**
* Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
*/
public ApiClient setAsyncResponseInterceptor(Consumer<HttpResponse<InputStream>> interceptor) {
public ApiClient setAsyncResponseInterceptor({{#useUnaryInterceptor}}UnaryOperator{{/useUnaryInterceptor}}{{^useUnaryInterceptor}}Consumer{{/useUnaryInterceptor}}<HttpResponse<InputStream>> interceptor) {
this.asyncResponseInterceptor = interceptor;
return this;
}
Expand All @@ -399,7 +406,7 @@ public class ApiClient {
*
* @return The custom interceptor that was set, or null if there isn't any.
*/
public Consumer<HttpResponse<InputStream>> getAsyncResponseInterceptor() {
public {{#useUnaryInterceptor}}UnaryOperator{{/useUnaryInterceptor}}{{^useUnaryInterceptor}}Consumer{{/useUnaryInterceptor}}<HttpResponse<InputStream>> getAsyncResponseInterceptor() {
return asyncResponseInterceptor;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Locale;
{{#useUnaryInterceptor}}import java.util.function.UnaryOperator;{{/useUnaryInterceptor}}
import java.util.function.Consumer;
{{#useGzipFeature}}
import java.util.function.Supplier;
Expand Down Expand Up @@ -86,8 +87,14 @@ public class {{classname}} {
private final String memberVarBaseUri;
private final Consumer<HttpRequest.Builder> memberVarInterceptor;
private final Duration memberVarReadTimeout;
{{#useUnaryInterceptor}}
private final UnaryOperator<HttpResponse<InputStream>> memberVarResponseInterceptor;
private final UnaryOperator<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
{{/useUnaryInterceptor}}
{{^useUnaryInterceptor}}
private final Consumer<HttpResponse<InputStream>> memberVarResponseInterceptor;
private final Consumer<HttpResponse<InputStream>> memberVarAsyncResponseInterceptor;
{{/useUnaryInterceptor}}

public {{classname}}() {
this(Configuration.getDefaultApiClient());
Expand Down Expand Up @@ -433,7 +440,12 @@ public class {{classname}} {
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream());
if (memberVarResponseInterceptor != null) {
{{#useUnaryInterceptor}}
localVarResponse = memberVarResponseInterceptor.apply(localVarResponse);
{{/useUnaryInterceptor}}
{{^useUnaryInterceptor}}
memberVarResponseInterceptor.accept(localVarResponse);
{{/useUnaryInterceptor}}
}
InputStream localVarResponseBody = null;
try {
Expand Down Expand Up @@ -526,7 +538,12 @@ public class {{classname}} {
localVarRequestBuilder.build(),
HttpResponse.BodyHandlers.ofInputStream()).thenComposeAsync(localVarResponse -> {
if (memberVarAsyncResponseInterceptor != null) {
{{#useUnaryInterceptor}}
localVarResponse = memberVarAsyncResponseInterceptor.apply(localVarResponse);
{{/useUnaryInterceptor}}
{{^useUnaryInterceptor}}
memberVarAsyncResponseInterceptor.accept(localVarResponse);
{{/useUnaryInterceptor}}
}
if (localVarResponse.statusCode()/ 100 != 2) {
return CompletableFuture.failedFuture(getApiException("{{operationId}}", localVarResponse));
Expand Down Expand Up @@ -935,4 +952,4 @@ public class {{classname}} {
{{/vendorExtensions.x-group-parameters}}
{{/operation}}
}
{{/operations}}
{{/operations}}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ApiClient {
protected Consumer<HttpRequest.Builder> interceptor;
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
protected Consumer<HttpResponse<InputStream>> asyncResponseInterceptor;

protected Duration readTimeout;
protected Duration connectTimeout;

Expand Down Expand Up @@ -359,7 +360,7 @@ public Consumer<HttpRequest.Builder> getRequestInterceptor() {
* Set a custom response interceptor.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand All @@ -382,7 +383,7 @@ public Consumer<HttpResponse<InputStream>> getResponseInterceptor() {
* Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ApiClient {
protected Consumer<HttpRequest.Builder> interceptor;
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
protected Consumer<HttpResponse<InputStream>> asyncResponseInterceptor;

protected Duration readTimeout;
protected Duration connectTimeout;

Expand Down Expand Up @@ -359,7 +360,7 @@ public Consumer<HttpRequest.Builder> getRequestInterceptor() {
* Set a custom response interceptor.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand All @@ -382,7 +383,7 @@ public Consumer<HttpResponse<InputStream>> getResponseInterceptor() {
* Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public class ApiClient {
protected Consumer<HttpRequest.Builder> interceptor;
protected Consumer<HttpResponse<InputStream>> responseInterceptor;
protected Consumer<HttpResponse<InputStream>> asyncResponseInterceptor;

protected Duration readTimeout;
protected Duration connectTimeout;

Expand Down Expand Up @@ -359,7 +360,7 @@ public Consumer<HttpRequest.Builder> getRequestInterceptor() {
* Set a custom response interceptor.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand All @@ -382,7 +383,7 @@ public Consumer<HttpResponse<InputStream>> getResponseInterceptor() {
* Set a custom async response interceptor. Use this interceptor when asyncNative is set to 'true'.
*
* <p>This is useful for logging, monitoring or extraction of header variables</p>
*
* <p>If you are using the UnaryInterceptor you can even manipulate the response to a certain degree</p>
* @param interceptor A function invoked before creating each request. A value
* of null resets the interceptor to a no-op.
* @return This object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Map;
import java.util.Set;
import java.util.Locale;

import java.util.function.Consumer;

@jakarta.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", comments = "Generator version: 7.18.0-SNAPSHOT")
Expand Down
Loading