diff --git a/bin/java-petstore-feign-10x.json b/bin/java-petstore-feign-10x.json index d8f09eb65a..95949f4a93 100644 --- a/bin/java-petstore-feign-10x.json +++ b/bin/java-petstore-feign-10x.json @@ -1,5 +1,4 @@ { "library": "feign", - "artifactId": "petstore-feign-10x", - "feignVersion": "10.x" + "artifactId": "petstore-feign-10x" } diff --git a/docs/generators/java.md b/docs/generators/java.md index 2c4c4691a0..2e3c153c08 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -22,13 +22,13 @@ sidebar_label: java |developerOrganizationUrl|developer organization URL in generated pom.xml| |http://openapitools.org| |disableHtmlEscaping|Disable HTML escaping of JSON strings when using gson (needed to avoid problems with byte[] fields)| |false| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| -|feignVersion|Version of OpenFeign: '10.x', '9.x' (default)| |false| +|feignVersion|Version of OpenFeign: '10.x' (default), '9.x' (deprecated)| |false| |fullJavaUtil|whether to use fully qualified name for classes under java.util. This option only works for Java API client| |false| |groupId|groupId in generated pom.xml| |org.openapitools| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |false| |invokerPackage|root package for generated code| |org.openapitools.client| |java8|Option. Use Java8 classes instead of third party equivalents|
**true**
Use Java 8 classes such as Base64
**false**
Various third party libraries as needed
|false| -|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey2' or other HTTP libaries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**feign**
HTTP client: OpenFeign 9.x or 10.x. JSON processing: Jackson 2.9.x. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit**
HTTP client: OkHttp 2.x. JSON processing: Gson 2.x (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.9.x. Only for Java8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client X.x. JSON processing: Jackson 2.9.x
|okhttp-gson| +|library|library template (sub-template) to use|
**jersey1**
HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey2' or other HTTP libaries instead.
**jersey2**
HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x
**feign**
HTTP client: OpenFeign 9.x (deprecated) or 10.x (default). JSON processing: Jackson 2.9.x.
**okhttp-gson**
[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.
**retrofit**
HTTP client: OkHttp 2.x. JSON processing: Gson 2.x (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead.
**retrofit2**
HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)
**resttemplate**
HTTP client: Spring RestTemplate 4.x. JSON processing: Jackson 2.9.x
**webclient**
HTTP client: Spring WebClient 5.x. JSON processing: Jackson 2.9.x
**resteasy**
HTTP client: Resteasy client 3.x. JSON processing: Jackson 2.9.x
**vertx**
HTTP client: VertX client 3.x. JSON processing: Jackson 2.9.x
**google-api-client**
HTTP client: Google API client 1.x. JSON processing: Jackson 2.9.x
**rest-assured**
HTTP client: rest-assured : 4.x. JSON processing: Gson 2.x or Jackson 2.9.x. Only for Java8
**native**
HTTP client: Java native HttpClient. JSON processing: Jackson 2.9.x. Only for Java11+
**microprofile**
HTTP client: Microprofile client X.x. JSON processing: Jackson 2.9.x
|okhttp-gson| |licenseName|The name of the license| |Unlicense| |licenseUrl|The URL of the license| |http://unlicense.org| |modelPackage|package for generated models| |org.openapitools.client.model| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index 6aa926c085..fe79a9641f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -17,6 +17,8 @@ package org.openapitools.codegen.languages; +import io.swagger.v3.oas.models.Operation; +import io.swagger.v3.oas.models.media.Schema; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.*; @@ -29,9 +31,6 @@ import org.openapitools.codegen.utils.ProcessUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import io.swagger.v3.oas.models.Operation; -import io.swagger.v3.oas.models.media.Schema; - import java.io.File; import java.util.*; import java.util.regex.Pattern; @@ -93,7 +92,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen protected boolean doNotUseRx = true; protected boolean usePlayWS = false; protected String playVersion = PLAY_25; - protected String feignVersion = FEIGN_9; + protected String feignVersion = FEIGN_10; protected boolean parcelableModel = false; protected boolean useBeanValidation = false; protected boolean performBeanValidation = false; @@ -136,13 +135,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation")); cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests")); cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception")); - cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x', '9.x' (default)")); + cliOptions.add(CliOption.newBoolean(FEIGN_VERSION, "Version of OpenFeign: '10.x' (default), '9.x' (deprecated)")); cliOptions.add(CliOption.newBoolean(USE_REFLECTION_EQUALS_HASHCODE, "Use org.apache.commons.lang3.builder for equals and hashCode in the models. WARNING: This will fail under a security manager, unless the appropriate permissions are set up correctly and also there's potential performance impact.")); cliOptions.add(CliOption.newBoolean(CASE_INSENSITIVE_RESPONSE_HEADERS, "Make API response's headers case-insensitive. Available on " + OKHTTP_GSON + ", " + JERSEY2 + " libraries")); supportedLibraries.put(JERSEY1, "HTTP client: Jersey client 1.19.x. JSON processing: Jackson 2.9.x. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'. IMPORTANT NOTE: jersey 1.x is no longer actively maintained so please upgrade to 'jersey2' or other HTTP libaries instead."); supportedLibraries.put(JERSEY2, "HTTP client: Jersey client 2.25.1. JSON processing: Jackson 2.9.x"); - supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.x or 10.x. JSON processing: Jackson 2.9.x. To enable OpenFeign 10.x, set the 'feignVersion' option to '10.x'"); + supportedLibraries.put(FEIGN, "HTTP client: OpenFeign 9.x (deprecated) or 10.x (default). JSON processing: Jackson 2.9.x."); supportedLibraries.put(OKHTTP_GSON, "[DEFAULT] HTTP client: OkHttp 3.x. JSON processing: Gson 2.8.x. Enable Parcelable models on Android using '-DparcelableModel=true'. Enable gzip request encoding using '-DuseGzipFeature=true'."); supportedLibraries.put(RETROFIT_1, "HTTP client: OkHttp 2.x. JSON processing: Gson 2.x (Retrofit 1.9.0). IMPORTANT NOTE: retrofit1.x is no longer actively maintained so please upgrade to 'retrofit2' instead."); supportedLibraries.put(RETROFIT_2, "HTTP client: OkHttp 3.x. JSON processing: Gson 2.x (Retrofit 2.3.0). Enable the RxJava adapter using '-DuseRxJava[2]=true'. (RxJava 1.x or 2.x)"); @@ -197,8 +196,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen public void processOpts() { if ((WEBCLIENT.equals(getLibrary()) && "threetenbp".equals(dateLibrary)) || NATIVE.equals(getLibrary())) { dateLibrary = "java8"; - } - else if (MICROPROFILE.equals(getLibrary())) { + } else if (MICROPROFILE.equals(getLibrary())) { dateLibrary = "legacy"; } @@ -235,10 +233,14 @@ public class JavaClientCodegen extends AbstractJavaCodegen if ("10.x".equals(feignVersion)) { additionalProperties.put("useFeign10", true); } else if ("9.x".equals(feignVersion)) { - // do nothing as 9.x is the default + additionalProperties.put("useFeign10", false); + once(LOGGER).warn("Feign 9.x support has been deprecated. Please use 10.x (default) instead."); } else { - throw new RuntimeException("Ivalid feignOoption '{}'. Must be '10.x' or '9.x'."); + throw new RuntimeException("Ivalid feignOoption '{}'. Must be '10.x' or '9.x' (deprecated)."); } + } else { + // default to feign 10.x + additionalProperties.put("useFeign10", true); } additionalProperties.put(FEIGN_VERSION, feignVersion); @@ -390,11 +392,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); } else if (REST_ASSURED.equals(getLibrary())) { - if(getSerializationLibrary() == null) { - LOGGER.info("No serializationLibrary configured, using '"+SERIALIZATION_LIBRARY_GSON+"' as fallback"); + if (getSerializationLibrary() == null) { + LOGGER.info("No serializationLibrary configured, using '" + SERIALIZATION_LIBRARY_GSON + "' as fallback"); setSerializationLibrary(SERIALIZATION_LIBRARY_GSON); } - if(SERIALIZATION_LIBRARY_JACKSON.equals(getSerializationLibrary())) { + if (SERIALIZATION_LIBRARY_JACKSON.equals(getSerializationLibrary())) { supportingFiles.add(new SupportingFile("JacksonObjectMapper.mustache", invokerFolder, "JacksonObjectMapper.java")); } else if (SERIALIZATION_LIBRARY_GSON.equals(getSerializationLibrary())) { supportingFiles.add(new SupportingFile("JSON.mustache", invokerFolder, "JSON.java")); @@ -468,11 +470,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); } - if(getSerializationLibrary() == null) { - LOGGER.info("No serializationLibrary configured, using '"+SERIALIZATION_LIBRARY_GSON+"' as fallback"); + if (getSerializationLibrary() == null) { + LOGGER.info("No serializationLibrary configured, using '" + SERIALIZATION_LIBRARY_GSON + "' as fallback"); setSerializationLibrary(SERIALIZATION_LIBRARY_GSON); } - if(SERIALIZATION_LIBRARY_JACKSON.equals(getSerializationLibrary())) { + if (SERIALIZATION_LIBRARY_JACKSON.equals(getSerializationLibrary())) { additionalProperties.put(SERIALIZATION_LIBRARY_JACKSON, "true"); additionalProperties.remove(SERIALIZATION_LIBRARY_GSON); if (!NATIVE.equals(getLibrary())) { @@ -681,6 +683,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen model.imports.remove("ToStringSerializer"); } } + @Override public CodegenModel fromModel(String name, Schema model) { CodegenModel codegenModel = super.fromModel(name, model); @@ -821,6 +824,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen /** * Serialization library. + * * @return 'gson' or 'jackson' */ public String getSerializationLibrary() { @@ -828,9 +832,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen } public void setSerializationLibrary(String serializationLibrary) { - if(SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) { + if (SERIALIZATION_LIBRARY_JACKSON.equalsIgnoreCase(serializationLibrary)) { this.serializationLibrary = SERIALIZATION_LIBRARY_JACKSON; - } else if(SERIALIZATION_LIBRARY_GSON.equalsIgnoreCase(serializationLibrary)) { + } else if (SERIALIZATION_LIBRARY_GSON.equalsIgnoreCase(serializationLibrary)) { this.serializationLibrary = SERIALIZATION_LIBRARY_GSON; } else { throw new IllegalArgumentException("Unexpected serializationLibrary value: " + serializationLibrary); @@ -838,7 +842,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen } public void forceSerializationLibrary(String serializationLibrary) { - if((this.serializationLibrary != null) && !this.serializationLibrary.equalsIgnoreCase(serializationLibrary)) { + if ((this.serializationLibrary != null) && !this.serializationLibrary.equalsIgnoreCase(serializationLibrary)) { LOGGER.warn("The configured serializationLibrary '" + this.serializationLibrary + "', is not supported by the library: '" + getLibrary() + "', switching back to: " + serializationLibrary); } setSerializationLibrary(serializationLibrary); diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache index 1d3511364c..1f0e606d87 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/ApiClient.mustache @@ -151,8 +151,8 @@ public class ApiClient { builder.addInterceptor(interceptor); } {{#useGzipFeature}} - // Enable gzip request compression - builder.addInterceptor(new GzipRequestInterceptor()); + // Enable gzip request compression + builder.addInterceptor(new GzipRequestInterceptor()); {{/useGzipFeature}} httpClient = builder.build();