Add authorization scope data to CodegenSecurity, demo use in JAXRS

This commit is contained in:
Nick Bruno
2015-10-14 22:07:43 -04:00
parent 638bbfaf43
commit 6cc17d8508
5 changed files with 29 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ import java.util.Set;
public class CodegenOperation {
public final List<CodegenProperty> responseHeaders = new ArrayList<CodegenProperty>();
public Boolean hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive,
public Boolean hasAuthMethods, hasConsumes, hasProduces, hasParams, returnTypeIsPrimitive,
returnSimpleType, subresourceOperation, isMapContainer, isListContainer,
hasMore = Boolean.TRUE, isMultipart, isResponseBinary = Boolean.FALSE;
public String path, operationId, returnType, httpMethod, returnBaseType,

View File

@@ -1,6 +1,7 @@
package io.swagger.codegen;
import java.util.Set;
import java.util.List;
import java.util.Map;
public class CodegenSecurity {
public String name;
@@ -11,5 +12,5 @@ public class CodegenSecurity {
public Boolean isKeyInQuery, isKeyInHeader;
// Oauth specific
public String flow, authorizationUrl, tokenUrl;
public Set<String> scopes;
public List<Map<String, Object>> scopes;
}

View File

@@ -1307,7 +1307,23 @@ public class DefaultCodegen {
sec.authorizationUrl = oauth2Definition.getAuthorizationUrl();
sec.tokenUrl = oauth2Definition.getTokenUrl();
if (oauth2Definition.getScopes() != null) {
sec.scopes = oauth2Definition.getScopes().keySet();
List<Map<String, Object>> scopes = new ArrayList<Map<String, Object>>();
int count = 0, numScopes = oauth2Definition.getScopes().size();
for(Map.Entry<String, String> scopeEntry : oauth2Definition.getScopes().entrySet()) {
Map<String, Object> scope = new HashMap<String, Object>();
scope.put("scope", scopeEntry.getKey());
scope.put("description", scopeEntry.getValue());
count += 1;
if (count < numScopes) {
scope.put("hasMore", "true");
} else {
scope.put("hasMore", null);
}
scopes.add(scope);
}
sec.scopes = scopes;
}
}

View File

@@ -509,6 +509,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
}
if (!authMethods.isEmpty()) {
co.authMethods = config.fromSecurity(authMethods);
co.hasAuthMethods = true;
}
}
catch (Exception ex) {