mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-03 06:00:52 +00:00
[java-client][okhttp-gson] no oauth2 usage when hasOAuthMethods is false (#1872)
* Fix Javadoc error * [java-client][okhttp-gson] no oauth2 usage when hasOAuthMethods is false
This commit is contained in:
parent
faf1f5d81d
commit
8305df6b4a
@ -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) {
|
||||
|
@ -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<String, String> 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.
|
||||
|
@ -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}}
|
@ -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}}
|
Loading…
x
Reference in New Issue
Block a user