forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -27,6 +27,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
public static final String DO_NOT_USE_RX = "doNotUseRx";
|
||||
public static final String USE_PLAY24_WS = "usePlay24WS";
|
||||
public static final String PARCELABLE_MODEL = "parcelableModel";
|
||||
public static final String USE_RUNTIME_EXCEPTION = "useRuntimeException";
|
||||
|
||||
public static final String RETROFIT_1 = "retrofit";
|
||||
public static final String RETROFIT_2 = "retrofit2";
|
||||
@@ -40,6 +41,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
protected boolean useBeanValidation = false;
|
||||
protected boolean performBeanValidation = false;
|
||||
protected boolean useGzipFeature = false;
|
||||
protected boolean useRuntimeException = false;
|
||||
|
||||
public JavaClientCodegen() {
|
||||
super();
|
||||
@@ -58,6 +60,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
cliOptions.add(CliOption.newBoolean(USE_BEANVALIDATION, "Use BeanValidation API annotations"));
|
||||
cliOptions.add(CliOption.newBoolean(PERFORM_BEANVALIDATION, "Perform BeanValidation"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_GZIP_FEATURE, "Send gzip-encoded requests"));
|
||||
cliOptions.add(CliOption.newBoolean(USE_RUNTIME_EXCEPTION, "Use RuntimeException instead of Exception"));
|
||||
|
||||
supportedLibraries.put("jersey1", "HTTP client: Jersey client 1.19.1. JSON processing: Jackson 2.7.0. Enable Java6 support using '-DsupportJava6=true'. Enable gzip request encoding using '-DuseGzipFeature=true'.");
|
||||
supportedLibraries.put("feign", "HTTP client: OpenFeign 9.4.0. JSON processing: Jackson 2.8.7");
|
||||
@@ -128,6 +131,10 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
this.setUseGzipFeature(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE));
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(USE_RUNTIME_EXCEPTION)) {
|
||||
this.setUseRuntimeException(convertPropertyToBooleanAndWriteBack(USE_RUNTIME_EXCEPTION));
|
||||
}
|
||||
|
||||
final String invokerFolder = (sourceFolder + '/' + invokerPackage).replace(".", "/");
|
||||
final String authFolder = (sourceFolder + '/' + invokerPackage + ".auth").replace(".", "/");
|
||||
|
||||
@@ -295,22 +302,22 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
|
||||
/**
|
||||
* Prioritizes consumes mime-type list by moving json-vendor and json mime-types up front, but
|
||||
* otherwise preserves original consumes definition order.
|
||||
* [application/vnd...+json,... application/json, ..as is..]
|
||||
*
|
||||
* Prioritizes consumes mime-type list by moving json-vendor and json mime-types up front, but
|
||||
* otherwise preserves original consumes definition order.
|
||||
* [application/vnd...+json,... application/json, ..as is..]
|
||||
*
|
||||
* @param consumes consumes mime-type list
|
||||
* @return
|
||||
* @return
|
||||
*/
|
||||
static List<Map<String, String>> prioritizeContentTypes(List<Map<String, String>> consumes) {
|
||||
if ( consumes.size() <= 1 )
|
||||
return consumes;
|
||||
|
||||
|
||||
List<Map<String, String>> prioritizedContentTypes = new ArrayList<>(consumes.size());
|
||||
|
||||
|
||||
List<Map<String, String>> jsonVendorMimeTypes = new ArrayList<>(consumes.size());
|
||||
List<Map<String, String>> jsonMimeTypes = new ArrayList<>(consumes.size());
|
||||
|
||||
|
||||
for ( Map<String, String> consume : consumes) {
|
||||
if ( isJsonVendorMimeType(consume.get(MEDIA_TYPE))) {
|
||||
jsonVendorMimeTypes.add(consume);
|
||||
@@ -320,18 +327,18 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
}
|
||||
else
|
||||
prioritizedContentTypes.add(consume);
|
||||
|
||||
|
||||
consume.put("hasMore", "true");
|
||||
}
|
||||
|
||||
|
||||
prioritizedContentTypes.addAll(0, jsonMimeTypes);
|
||||
prioritizedContentTypes.addAll(0, jsonVendorMimeTypes);
|
||||
|
||||
|
||||
prioritizedContentTypes.get(prioritizedContentTypes.size()-1).put("hasMore", null);
|
||||
|
||||
|
||||
return prioritizedContentTypes;
|
||||
}
|
||||
|
||||
|
||||
private static boolean isMultipartType(List<Map<String, String>> consumes) {
|
||||
Map<String, String> firstType = consumes.get(0);
|
||||
if (firstType != null) {
|
||||
@@ -419,8 +426,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
|
||||
this.useGzipFeature = useGzipFeature;
|
||||
}
|
||||
|
||||
public void setUseRuntimeException(boolean useRuntimeException) {
|
||||
this.useRuntimeException = useRuntimeException;
|
||||
}
|
||||
|
||||
final private static Pattern JSON_MIME_PATTERN = Pattern.compile("(?i)application\\/json(;.*)?");
|
||||
final private static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?");
|
||||
final private static Pattern JSON_VENDOR_MIME_PATTERN = Pattern.compile("(?i)application\\/vnd.(.*)+json(;.*)?");
|
||||
|
||||
/**
|
||||
* Check if the given MIME is a JSON MIME.
|
||||
|
||||
@@ -673,6 +673,11 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
return varName;
|
||||
}
|
||||
|
||||
// for symbol, e.g. $, #
|
||||
if (getSymbolName(name) != null) {
|
||||
return getSymbolName(name).toUpperCase();
|
||||
}
|
||||
|
||||
// string
|
||||
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||
enumName = enumName.replaceFirst("^_", "");
|
||||
|
||||
@@ -196,6 +196,13 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
return str.replaceAll("\\.", "_");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
// process enum in models
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter){
|
||||
postProcessPattern(parameter.pattern, parameter.vendorExtensions);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.samskivert.mustache.Mustache;
|
||||
import com.samskivert.mustache.Template;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.codegen.languages.features.BeanValidationFeatures;
|
||||
import io.swagger.models.Operation;
|
||||
@@ -7,7 +9,12 @@ import io.swagger.models.Path;
|
||||
import io.swagger.models.Swagger;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.util.*;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
public class SpringCodegen extends AbstractJavaCodegen implements BeanValidationFeatures {
|
||||
public static final String DEFAULT_LIBRARY = "spring-boot";
|
||||
@@ -170,6 +177,9 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
this.setImplicitHeaders(Boolean.valueOf(additionalProperties.get(IMPLICIT_HEADERS).toString()));
|
||||
}
|
||||
|
||||
typeMapping.put("file", "Resource");
|
||||
importMapping.put("Resource", "org.springframework.core.io.Resource");
|
||||
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
@@ -287,6 +297,19 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
break;
|
||||
}
|
||||
|
||||
// add lamda for mustache templates
|
||||
additionalProperties.put("lamdaEscapeDoubleQuote", new Mustache.Lambda() {
|
||||
@Override
|
||||
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
|
||||
writer.write(fragment.execute().replaceAll("\"", Matcher.quoteReplacement("\\\"")));
|
||||
}
|
||||
});
|
||||
additionalProperties.put("lamdaRemoveLineBreak", new Mustache.Lambda() {
|
||||
@Override
|
||||
public void execute(Template.Fragment fragment, Writer writer) throws IOException {
|
||||
writer.write(fragment.execute().replaceAll("\\r|\\n", ""));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -470,6 +493,32 @@ public class SpringCodegen extends AbstractJavaCodegen implements BeanValidation
|
||||
return camelize(name) + "Api";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setParameterExampleValue(CodegenParameter p) {
|
||||
String type = p.baseType;
|
||||
if (type == null) {
|
||||
type = p.dataType;
|
||||
}
|
||||
|
||||
if ("File".equals(type)) {
|
||||
String example;
|
||||
|
||||
if (p.defaultValue == null) {
|
||||
example = p.example;
|
||||
} else {
|
||||
example = p.defaultValue;
|
||||
}
|
||||
|
||||
if (example == null) {
|
||||
example = "/path/to/file";
|
||||
}
|
||||
example = "new org.springframework.core.io.FileSystemResource(new java.io.File(\"" + escapeText(example) + "\"))";
|
||||
p.example = example;
|
||||
} else {
|
||||
super.setParameterExampleValue(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user