forked from loafle/openapi-generator-original
added unit tests to feign client
This commit is contained in:
@@ -11,6 +11,12 @@ import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.DefaultCodegen;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.models.Model;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.models.parameters.BodyParameter;
|
||||
import io.swagger.models.parameters.FormParameter;
|
||||
import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.models.properties.ArrayProperty;
|
||||
import io.swagger.models.properties.BooleanProperty;
|
||||
import io.swagger.models.properties.DoubleProperty;
|
||||
@@ -216,7 +222,9 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("StringUtil.mustache", invokerFolder, "StringUtil.java"));
|
||||
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
if (!"feign".equals(getLibrary())) {
|
||||
if ("feign".equals(getLibrary())) {
|
||||
supportingFiles.add(new SupportingFile("FormAwareEncoder.mustache", invokerFolder, "FormAwareEncoder.java"));
|
||||
} else {
|
||||
supportingFiles.add(new SupportingFile("auth/HttpBasicAuth.mustache", authFolder, "HttpBasicAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/ApiKeyAuth.mustache", authFolder, "ApiKeyAuth.java"));
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
@@ -544,6 +552,58 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return objs;
|
||||
}
|
||||
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for (String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if (path.getOperations() != null) {
|
||||
for (Operation operation : path.getOperations()) {
|
||||
boolean hasFormParameters = false;
|
||||
for (Parameter parameter : operation.getParameters()) {
|
||||
parameter.getVendorExtensions().put("x-isBody", parameter instanceof BodyParameter);
|
||||
if (parameter instanceof FormParameter) {
|
||||
hasFormParameters = true;
|
||||
}
|
||||
}
|
||||
|
||||
String defaultContentType = hasFormParameters ? "application/x-www-form-urlencoded" : "application/json";
|
||||
String contentType = operation.getConsumes() == null || operation.getConsumes().isEmpty()
|
||||
? defaultContentType : operation.getConsumes().get(0);
|
||||
String accepts = getAccept(operation);
|
||||
operation.setVendorExtension("x-contentType", contentType);
|
||||
operation.setVendorExtension("x-accepts", accepts);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String getAccept(Operation operation) {
|
||||
String accepts = null;
|
||||
String defaultContentType = "application/json";
|
||||
if (operation.getProduces() != null && !operation.getProduces().isEmpty()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String produces : operation.getProduces()) {
|
||||
if (defaultContentType.equalsIgnoreCase(produces)) {
|
||||
accepts = defaultContentType;
|
||||
break;
|
||||
} else {
|
||||
if (sb.length() > 0) {
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(produces);
|
||||
}
|
||||
}
|
||||
if (accepts == null) {
|
||||
accepts = sb.toString();
|
||||
}
|
||||
} else {
|
||||
accepts = defaultContentType;
|
||||
}
|
||||
|
||||
return accepts;
|
||||
}
|
||||
|
||||
protected boolean needToImport(String type) {
|
||||
return super.needToImport(type) && type.indexOf(".") < 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user