forked from loafle/openapi-generator-original
Merge branch 'develop_2.0' into library-template-jersey2
Conflicts: modules/swagger-codegen/src/main/resources/Java/JsonUtil.mustache
This commit is contained in:
@@ -30,6 +30,23 @@ public class CodegenOperation {
|
||||
public List<Map<String, String>> examples;
|
||||
public ExternalDocs externalDocs;
|
||||
|
||||
private boolean nonempty(List<CodegenParameter> params)
|
||||
{
|
||||
return params != null && params.size() > 0;
|
||||
}
|
||||
public boolean getHasBodyParam() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasQueryParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasHeaderParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
public boolean getHasPathParams() {
|
||||
return nonempty(bodyParams);
|
||||
}
|
||||
|
||||
// legacy support
|
||||
public String nickname;
|
||||
}
|
||||
|
||||
@@ -639,7 +639,9 @@ public class DefaultCodegen {
|
||||
if (np.getMaximum() != null) {
|
||||
allowableValues.put("max", np.getMaximum());
|
||||
}
|
||||
property.allowableValues = allowableValues;
|
||||
if(allowableValues.size() > 0) {
|
||||
property.allowableValues = allowableValues;
|
||||
}
|
||||
}
|
||||
|
||||
if (p instanceof StringProperty) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.swagger.models.parameters.Parameter;
|
||||
import io.swagger.util.Json;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
@@ -63,6 +64,10 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
List<File> files = new ArrayList<File>();
|
||||
try {
|
||||
config.processOpts();
|
||||
|
||||
config.additionalProperties().put("generatedDate", DateTime.now().toString());
|
||||
config.additionalProperties().put("generatorClass", config.getClass().toString());
|
||||
|
||||
if (swagger.getInfo() != null) {
|
||||
Info info = swagger.getInfo();
|
||||
if (info.getTitle() != null) {
|
||||
@@ -189,7 +194,7 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
|
||||
for (String templateName : config.apiTemplateFiles().keySet()) {
|
||||
|
||||
String filename = config.apiFilename(templateName, tag);
|
||||
if (!config.shouldOverwrite(filename)) {
|
||||
if (!config.shouldOverwrite(filename) && new File(filename).exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -96,7 +96,7 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.setInvokerPackage((String) additionalProperties.get("invokerPackage"));
|
||||
} else {
|
||||
@@ -134,6 +134,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
this.setLocalVariablePrefix((String) additionalProperties.get("localVariablePrefix"));
|
||||
}
|
||||
|
||||
this.sanitizeConfig();
|
||||
|
||||
final String invokerFolder = (sourceFolder + File.separator + invokerPackage).replace(".", File.separator);
|
||||
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
supportingFiles.add(new SupportingFile("ApiClient.mustache", invokerFolder, "ApiClient.java"));
|
||||
@@ -151,7 +153,26 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("auth/OAuth.mustache", authFolder, "OAuth.java"));
|
||||
}
|
||||
|
||||
|
||||
private void sanitizeConfig() {
|
||||
// Sanitize any config options here. We also have to update the additionalProperties because
|
||||
// the whole additionalProperties object is injected into the main object passed to the mustache layer
|
||||
|
||||
this.setApiPackage(sanitizePackageName(apiPackage));
|
||||
if (additionalProperties.containsKey("apiPackage")) {
|
||||
this.additionalProperties.put("apiPackage", apiPackage);
|
||||
}
|
||||
|
||||
this.setModelPackage(sanitizePackageName(modelPackage));
|
||||
if (additionalProperties.containsKey("modelPackage")) {
|
||||
this.additionalProperties.put("modelPackage", modelPackage);
|
||||
}
|
||||
|
||||
this.setInvokerPackage(sanitizePackageName(invokerPackage));
|
||||
if (additionalProperties.containsKey("invokerPackage")) {
|
||||
this.additionalProperties.put("invokerPackage", invokerPackage);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return "_" + name;
|
||||
@@ -347,4 +368,14 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void setLocalVariablePrefix(String localVariablePrefix) {
|
||||
this.localVariablePrefix = localVariablePrefix;
|
||||
}
|
||||
|
||||
private String sanitizePackageName(String packageName) {
|
||||
packageName = packageName.trim();
|
||||
packageName = packageName.replaceAll("[^a-zA-Z0-9_\\.]", "_");
|
||||
if(Strings.isNullOrEmpty(packageName)) {
|
||||
return "invalidPackageName";
|
||||
}
|
||||
return packageName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String escapeReservedWord(String name) {
|
||||
return name + "_";
|
||||
return "_" + name;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -179,14 +179,14 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
// petId => pet_id
|
||||
name = underscore(dropDots(name));
|
||||
|
||||
// remove leading underscore
|
||||
name = name.replaceAll("^_*", "");
|
||||
|
||||
// for reserved word or word starting with number, append _
|
||||
if (reservedWords.contains(name) || name.matches("^\\d.*")) {
|
||||
name = escapeReservedWord(name);
|
||||
}
|
||||
|
||||
// remove leading underscore
|
||||
name = name.replaceAll("^_*", "");
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user