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
|
||||
}
|
||||
}
|
||||
|
||||
// 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())) && ProcessUtils.hasOAuthMethods(objs)) {
|
||||
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)) {
|
||||
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,6 +10,8 @@ import java.util.Map;
|
||||
|
||||
public class ProcessUtils {
|
||||
|
||||
private static Boolean hasOAuthMethods;
|
||||
|
||||
/**
|
||||
* Add x-index extension to the model's properties
|
||||
*
|
||||
@ -66,7 +68,6 @@ public class ProcessUtils {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user