[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:
Jérémie Bresson 2019-01-10 15:00:45 +01:00 committed by William Cheng
parent faf1f5d81d
commit 8305df6b4a
4 changed files with 13 additions and 1 deletions

View File

@ -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) {

View File

@ -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.

View File

@ -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}}

View File

@ -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}}