Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
OAuth security schema is used but OAuth related files are not generated
  • Loading branch information
eyals24 committed Jul 22, 2019
commit 738b7dba342719c3e31d3f3b94ef4cdc61215f74
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

package org.openapitools.codegen.languages;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.*;
Expand Down Expand Up @@ -499,8 +502,28 @@ public int compare(CodegenParameter one, CodegenParameter another) {
supportingFiles.add(new SupportingFile("auth/RetryingOAuth.mustache", authFolder, "RetryingOAuth.java"));
}

boolean isOAuth = Optional
.ofNullable(this.openAPI)
.map(OpenAPI::getComponents)
.map(Components::getSecuritySchemes)
.map(v -> !v.isEmpty())
.orElse(false)

&&

this
.openAPI
.getComponents()
.getSecuritySchemes()
.values()
.stream()
.findFirst()
.map(SecurityScheme::getType)
.map(v -> v.equals(SecurityScheme.Type.OAUTH2))
.orElse(false);

// 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)) && ProcessUtils.hasOAuthMethods(objs)) {
if ((!(GOOGLE_API_CLIENT.equals(getLibrary()) || REST_ASSURED.equals(getLibrary()) || usePlayWS)) && (ProcessUtils.hasOAuthMethods(objs) || isOAuth)) {
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
supportingFiles.add(new SupportingFile("auth/OAuthFlow.mustache", authFolder, "OAuthFlow.java"));
}
Expand Down