forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -406,40 +406,39 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||
if (operations != null) {
|
||||
List<CodegenOperation> ops = (List<CodegenOperation>) operations.get("operation");
|
||||
for (CodegenOperation operation : ops) {
|
||||
for (final CodegenOperation operation : ops) {
|
||||
List<CodegenResponse> responses = operation.responses;
|
||||
if (responses != null) {
|
||||
for (CodegenResponse resp : responses) {
|
||||
for (final CodegenResponse resp : responses) {
|
||||
if ("0".equals(resp.code)) {
|
||||
resp.code = "200";
|
||||
}
|
||||
doDataTypeAssignment(resp.dataType, new DataTypeAssigner() {
|
||||
@Override
|
||||
public void setReturnType(final String returnType) {
|
||||
resp.dataType = returnType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setReturnContainer(final String returnContainer) {
|
||||
resp.containerType = returnContainer;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (operation.returnType == null) {
|
||||
operation.returnType = "Void";
|
||||
} else if (operation.returnType.startsWith("List")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("List<".length(), end).trim();
|
||||
operation.returnContainer = "List";
|
||||
doDataTypeAssignment(operation.returnType, new DataTypeAssigner() {
|
||||
|
||||
@Override
|
||||
public void setReturnType(final String returnType) {
|
||||
operation.returnType = returnType;
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end).split(",")[1].trim();
|
||||
operation.returnContainer = "Map";
|
||||
|
||||
@Override
|
||||
public void setReturnContainer(final String returnContainer) {
|
||||
operation.returnContainer = returnContainer;
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end).trim();
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(implicitHeaders){
|
||||
removeHeadersFromAllParams(operation.allParams);
|
||||
@@ -450,6 +449,41 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
return objs;
|
||||
}
|
||||
|
||||
private interface DataTypeAssigner {
|
||||
void setReturnType(String returnType);
|
||||
void setReturnContainer(String returnContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param returnType The return type that needs to be converted
|
||||
* @param dataTypeAssigner An object that will assign the data to the respective fields in the model.
|
||||
*/
|
||||
private void doDataTypeAssignment(String returnType, DataTypeAssigner dataTypeAssigner) {
|
||||
final String rt = returnType;
|
||||
if (rt == null) {
|
||||
dataTypeAssigner.setReturnType("Void");
|
||||
} else if (rt.startsWith("List")) {
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
dataTypeAssigner.setReturnType(rt.substring("List<".length(), end).trim());
|
||||
dataTypeAssigner.setReturnContainer("List");
|
||||
}
|
||||
} else if (rt.startsWith("Map")) {
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
dataTypeAssigner.setReturnType(rt.substring("Map<".length(), end).split(",")[1].trim());
|
||||
dataTypeAssigner.setReturnContainer("Map");
|
||||
}
|
||||
} else if (rt.startsWith("Set")) {
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
dataTypeAssigner.setReturnType(rt.substring("Set<".length(), end).trim());
|
||||
dataTypeAssigner.setReturnContainer("Set");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method removes header parameters from the list of parameters and also
|
||||
* corrects last allParams hasMore state.
|
||||
|
||||
@@ -42,7 +42,7 @@ public interface {{classname}} {
|
||||
{{/hasMore}}{{/authMethods}}
|
||||
}{{/hasAuthMethods}}, tags={ {{#vendorExtensions.x-tags}}"{{tag}}",{{/vendorExtensions.x-tags}} })
|
||||
@ApiResponses(value = { {{#responses}}
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{returnType}}}.class){{#hasMore}},{{/hasMore}}{{/responses}} })
|
||||
@ApiResponse(code = {{{code}}}, message = "{{{message}}}", response = {{{dataType}}}.class{{#containerType}}, responseContainer = "{{{containerType}}}"{{/containerType}}){{#hasMore}},{{/hasMore}}{{/responses}} })
|
||||
{{#implicitHeaders}}
|
||||
@ApiImplicitParams({
|
||||
{{#headerParams}}{{>implicitHeader}}{{/headerParams}}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
{{>licenseInfo}}
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
import { Inject, Injectable, Optional } from '@angular/core';
|
||||
import { Http, Headers, URLSearchParams } from '@angular/http';
|
||||
import { RequestMethod, RequestOptions, RequestOptionsArgs } from '@angular/http';
|
||||
@@ -17,8 +19,6 @@ import { Configuration } from '../configurat
|
||||
import { {{classname}}Interface } from './{{classname}}Interface';
|
||||
{{/withInterfaces}}
|
||||
|
||||
/* tslint:disable:no-unused-variable member-ordering */
|
||||
|
||||
{{#operations}}
|
||||
|
||||
{{#description}}
|
||||
|
||||
Reference in New Issue
Block a user