diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index a3e844df37b..a41e57378aa 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -1508,7 +1508,7 @@ public class DefaultCodegen implements CodegenConfig { * * @param name string to be capitalized * @return capitalized string - * @deprecated + * @deprecated use {@link org.openapitools.codegen.utils.StringUtils#camelize(String)} instead */ @SuppressWarnings("static-method") public String initialCaps(String name) { 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 33081f30a0c..14f55484815 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 @@ -53,9 +53,11 @@ import java.util.regex.Pattern; import {{invokerPackage}}.auth.Authentication; import {{invokerPackage}}.auth.HttpBasicAuth; import {{invokerPackage}}.auth.ApiKeyAuth; +{{#hasOAuthMethods}} import {{invokerPackage}}.auth.OAuth; import {{invokerPackage}}.auth.RetryingOAuth; import {{invokerPackage}}.auth.OAuthFlow; +{{/hasOAuthMethods}} public class ApiClient { @@ -117,12 +119,14 @@ public class ApiClient { public ApiClient(String clientId, String clientSecret, Map parameters) { init(); +{{#hasOAuthMethods}} RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, OAuthFlow.{{flow}}, clientSecret, parameters); authentications.put( "{{name}}", retryingOAuth ); httpClient.interceptors().add(retryingOAuth); +{{/hasOAuthMethods}} // Prevent the authentications from being modified. authentications = Collections.unmodifiableMap(authentications); @@ -399,12 +403,14 @@ public class ApiClient { * @param accessToken Access token */ public void setAccessToken(String accessToken) { + {{#hasOAuthMethods}} for (Authentication auth : authentications.values()) { if (auth instanceof OAuth) { ((OAuth) auth).setAccessToken(accessToken); return; } } + {{/hasOAuthMethods}} throw new RuntimeException("No OAuth2 authentication configured!"); } @@ -550,6 +556,7 @@ public class ApiClient { return this; } + {{#hasOAuthMethods}} /** * Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one) * @return Token request builder @@ -563,6 +570,7 @@ public class ApiClient { } return null; } + {{/hasOAuthMethods}} /** * Format the given parameter object into string. diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/OAuthOkHttpClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/OAuthOkHttpClient.mustache index 6886c2fc358..5460132cdb1 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/OAuthOkHttpClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/OAuthOkHttpClient.mustache @@ -1,3 +1,4 @@ +{{#hasOAuthMethods}} package {{invokerPackage}}.auth; import com.squareup.okhttp.OkHttpClient; @@ -66,3 +67,4 @@ public class OAuthOkHttpClient implements HttpClient { // Nothing to do here } } +{{/hasOAuthMethods}} \ No newline at end of file diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache index 11ef3c3ca61..5cf6fe7e294 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/okhttp-gson/auth/RetryingOAuth.mustache @@ -1,3 +1,4 @@ +{{#hasOAuthMethods}} package {{invokerPackage}}.auth; import {{invokerPackage}}.Pair; @@ -172,3 +173,4 @@ public class RetryingOAuth extends OAuth implements Interceptor { // No implementation necessary } } +{{/hasOAuthMethods}} \ No newline at end of file