Merge remote-tracking branch 'origin/master' into 4.1.x

This commit is contained in:
wing328
2019-07-02 22:48:09 +08:00
207 changed files with 2213 additions and 910 deletions

View File

@@ -810,7 +810,7 @@ public class DefaultCodegen implements CodegenConfig {
* @return the snake-cased variable name
*/
public String toApiVarName(String name) {
return snakeCase(name);
return lowerCamelCase(name);
}
/**
@@ -1533,13 +1533,13 @@ public class DefaultCodegen implements CodegenConfig {
}
/**
* Return the snake-case of the string
* Return the lowerCamelCase of the string
*
* @param name string to be snake-cased
* @return snake-cased string
* @param name string to be lowerCamelCased
* @return lowerCamelCase string
*/
@SuppressWarnings("static-method")
public String snakeCase(String name) {
public String lowerCamelCase(String name) {
return (name.length() > 0) ? (Character.toLowerCase(name.charAt(0)) + name.substring(1)) : "";
}

View File

@@ -784,6 +784,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
return p.getDefault().toString();
}
return null;
} else if (ModelUtils.isURISchema(p)) {
if (p.getDefault() != null) {
return "URI.create(\"" + escapeText((String) p.getDefault()) + "\")";
}
return null;
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
String _default = (String) p.getDefault();

View File

@@ -834,6 +834,10 @@ public abstract class AbstractKotlinCodegen extends DefaultCodegen implements Co
if (p.getDefault() != null) {
return p.getDefault().toString();
}
} else if (ModelUtils.isURISchema(p)) {
if (p.getDefault() != null) {
return "URI.create('" + p.getDefault() + "')";
}
} else if (ModelUtils.isStringSchema(p)) {
if (p.getDefault() != null) {
return "'" + p.getDefault() + "'";

View File

@@ -128,7 +128,7 @@ public class ErlangClientCodegen extends DefaultCodegen implements CodegenConfig
if (languageSpecificPrimitives.contains(type))
return (type);
} else
type = getTypeDeclaration(toModelName(snakeCase(schemaType)));
type = getTypeDeclaration(toModelName(lowerCamelCase(schemaType)));
return type;
}

View File

@@ -137,7 +137,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
} else if (typeMapping.containsKey(typeDeclaration)) {
return typeMapping.get(typeDeclaration);
} else {
return getTypeDeclaration(toModelName(snakeCase(typeDeclaration)));
return getTypeDeclaration(toModelName(lowerCamelCase(typeDeclaration)));
}
}
@@ -179,7 +179,7 @@ public class ErlangProperCodegen extends DefaultCodegen implements CodegenConfig
} else if (typeMapping.containsKey(schemaType)) {
return typeMapping.get(schemaType);
} else {
return getTypeDeclaration(toModelName(snakeCase(schemaType)));
return getTypeDeclaration(toModelName(lowerCamelCase(schemaType)));
}
}

View File

@@ -695,4 +695,12 @@ public class JavaClientCodegen extends AbstractJavaCodegen
return mime != null && JSON_VENDOR_MIME_PATTERN.matcher(mime).matches();
}
@Override
public String toApiVarName(String name) {
String apiVarName = super.toApiVarName(name);
if (reservedWords.contains(apiVarName)) {
apiVarName = escapeReservedWord(apiVarName);
}
return apiVarName;
}
}

View File

