Skip to content

Commit bc5a610

Browse files
committed
Use the first security requirement from the array
According to swagger spec, "there is a logical OR between the security requirements". The original behavior was to apply the security requirements as the logic AND and skip security requirements that include more that 1 security.
1 parent 65e63a8 commit bc5a610

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/DefaultGenerator.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -483,16 +483,16 @@ public void processOperation(String resourcePath, String httpMethod, Operation o
483483
securities.add(sr.getRequirements());
484484
}
485485
}
486-
if (securities == null) {
486+
if (securities == null || securities.isEmpty()) {
487487
continue;
488488
}
489489
Map<String, SecuritySchemeDefinition> authMethods = new HashMap<String, SecuritySchemeDefinition>();
490-
for (Map<String, List<String>> security : securities) {
491-
if (security.size() != 1) {
492-
//Not sure what to do
493-
continue;
494-
}
495-
String securityName = security.keySet().iterator().next();
490+
// NOTE: Use only the first security requirement for now.
491+
// See the "security" field of "Swagger Object":
492+
// https://github.com/swagger-api/swagger-spec/blob/master/versions/2.0.md#swagger-object
493+
// "there is a logical OR between the security requirements"
494+
Map<String, List<String>> security = securities.get(0);
495+
for (String securityName : security.keySet()) {
496496
SecuritySchemeDefinition securityDefinition = fromSecurity(securityName);
497497
if (securityDefinition != null) {
498498
if(securityDefinition instanceof OAuth2Definition) {
@@ -503,7 +503,7 @@ public void processOperation(String resourcePath, String httpMethod, Operation o
503503
oauth2Operation.setFlow(oauth2Definition.getFlow());
504504
oauth2Operation.setTokenUrl(oauth2Definition.getTokenUrl());
505505
oauth2Operation.setScopes(new HashMap<String, String>());
506-
for (String scope : security.values().iterator().next()) {
506+
for (String scope : security.get(securityName)) {
507507
if (oauth2Definition.getScopes().containsKey(scope)) {
508508
oauth2Operation.addScope(scope, oauth2Definition.getScopes().get(scope));
509509
}

0 commit comments

Comments
 (0)