diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache index 026c04dd9c2..9ec0f795219 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/webclient/ApiClient.mustache @@ -117,7 +117,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } {{#generateClientAsBean}} @@ -139,7 +139,7 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -163,15 +163,16 @@ public class ApiClient{{#jsr310}} extends JavaTimeFormatter{{/jsr310}} { return mapper; } - protected void init() { + protected static Map buildAuthentications() {{=<% %>=}}{<%={{ }}=%>{{#authMethods.0}} // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} + Map authentications = new HashMap<>();{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} authentications.put("{{name}}", new HttpBasicAuth());{{/isBasicBasic}}{{#isBasicBearer}} authentications.put("{{name}}", new HttpBearerAuth("{{scheme}}"));{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} authentications.put("{{name}}", new ApiKeyAuth({{#isKeyInHeader}}"header"{{/isKeyInHeader}}{{#isKeyInQuery}}"query"{{/isKeyInQuery}}{{#isKeyInCookie}}"cookie"{{/isKeyInCookie}}, "{{keyParamName}}"));{{/isApiKey}}{{#isOAuth}} authentications.put("{{name}}", new OAuth());{{/isOAuth}}{{/authMethods}} // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + return Collections.unmodifiableMap(authentications);{{/authMethods.0}}{{^authMethods.0}} + return Collections.emptyMap();{{/authMethods.0}} } /** diff --git a/samples/client/others/java/webclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/others/java/webclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java index 3dc2ed2c7c1..2470859ca23 100644 --- a/samples/client/others/java/webclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/others/java/webclient-useAbstractionForFiles/src/main/java/org/openapitools/client/ApiClient.java @@ -112,7 +112,7 @@ public class ApiClient extends JavaTimeFormatter { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } public ApiClient(WebClient webClient) { @@ -131,7 +131,7 @@ public class ApiClient extends JavaTimeFormatter { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -153,11 +153,8 @@ public class ApiClient extends JavaTimeFormatter { return mapper; } - protected void init() { - // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); - // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + protected static Map buildAuthentications() { + return Collections.emptyMap(); } /** diff --git a/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/ApiClient.java index 63181b4f618..517fd6f8cf9 100644 --- a/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient-jakarta/src/main/java/org/openapitools/client/ApiClient.java @@ -113,7 +113,7 @@ public class ApiClient extends JavaTimeFormatter { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } public ApiClient(WebClient webClient) { @@ -132,7 +132,7 @@ public class ApiClient extends JavaTimeFormatter { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -154,16 +154,16 @@ public class ApiClient extends JavaTimeFormatter { return mapper; } - protected void init() { + protected static Map buildAuthentications() { // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); + Map authentications = new HashMap<>(); authentications.put("petstore_auth", new OAuth()); authentications.put("api_key", new ApiKeyAuth("header", "api_key")); authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query")); authentications.put("http_basic_test", new HttpBasicAuth()); authentications.put("bearer_test", new HttpBearerAuth("bearer")); // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + return Collections.unmodifiableMap(authentications); } /** diff --git a/samples/client/petstore/java/webclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java index 8b998104492..d37baf5cb95 100644 --- a/samples/client/petstore/java/webclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient-nullable-arrays/src/main/java/org/openapitools/client/ApiClient.java @@ -112,7 +112,7 @@ public class ApiClient extends JavaTimeFormatter { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } public ApiClient(WebClient webClient) { @@ -131,7 +131,7 @@ public class ApiClient extends JavaTimeFormatter { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -153,11 +153,8 @@ public class ApiClient extends JavaTimeFormatter { return mapper; } - protected void init() { - // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); - // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + protected static Map buildAuthentications() { + return Collections.emptyMap(); } /** diff --git a/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java index 5502ac03a91..8d6e1090cd8 100644 --- a/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient-swagger2/src/main/java/org/openapitools/client/ApiClient.java @@ -113,7 +113,7 @@ public class ApiClient extends JavaTimeFormatter { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } public ApiClient(WebClient webClient) { @@ -132,7 +132,7 @@ public class ApiClient extends JavaTimeFormatter { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -154,16 +154,16 @@ public class ApiClient extends JavaTimeFormatter { return mapper; } - protected void init() { + protected static Map buildAuthentications() { // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); + Map authentications = new HashMap<>(); authentications.put("petstore_auth", new OAuth()); authentications.put("api_key", new ApiKeyAuth("header", "api_key")); authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query")); authentications.put("http_basic_test", new HttpBasicAuth()); authentications.put("bearer_test", new HttpBearerAuth("bearer")); // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + return Collections.unmodifiableMap(authentications); } /** diff --git a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java index 5502ac03a91..8d6e1090cd8 100644 --- a/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java +++ b/samples/client/petstore/java/webclient/src/main/java/org/openapitools/client/ApiClient.java @@ -113,7 +113,7 @@ public class ApiClient extends JavaTimeFormatter { this.dateFormat = createDefaultDateFormat(); this.objectMapper = createDefaultObjectMapper(this.dateFormat); this.webClient = buildWebClient(this.objectMapper); - this.init(); + this.authentications = buildAuthentications(); } public ApiClient(WebClient webClient) { @@ -132,7 +132,7 @@ public class ApiClient extends JavaTimeFormatter { this.webClient = webClient; this.dateFormat = format; this.objectMapper = createDefaultObjectMapper(format); - this.init(); + this.authentications = buildAuthentications(); } public static DateFormat createDefaultDateFormat() { @@ -154,16 +154,16 @@ public class ApiClient extends JavaTimeFormatter { return mapper; } - protected void init() { + protected static Map buildAuthentications() { // Setup authentications (key: authentication name, value: authentication). - authentications = new HashMap(); + Map authentications = new HashMap<>(); authentications.put("petstore_auth", new OAuth()); authentications.put("api_key", new ApiKeyAuth("header", "api_key")); authentications.put("api_key_query", new ApiKeyAuth("query", "api_key_query")); authentications.put("http_basic_test", new HttpBasicAuth()); authentications.put("bearer_test", new HttpBearerAuth("bearer")); // Prevent the authentications from being modified. - authentications = Collections.unmodifiableMap(authentications); + return Collections.unmodifiableMap(authentications); } /**