@@ -44,6 +44,7 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
public static final String ROOT_PACKAGE = "rootPackage";
public static final String RX_INTERFACE_OPTION = "rxInterface";
public static final String RX_VERSION_2_OPTION = "rxVersion2";
public static final String VERTX_SWAGGER_ROUTER_VERSION_OPTION = "vertxSwaggerRouterVersion";
/**
@@ -88,6 +89,9 @@ public class JavaVertXServerCodegen extends AbstractJavaCodegen {
cliOptions.add(CliOption.newBoolean(RX_INTERFACE_OPTION,
"When specified, API interfaces are generated with RX "
+ "and methods return Single<> and Comparable."));
cliOptions.add(CliOption.newBoolean(RX_VERSION_2_OPTION,
"When specified in combination with rxInterface, "
+ "API interfaces are generated with RxJava2."));
cliOptions.add(CliOption.newString(VERTX_SWAGGER_ROUTER_VERSION_OPTION,
"Specify the version of the swagger router library"));

View File

@@ -61,7 +61,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
public static final String SERVICE_INTERFACE = "serviceInterface";
public static final String SERVICE_IMPLEMENTATION = "serviceImplementation";
public static final String REACTIVE = "reactive";
public static final String INTERFACE_ONLY = "interfaceOnly";
private String basePackage;
private String invokerPackage;
@@ -75,12 +75,11 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
private boolean serviceInterface = false;
private boolean serviceImplementation = false;
private boolean reactive = false;
private boolean interfaceOnly = false;
public KotlinSpringServerCodegen() {
super();
apiTestTemplateFiles.put("api_test.mustache", ".kt");
reservedWords.addAll(VARIABLE_RESERVED_WORDS);
outputFolder = "generated-code/kotlin-spring";
@@ -124,6 +123,7 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
"interfaces. If this is set to true service interfaces will also be generated", serviceImplementation);
addSwitch(USE_BEANVALIDATION, "Use BeanValidation API annotations to validate data types", useBeanValidation);
addSwitch(REACTIVE, "use coroutines for reactive behavior", reactive);
addSwitch(INTERFACE_ONLY, "Whether to generate only API interface stubs without the server files.", interfaceOnly);
supportedLibraries.put(SPRING_BOOT, "Spring-boot Server application.");
setLibrary(SPRING_BOOT);
@@ -209,6 +209,10 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
return this.useBeanValidation;
}
public void setInterfaceOnly(boolean interfaceOnly) {
this.interfaceOnly = interfaceOnly;
}
@Override
public void setUseBeanValidation(boolean useBeanValidation) {
this.useBeanValidation = useBeanValidation;
@@ -322,9 +326,18 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
writePropertyBack(REACTIVE, reactive);
writePropertyBack(EXCEPTION_HANDLER, exceptionHandler);
if (additionalProperties.containsKey(INTERFACE_ONLY)) {
this.setInterfaceOnly(Boolean.valueOf(additionalProperties.get(INTERFACE_ONLY).toString()));
}
modelTemplateFiles.put("model.mustache", ".kt");
apiTemplateFiles.put("api.mustache", ".kt");
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
if (interfaceOnly) {
apiTemplateFiles.put("apiInterface.mustache", ".kt");
} else {
apiTemplateFiles.put("api.mustache", ".kt");
apiTestTemplateFiles.put("api_test.mustache", ".kt");
}
if (this.serviceInterface) {
apiTemplateFiles.put("service.mustache", "Service.kt");
@@ -335,6 +348,9 @@ public class KotlinSpringServerCodegen extends AbstractKotlinCodegen
apiTemplateFiles.put("serviceImpl.mustache", "ServiceImpl.kt");
}
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
if (this.exceptionHandler) {
supportingFiles.add(new SupportingFile("exceptions.mustache",
sanitizeDirectory(sourceFolder + File.separator + apiPackage), "Exceptions.kt"));

View File

@@ -200,7 +200,7 @@ public class PhpSymfonyServerCodegen extends AbstractPhpCodegen implements Codeg
if (alias != null && !alias.isEmpty()) {
this.bundleAlias = alias.toLowerCase(Locale.ROOT);
} else {
this.bundleAlias = snakeCase(bundleName).replaceAll("([A-Z]+)", "\\_$1").toLowerCase(Locale.ROOT);
this.bundleAlias = lowerCamelCase(bundleName).replaceAll("([A-Z]+)", "\\_$1").toLowerCase(Locale.ROOT);
}
}