forked from loafle/openapi-generator-original
merged
This commit is contained in:
@@ -67,6 +67,8 @@ public interface CodegenConfig {
|
||||
|
||||
CodegenModel fromModel(String name, Model model, Map<String, Model> allDefinitions);
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger);
|
||||
|
||||
CodegenOperation fromOperation(String resourcePath, String httpMethod, Operation operation, Map<String, Model> definitions);
|
||||
|
||||
List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition> schemes);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -867,8 +867,12 @@ public class DefaultCodegen {
|
||||
}
|
||||
return responses.get(code);
|
||||
}
|
||||
|
||||
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
return fromOperation(path, httpMethod, operation, definitions, null);
|
||||
}
|
||||
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
|
||||
Set<String> imports = new HashSet<String>();
|
||||
op.vendorExtensions = operation.getVendorExtensions();
|
||||
@@ -904,15 +908,32 @@ public class DefaultCodegen {
|
||||
op.summary = escapeText(operation.getSummary());
|
||||
op.notes = escapeText(operation.getDescription());
|
||||
op.tags = operation.getTags();
|
||||
op.hasConsumes = false;
|
||||
op.hasProduces = false;
|
||||
|
||||
if (operation.getConsumes() != null && operation.getConsumes().size() > 0) {
|
||||
List<String> consumes = new ArrayList<String>();
|
||||
if (operation.getConsumes() != null) {
|
||||
if (operation.getConsumes().size() > 0) {
|
||||
// use consumes defined in the operation
|
||||
consumes = operation.getConsumes();
|
||||
} else {
|
||||
// empty list, do nothing to override global setting
|
||||
}
|
||||
} else if (swagger != null && swagger.getConsumes() != null && swagger.getConsumes().size() > 0) {
|
||||
// use consumes defined globally
|
||||
consumes = swagger.getConsumes();
|
||||
LOGGER.debug("No consumes defined in operation. Using global consumes (" + swagger.getConsumes() + ") for " + op.operationId);
|
||||
}
|
||||
|
||||
// if "consumes" is defined (per operation or using global definition)
|
||||
if (consumes != null && consumes.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for (String key : operation.getConsumes()) {
|
||||
for (String key : consumes) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getConsumes().size()) {
|
||||
if (count < consumes.size()) {
|
||||
mediaType.put("hasMore", "true");
|
||||
} else {
|
||||
mediaType.put("hasMore", null);
|
||||
@@ -923,14 +944,29 @@ public class DefaultCodegen {
|
||||
op.hasConsumes = true;
|
||||
}
|
||||
|
||||
if (operation.getProduces() != null && operation.getProduces().size() > 0) {
|
||||
List<String> produces = new ArrayList<String>();
|
||||
if (operation.getProduces() != null) {
|
||||
if (operation.getProduces().size() > 0) {
|
||||
// use produces defined in the operation
|
||||
produces = operation.getProduces();
|
||||
} else {
|
||||
// empty list, do nothing to override global setting
|
||||
}
|
||||
} else if (swagger != null && swagger.getProduces() != null && swagger.getProduces().size() > 0) {
|
||||
// use produces defined globally
|
||||
produces = swagger.getProduces();
|
||||
LOGGER.debug("No produces defined in operation. Using global produces (" + swagger.getProduces() + ") for " + op.operationId);
|
||||
}
|
||||
|
||||
// if "produces" is defined (per operation or using global definition)
|
||||
if (produces != null && produces.size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for (String key : operation.getProduces()) {
|
||||
for (String key : produces) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getProduces().size()) {
|
||||
if (count < produces.size()) {
|
||||
mediaType.put("hasMore", "true");
|
||||
} else {
|
||||
mediaType.put("hasMore", null);
|
||||
@@ -1310,7 +1346,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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -475,7 +475,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String tag : tags) {
|
||||
CodegenOperation co = null;
|
||||
try {
|
||||
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions());
|
||||
co = config.fromOperation(resourcePath, httpMethod, operation, swagger.getDefinitions(), swagger);
|
||||
co.tags = new ArrayList<String>();
|
||||
co.tags.add(sanitizeTag(tag));
|
||||
config.addOperationToGroup(sanitizeTag(tag), resourcePath, operation, co, operations);
|
||||
@@ -523,6 +523,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
}
|
||||
if (!authMethods.isEmpty()) {
|
||||
co.authMethods = config.fromSecurity(authMethods);
|
||||
co.hasAuthMethods = true;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
|
||||
import com.google.common.collect.Iterators;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.parameters.HeaderParameter;
|
||||
@@ -256,7 +258,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions, Swagger swagger) {
|
||||
path = normalizePath(path);
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
parameters = Lists.newArrayList(Iterators.filter(parameters.iterator(), new Predicate<Parameter>() {
|
||||
@@ -266,7 +268,7 @@ public class SwiftCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}));
|
||||
operation.setParameters(parameters);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions);
|
||||
return super.fromOperation(path, httpMethod, operation, definitions, swagger);
|
||||
}
|
||||
|
||||
private static String normalizePath(String path) {
|
||||
|
||||
Reference in New Issue
Block a user