forked from loafle/openapi-generator-original
[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
|
* @param name string to be capitalized
|
||||||
* @return capitalized string
|
* @return capitalized string
|
||||||
* @deprecated
|
* @deprecated use {@link org.openapitools.codegen.utils.StringUtils#camelize(String)} instead
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("static-method")
|
@SuppressWarnings("static-method")
|
||||||
public String initialCaps(String name) {
|
public String initialCaps(String name) {
|
||||||
|
@ -53,9 +53,11 @@ import java.util.regex.Pattern;
|
|||||||
import {{invokerPackage}}.auth.Authentication;
|
import {{invokerPackage}}.auth.Authentication;
|
||||||
import {{invokerPackage}}.auth.HttpBasicAuth;
|
import {{invokerPackage}}.auth.HttpBasicAuth;
|
||||||
import {{invokerPackage}}.auth.ApiKeyAuth;
|
import {{invokerPackage}}.auth.ApiKeyAuth;
|
||||||
|
{{#hasOAuthMethods}}
|
||||||
import {{invokerPackage}}.auth.OAuth;
|
import {{invokerPackage}}.auth.OAuth;
|
||||||
import {{invokerPackage}}.auth.RetryingOAuth;
|
import {{invokerPackage}}.auth.RetryingOAuth;
|
||||||
import {{invokerPackage}}.auth.OAuthFlow;
|
import {{invokerPackage}}.auth.OAuthFlow;
|
||||||
|
{{/hasOAuthMethods}}
|
||||||
|
|
||||||
public class ApiClient {
|
public class ApiClient {
|
||||||
|
|
||||||
@ -117,12 +119,14 @@ public class ApiClient {
|
|||||||
public ApiClient(String clientId, String clientSecret, Map<String, String> parameters) {
|
public ApiClient(String clientId, String clientSecret, Map<String, String> parameters) {
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
{{#hasOAuthMethods}}
|
||||||
RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, OAuthFlow.{{flow}}, clientSecret, parameters);
|
RetryingOAuth retryingOAuth = new RetryingOAuth("{{tokenUrl}}", clientId, OAuthFlow.{{flow}}, clientSecret, parameters);
|
||||||
authentications.put(
|
authentications.put(
|
||||||
"{{name}}",
|
"{{name}}",
|
||||||
retryingOAuth
|
retryingOAuth
|
||||||
);
|
);
|
||||||
httpClient.interceptors().add(retryingOAuth);
|
httpClient.interceptors().add(retryingOAuth);
|
||||||
|
{{/hasOAuthMethods}}
|
||||||
|
|
||||||
// Prevent the authentications from being modified.
|
// Prevent the authentications from being modified.
|
||||||
authentications = Collections.unmodifiableMap(authentications);
|
authentications = Collections.unmodifiableMap(authentications);
|
||||||
@ -399,12 +403,14 @@ public class ApiClient {
|
|||||||
* @param accessToken Access token
|
* @param accessToken Access token
|
||||||
*/
|
*/
|
||||||
public void setAccessToken(String accessToken) {
|
public void setAccessToken(String accessToken) {
|
||||||
|
{{#hasOAuthMethods}}
|
||||||
for (Authentication auth : authentications.values()) {
|
for (Authentication auth : authentications.values()) {
|
||||||
if (auth instanceof OAuth) {
|
if (auth instanceof OAuth) {
|
||||||
((OAuth) auth).setAccessToken(accessToken);
|
((OAuth) auth).setAccessToken(accessToken);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{{/hasOAuthMethods}}
|
||||||
throw new RuntimeException("No OAuth2 authentication configured!");
|
throw new RuntimeException("No OAuth2 authentication configured!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -550,6 +556,7 @@ public class ApiClient {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{{#hasOAuthMethods}}
|
||||||
/**
|
/**
|
||||||
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
|
* Helper method to configure the token endpoint of the first oauth found in the apiAuthorizations (there should be only one)
|
||||||
* @return Token request builder
|
* @return Token request builder
|
||||||
@ -563,6 +570,7 @@ public class ApiClient {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
{{/hasOAuthMethods}}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format the given parameter object into string.
|
* Format the given parameter object into string.
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
{{#hasOAuthMethods}}
|
||||||
package {{invokerPackage}}.auth;
|
package {{invokerPackage}}.auth;
|
||||||
|
|
||||||
import com.squareup.okhttp.OkHttpClient;
|
import com.squareup.okhttp.OkHttpClient;
|
||||||
@ -66,3 +67,4 @@ public class OAuthOkHttpClient implements HttpClient {
|
|||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{{/hasOAuthMethods}}
|
@ -1,3 +1,4 @@
|
|||||||
|
{{#hasOAuthMethods}}
|
||||||
package {{invokerPackage}}.auth;
|
package {{invokerPackage}}.auth;
|
||||||
|
|
||||||
import {{invokerPackage}}.Pair;
|
import {{invokerPackage}}.Pair;
|
||||||
@ -172,3 +173,4 @@ public class RetryingOAuth extends OAuth implements Interceptor {
|
|||||||
// No implementation necessary
|
// No implementation necessary
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{{/hasOAuthMethods}}
|
Loading…
x
Reference in New Issue
Block a user