mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-08 08:30:56 +00:00
Code fixes after reformatting
This commit is contained in:
parent
aa0586c666
commit
56714e6c07
@ -11,7 +11,7 @@ import io.swagger.codegen.cmd.Meta;
|
||||
* User: lanwen
|
||||
* Date: 24.03.15
|
||||
* Time: 17:56
|
||||
* <p/>
|
||||
* <p>
|
||||
* Command line interface for swagger codegen
|
||||
* use `swagger-codegen-cli.jar help` for more info
|
||||
*
|
||||
|
@ -869,207 +869,6 @@ public class DefaultCodegen {
|
||||
return op;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public CodegenOperation fromOperation(String path, String httpMethod, Operation operation, Map<String, Model> definitions) {
|
||||
CodegenOperation op = CodegenModelFactory.newInstance(CodegenModelType.OPERATION);
|
||||
Set<String> imports = new HashSet<String>();
|
||||
|
||||
String operationId = operation.getOperationId();
|
||||
if (operationId == null) {
|
||||
String tmpPath = path;
|
||||
tmpPath = tmpPath.replaceAll("\\{", "");
|
||||
tmpPath = tmpPath.replaceAll("\\}", "");
|
||||
String[] parts = (tmpPath + "/" + httpMethod).split("/");
|
||||
StringBuilder builder = new StringBuilder();
|
||||
if ("/".equals(tmpPath)) {
|
||||
// must be root tmpPath
|
||||
builder.append("root");
|
||||
}
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
String part = parts[i];
|
||||
if (part.length() > 0) {
|
||||
if (builder.toString().length() == 0) {
|
||||
part = Character.toLowerCase(part.charAt(0)) + part.substring(1);
|
||||
} else {
|
||||
part = initialCaps(part);
|
||||
}
|
||||
builder.append(part);
|
||||
}
|
||||
}
|
||||
operationId = builder.toString();
|
||||
LOGGER.warn("generated operationId " + operationId);
|
||||
}
|
||||
operationId = removeNonNameElementToCamelCase(operationId);
|
||||
op.path = path;
|
||||
op.operationId = toOperationId(operationId);
|
||||
op.summary = escapeText(operation.getSummary());
|
||||
op.notes = escapeText(operation.getDescription());
|
||||
op.tags = operation.getTags();
|
||||
|
||||
if (operation.getConsumes() != null && operation.getConsumes().size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for (String key : operation.getConsumes()) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getConsumes().size()) {
|
||||
mediaType.put("hasMore", "true");
|
||||
} else {
|
||||
mediaType.put("hasMore", null);
|
||||
}
|
||||
c.add(mediaType);
|
||||
}
|
||||
op.consumes = c;
|
||||
op.hasConsumes = true;
|
||||
}
|
||||
|
||||
if (operation.getProduces() != null && operation.getProduces().size() > 0) {
|
||||
List<Map<String, String>> c = new ArrayList<Map<String, String>>();
|
||||
int count = 0;
|
||||
for (String key : operation.getProduces()) {
|
||||
Map<String, String> mediaType = new HashMap<String, String>();
|
||||
mediaType.put("mediaType", key);
|
||||
count += 1;
|
||||
if (count < operation.getProduces().size()) {
|
||||
mediaType.put("hasMore", "true");
|
||||
} else {
|
||||
mediaType.put("hasMore", null);
|
||||
}
|
||||
c.add(mediaType);
|
||||
}
|
||||
op.produces = c;
|
||||
op.hasProduces = true;
|
||||
}
|
||||
|
||||
if (operation.getResponses() != null && !operation.getResponses().isEmpty()) {
|
||||
Response methodResponse = findMethodResponse(operation.getResponses());
|
||||
|
||||
for (Map.Entry<String, Response> entry : operation.getResponses().entrySet()) {
|
||||
Response response = entry.getValue();
|
||||
CodegenResponse r = fromResponse(entry.getKey(), response);
|
||||
r.hasMore = true;
|
||||
if (r.baseType != null &&
|
||||
!defaultIncludes.contains(r.baseType) &&
|
||||
!languageSpecificPrimitives.contains(r.baseType)) {
|
||||
imports.add(r.baseType);
|
||||
}
|
||||
r.isDefault = response == methodResponse;
|
||||
op.responses.add(r);
|
||||
}
|
||||
op.responses.get(op.responses.size() - 1).hasMore = false;
|
||||
|
||||
if (methodResponse != null) {
|
||||
if (methodResponse.getSchema() != null) {
|
||||
CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
|
||||
|
||||
Property responseProperty = methodResponse.getSchema();
|
||||
|
||||
if (responseProperty instanceof ArrayProperty) {
|
||||
ArrayProperty ap = (ArrayProperty) responseProperty;
|
||||
CodegenProperty innerProperty = fromProperty("response", ap.getItems());
|
||||
op.returnBaseType = innerProperty.baseType;
|
||||
} else {
|
||||
if (cm.complexType != null) {
|
||||
op.returnBaseType = cm.complexType;
|
||||
} else {
|
||||
op.returnBaseType = cm.baseType;
|
||||
}
|
||||
}
|
||||
op.examples = new ExampleGenerator(definitions).generate(methodResponse.getExamples(), operation.getProduces(), responseProperty);
|
||||
op.defaultResponse = toDefaultValue(responseProperty);
|
||||
op.returnType = cm.datatype;
|
||||
if (cm.isContainer != null) {
|
||||
op.returnContainer = cm.containerType;
|
||||
if ("map".equals(cm.containerType)) {
|
||||
op.isMapContainer = Boolean.TRUE;
|
||||
} else if ("list".equalsIgnoreCase(cm.containerType)) {
|
||||
op.isListContainer = Boolean.TRUE;
|
||||
} else if ("array".equalsIgnoreCase(cm.containerType)) {
|
||||
op.isListContainer = Boolean.TRUE;
|
||||
}
|
||||
} else {
|
||||
op.returnSimpleType = true;
|
||||
}
|
||||
if (languageSpecificPrimitives().contains(op.returnBaseType) || op.returnBaseType == null) {
|
||||
op.returnTypeIsPrimitive = true;
|
||||
}
|
||||
}
|
||||
addHeaders(methodResponse, op.responseHeaders);
|
||||
}
|
||||
}
|
||||
|
||||
List<Parameter> parameters = operation.getParameters();
|
||||
CodegenParameter bodyParam = null;
|
||||
List<CodegenParameter> allParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> bodyParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> pathParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> queryParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> headerParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> cookieParams = new ArrayList<CodegenParameter>();
|
||||
List<CodegenParameter> formParams = new ArrayList<CodegenParameter>();
|
||||
|
||||
if (parameters != null) {
|
||||
for (Parameter param : parameters) {
|
||||
CodegenParameter p = fromParameter(param, imports);
|
||||
allParams.add(p);
|
||||
if (param instanceof QueryParameter) {
|
||||
p.isQueryParam = new Boolean(true);
|
||||
queryParams.add(p.copy());
|
||||
} else if (param instanceof PathParameter) {
|
||||
p.required = true;
|
||||
p.isPathParam = new Boolean(true);
|
||||
pathParams.add(p.copy());
|
||||
} else if (param instanceof HeaderParameter) {
|
||||
p.isHeaderParam = new Boolean(true);
|
||||
headerParams.add(p.copy());
|
||||
} else if (param instanceof CookieParameter) {
|
||||
p.isCookieParam = new Boolean(true);
|
||||
cookieParams.add(p.copy());
|
||||
} else if (param instanceof BodyParameter) {
|
||||
p.isBodyParam = new Boolean(true);
|
||||
bodyParam = p;
|
||||
bodyParams.add(p.copy());
|
||||
} else if (param instanceof FormParameter) {
|
||||
if ("file".equalsIgnoreCase(((FormParameter) param).getType())) {
|
||||
p.isFile = true;
|
||||
} else {
|
||||
p.notFile = true;
|
||||
}
|
||||
p.isFormParam = new Boolean(true);
|
||||
formParams.add(p.copy());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String i : imports) {
|
||||
if (!defaultIncludes.contains(i) && !languageSpecificPrimitives.contains(i)) {
|
||||
op.imports.add(i);
|
||||
}
|
||||
}
|
||||
op.bodyParam = bodyParam;
|
||||
op.httpMethod = httpMethod.toUpperCase();
|
||||
op.allParams = addHasMore(allParams);
|
||||
op.bodyParams = addHasMore(bodyParams);
|
||||
op.pathParams = addHasMore(pathParams);
|
||||
op.queryParams = addHasMore(queryParams);
|
||||
op.headerParams = addHasMore(headerParams);
|
||||
// op.cookieParams = cookieParams;
|
||||
op.formParams = addHasMore(formParams);
|
||||
// legacy support
|
||||
op.nickname = op.operationId;
|
||||
|
||||
|
||||
if (op.allParams.size() > 0) {
|
||||
op.hasParams = true;
|
||||
}
|
||||
op.externalDocs = operation.getExternalDocs();
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
public CodegenResponse fromResponse(String responseCode, Response response) {
|
||||
CodegenResponse r = CodegenModelFactory.newInstance(CodegenModelType.RESPONSE);
|
||||
if ("default".equals(responseCode)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user