From 17977da7ac03ed3de1914d19b3f9f833caf7d51b Mon Sep 17 00:00:00 2001 From: Hugo Alves <hugo.ma.alves@gmail.com> Date: Wed, 12 May 2021 17:00:51 +0100 Subject: [PATCH 1/2] Do not create OAuth classes when the client doesn't have security configured --- .../codegen/languages/JavaClientCodegen.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java index f82aba5b284..3fad08665e9 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaClientCodegen.java @@ -394,9 +394,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen forceSerializationLibrary(SERIALIZATION_LIBRARY_JACKSON); supportingFiles.add(new SupportingFile("ParamExpander.mustache", invokerFolder, "ParamExpander.java")); supportingFiles.add(new SupportingFile("EncodingUtils.mustache", invokerFolder, "EncodingUtils.java")); - supportingFiles.add(new SupportingFile("auth/DefaultApi20Impl.mustache", authFolder, "DefaultApi20Impl.java")); - supportingFiles.add(new SupportingFile("auth/OauthPasswordGrant.mustache", authFolder, "OauthPasswordGrant.java")); - supportingFiles.add(new SupportingFile("auth/OauthClientCredentialsGrant.mustache", authFolder, "OauthClientCredentialsGrant.java")); } else if (OKHTTP_GSON.equals(getLibrary()) || StringUtils.isEmpty(getLibrary())) { // the "okhttp-gson" library template requires "ApiCallback.mustache" for async call @@ -593,8 +590,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen supportingFiles.add(new SupportingFile("auth/OAuthOkHttpClient.mustache", authFolder, "OAuthOkHttpClient.java")); supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java")); } - - // google-api-client doesn't use the OpenAPI auth, because it uses Google Credential directly (HttpRequestInitializer) + if (FEIGN.equals(getLibrary())) { + supportingFiles.add(new SupportingFile("auth/DefaultApi20Impl.mustache", authFolder, "DefaultApi20Impl.java")); + supportingFiles.add(new SupportingFile("auth/OauthPasswordGrant.mustache", authFolder, "OauthPasswordGrant.java")); + supportingFiles.add(new SupportingFile("auth/OauthClientCredentialsGrant.mustache", authFolder, "OauthClientCredentialsGrant.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()))) { supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java")); -- GitLab From 3f292c69e97cae70e081f351f955fb41b801450c Mon Sep 17 00:00:00 2001 From: Hugo Alves <hugo.ma.alves@gmail.com> Date: Wed, 12 May 2021 17:40:41 +0100 Subject: [PATCH 2/2] Do not create OAuth classes when the client doesn't have security configured --- .../src/main/resources/Java/libraries/feign/ApiClient.mustache | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache index 4e094dfccbe..0530689a459 100644 --- a/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache +++ b/modules/openapi-generator/src/main/resources/Java/libraries/feign/ApiClient.mustache @@ -162,6 +162,7 @@ public class ApiClient { return objectMapper; } + {{#hasAuthMethods}} private RequestInterceptor buildOauthRequestInterceptor(OAuthFlow flow, String authorizationUrl, String tokenUrl, String scopes) { switch (flow) { case password: @@ -172,6 +173,7 @@ public class ApiClient { throw new RuntimeException("Oauth flow \"" + flow + "\" is not implemented"); } } + {{/hasAuthMethods}} public ObjectMapper getObjectMapper(){ return objectMapper; -- GitLab