From 3bd6d67cc0b0517d39044213d199588bdcbc235f Mon Sep 17 00:00:00 2001 From: William Cheng Date: Thu, 25 Apr 2024 12:51:18 +0800 Subject: [PATCH] (java client) minor code enhancements (#18493) * (java client) minor code enhancements * update doc --- docs/generators/java.md | 2 +- .../codegen/languages/JavaClientCodegen.java | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/docs/generators/java.md b/docs/generators/java.md index e08e5d2a6f..b6eab0d23e 100644 --- a/docs/generators/java.md +++ b/docs/generators/java.md @@ -47,7 +47,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |dynamicOperations|Generate operations dynamically at runtime from an OAS| |false| |ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| |enumUnknownDefaultCase|If the server adds new enum cases, that are unknown by an old spec/client, the client will fail to parse the network response.With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the server sends an enum case that is not known by the client/spec, they can safely fallback to this case.|
**false**
No changes to the enum's are made, this is the default option.
**true**
With this option enabled, each enum will have a new case, 'unknown_default_open_api', so that when the enum case sent by the server is not known by the client/spec, can safely be decoded to this case.
|false| -|errorObjectType|Error Object type. (This option is for okhttp-gson-next-gen only)| |null| +|errorObjectType|Error Object type. (This option is for okhttp-gson only)| |null| |generateClientAsBean|For resttemplate, configure whether to create `ApiClient.java` and Apis clients as bean (with `@Component` annotation).| |false| |gradleProperties|Append additional Gradle properties to the gradle.properties file| |null| |groupId|groupId in generated pom.xml| |org.openapitools| 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 a69084590f..dcf4f15722 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 @@ -182,10 +182,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen .includeDocumentationFeatures(DocumentationFeature.Readme) .includeGlobalFeatures(GlobalFeature.ParameterizedServer) .includeSecurityFeatures(SecurityFeature.OAuth2_AuthorizationCode, - SecurityFeature.OAuth2_ClientCredentials, - SecurityFeature.OAuth2_Password, - SecurityFeature.SignatureAuth,//jersey only - SecurityFeature.AWSV4Signature)//okhttp-gson only + SecurityFeature.OAuth2_ClientCredentials, + SecurityFeature.OAuth2_Password, + SecurityFeature.SignatureAuth,//jersey only + SecurityFeature.AWSV4Signature)//okhttp-gson only ); outputFolder = "generated-code" + File.separator + "java"; @@ -222,7 +222,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen cliOptions.add(CliOption.newBoolean(SUPPORT_STREAMING, "Support streaming endpoint (beta)", this.supportStreaming)); cliOptions.add(CliOption.newBoolean(CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT, CodegenConstants.WITH_AWSV4_SIGNATURE_COMMENT_DESC + " (only available for okhttp-gson library)", this.withAWSV4Signature)); cliOptions.add(CliOption.newString(GRADLE_PROPERTIES, "Append additional Gradle properties to the gradle.properties file")); - cliOptions.add(CliOption.newString(ERROR_OBJECT_TYPE, "Error Object type. (This option is for okhttp-gson-next-gen only)")); + cliOptions.add(CliOption.newString(ERROR_OBJECT_TYPE, "Error Object type. (This option is for okhttp-gson only)")); cliOptions.add(CliOption.newString(CONFIG_KEY, "Config key in @RegisterRestClient. Default to none. Only `microprofile` supports this option.")); cliOptions.add(CliOption.newBoolean(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP_DESC + " Only jersey2, jersey3, native, okhttp-gson support this option.")); cliOptions.add(CliOption.newString(MICROPROFILE_REST_CLIENT_VERSION, "Version of MicroProfile Rest Client API.")); @@ -472,15 +472,13 @@ public class JavaClientCodegen extends AbstractJavaCodegen if (additionalProperties.containsKey(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY)) { this.setMaxAttemptsForRetry(Integer.parseInt(additionalProperties.get(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY).toString())); - } - else { + } else { additionalProperties.put(CodegenConstants.MAX_ATTEMPTS_FOR_RETRY, maxAttemptsForRetry); } if (additionalProperties.containsKey(CodegenConstants.WAIT_TIME_OF_THREAD)) { this.setWaitTimeMillis(Long.parseLong((additionalProperties.get(CodegenConstants.WAIT_TIME_OF_THREAD).toString()))); - } - else { + } else { additionalProperties.put(CodegenConstants.WAIT_TIME_OF_THREAD, waitTimeMillis); } writePropertyBack(USE_ENUM_CASE_INSENSITIVE, useEnumCaseInsensitive); @@ -1264,11 +1262,11 @@ public class JavaClientCodegen extends AbstractJavaCodegen } public void setMaxAttemptsForRetry(int maxAttemptsForRetry) { - this.maxAttemptsForRetry= maxAttemptsForRetry; + this.maxAttemptsForRetry = maxAttemptsForRetry; } public void setWaitTimeMillis(long waitTimeMillis) { - this.waitTimeMillis= waitTimeMillis; + this.waitTimeMillis = waitTimeMillis; } /**