forked from loafle/openapi-generator-original
[Java] Fix repeated OAuth files being generated (#6285)
* fix repeated oauth files being generated * fix oauth check
This commit is contained in:
parent
9c4b37299a
commit
c95bc4dfb0
@ -106,6 +106,9 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
protected String authFolder;
|
||||
protected String serializationLibrary = null;
|
||||
|
||||
protected boolean addOAuthSupportingFiles = false;
|
||||
protected boolean addOAuthRetrySupportingFiles = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
|
||||
@ -368,7 +371,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
supportingFiles.add(new SupportingFile("ProgressResponseBody.mustache", invokerFolder, "ProgressResponseBody.java"));
|
||||
supportingFiles.add(new SupportingFile("GzipRequestInterceptor.mustache", invokerFolder, "GzipRequestInterceptor.java"));
|
||||
|
||||
// NOTE: below moved to postProcessOpoerationsWithModels
|
||||
// NOTE: below moved to postProcessOperationsWithModels
|
||||
//supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
//supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java"));
|
||||
forceSerializationLibrary(SERIALIZATION_LIBRARY_GSON);
|
||||
@ -588,16 +591,22 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
}
|
||||
|
||||
// for okhttp-gson (default), check to see if OAuth is defined and included OAuth-related files accordingly
|
||||
if ((OKHTTP_GSON.equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) && ProcessUtils.hasOAuthMethods(objs)) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java"));
|
||||
}
|
||||
// has OAuth defined
|
||||
if (ProcessUtils.hasOAuthMethods(objs)) {
|
||||
// for okhttp-gson (default), check to see if OAuth is defined and included OAuth-related files accordingly
|
||||
if ((OKHTTP_GSON.equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) && !addOAuthRetrySupportingFiles) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java"));
|
||||
addOAuthRetrySupportingFiles = true; // add only once
|
||||
}
|
||||
|
||||
// google-api-client doesn't use the OpenAPI auth, because it uses Google Credential directly (HttpRequestInitializer)
|
||||
if ((!(GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || usePlayWS || NATIVE.equals(getLibrary()) || MICROPROFILE.equals(getLibrary()))) && ProcessUtils.hasOAuthMethods(objs)) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
// google-api-client doesn't use the OpenAPI auth, because it uses Google Credential directly (HttpRequestInitializer)
|
||||
if (!(GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || usePlayWS
|
||||
|| NATIVE.equals(getLibrary()) || MICROPROFILE.equals(getLibrary())) && !addOAuthSupportingFiles) {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
|
||||
addOAuthSupportingFiles = true; // add only once
|
||||
}
|
||||
}
|
||||
|
||||
if (MICROPROFILE.equals(getLibrary())) {
|
||||
|
@ -10,10 +10,12 @@ import java.util.Map;
|
||||
|
||||
public class ProcessUtils {
|
||||
|
||||
private static Boolean hasOAuthMethods;
|
||||
|
||||
/**
|
||||
* Add x-index extension to the model's properties
|
||||
*
|
||||
* @param models List of models
|
||||
* @param models List of models
|
||||
* @param initialIndex starting index to use
|
||||
*/
|
||||
public static void addIndexToProperties(List<Object> models, int initialIndex) {
|
||||
@ -66,7 +68,6 @@ public class ProcessUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -103,11 +104,11 @@ public class ProcessUtils {
|
||||
*/
|
||||
public static boolean hasHttpBasicMethods(List<CodegenSecurity> authMethods) {
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isBasicBasic)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isBasicBasic)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -120,11 +121,11 @@ public class ProcessUtils {
|
||||
*/
|
||||
public static boolean hasApiKeyMethods(List<CodegenSecurity> authMethods) {
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isApiKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isApiKey)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -139,11 +140,11 @@ public class ProcessUtils {
|
||||
*/
|
||||
public static boolean hasHttpSignatureMethods(List<CodegenSecurity> authMethods) {
|
||||
if (authMethods != null && !authMethods.isEmpty()) {
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isHttpSignature)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (CodegenSecurity cs : authMethods) {
|
||||
if (Boolean.TRUE.equals(cs.isHttpSignature)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user