forked from loafle/openapi-generator-original
Merge remote-tracking branch 'origin/master' into 2.3.0
This commit is contained in:
@@ -18,7 +18,7 @@ public class CodegenModel {
|
||||
public CodegenModel parentModel;
|
||||
public List<CodegenModel> interfaceModels;
|
||||
|
||||
public String name, classname, description, classVarName, modelJson, dataType;
|
||||
public String name, classname, title, description, classVarName, modelJson, dataType;
|
||||
public String classFilename; // store the class file name, mainly used for import
|
||||
public String unescapedDescription;
|
||||
public String discriminator;
|
||||
@@ -80,6 +80,8 @@ public class CodegenModel {
|
||||
return false;
|
||||
if (classname != null ? !classname.equals(that.classname) : that.classname != null)
|
||||
return false;
|
||||
if (title != null ? !title.equals(that.title) : that.title != null)
|
||||
return false;
|
||||
if (description != null ? !description.equals(that.description) : that.description != null)
|
||||
return false;
|
||||
if (classVarName != null ? !classVarName.equals(that.classVarName) : that.classVarName != null)
|
||||
@@ -143,6 +145,7 @@ public class CodegenModel {
|
||||
result = 31 * result + (interfaceModels != null ? interfaceModels.hashCode() : 0);
|
||||
result = 31 * result + (name != null ? name.hashCode() : 0);
|
||||
result = 31 * result + (classname != null ? classname.hashCode() : 0);
|
||||
result = 31 * result + (title != null ? title.hashCode() : 0);
|
||||
result = 31 * result + (description != null ? description.hashCode() : 0);
|
||||
result = 31 * result + (classVarName != null ? classVarName.hashCode() : 0);
|
||||
result = 31 * result + (modelJson != null ? modelJson.hashCode() : 0);
|
||||
|
||||
@@ -1205,6 +1205,7 @@ public class DefaultCodegen {
|
||||
} else {
|
||||
m.name = name;
|
||||
}
|
||||
m.title = escapeText(model.getTitle());
|
||||
m.description = escapeText(model.getDescription());
|
||||
m.unescapedDescription = model.getDescription();
|
||||
m.classname = toModelName(name);
|
||||
@@ -2455,6 +2456,9 @@ public class DefaultCodegen {
|
||||
sec.isKeyInHeader = sec.isKeyInQuery = sec.isApiKey = sec.isBasic = false;
|
||||
sec.isOAuth = true;
|
||||
sec.flow = oauth2Definition.getFlow();
|
||||
if (sec.flow == null) {
|
||||
throw new RuntimeException("missing oauth flow in " + sec.name);
|
||||
}
|
||||
switch(sec.flow) {
|
||||
case "accessCode":
|
||||
sec.isCode = true;
|
||||
|
||||
@@ -182,8 +182,10 @@ public class InlineModelResolver {
|
||||
}
|
||||
} else if (model instanceof ComposedModel) {
|
||||
ComposedModel m = (ComposedModel) model;
|
||||
Map<String, Property> properties = m.getChild().getProperties();
|
||||
flattenProperties(properties, modelName);
|
||||
if (m.getChild() != null) {
|
||||
Map<String, Property> properties = m.getChild().getProperties();
|
||||
flattenProperties(properties, modelName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,6 +377,11 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// to avoid conflicts with 'callback' parameter for async call
|
||||
if ("callback".equals(name)) {
|
||||
return "paramCallback";
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
apiTestTemplateFiles.put("api_test.mustache", ".php");
|
||||
modelDocTemplateFiles.put("model_doc.mustache", ".md");
|
||||
apiDocTemplateFiles.put("api_doc.mustache", ".md");
|
||||
|
||||
|
||||
apiPackage = invokerPackage + "\\" + apiDirName;
|
||||
modelPackage = invokerPackage + "\\" + modelDirName;
|
||||
|
||||
@@ -197,6 +197,12 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||
|
||||
// make api and model src path available in mustache template
|
||||
additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
|
||||
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
|
||||
additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
|
||||
additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
@@ -213,6 +219,10 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
|
||||
}
|
||||
|
||||
public String toSrcPath(String packageName, String basePath) {
|
||||
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (basePath != null && basePath.length() > 0) {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
@@ -232,13 +242,13 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
regLastPathSeparator = "\\\\$";
|
||||
}
|
||||
|
||||
return (getPackagePath() + File.separatorChar + basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll(regFirstPathSeparator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
return (basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll(regFirstPathSeparator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -392,7 +402,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// remove [
|
||||
// remove [
|
||||
name = name.replaceAll("\\]", "");
|
||||
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
@@ -417,7 +427,7 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
if (!name.matches("^\\\\.*")) {
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
}
|
||||
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
@@ -642,5 +652,5 @@ public abstract class AbstractPhpCodegen extends DefaultCodegen implements Codeg
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
return input.replace("*/", "");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.google.common.collect.ImmutableMap;
|
||||
import io.swagger.codegen.CodegenConstants;
|
||||
import io.swagger.codegen.CodegenType;
|
||||
import io.swagger.codegen.CodegenModel;
|
||||
import io.swagger.codegen.CodegenParameter;
|
||||
import io.swagger.codegen.SupportingFile;
|
||||
import io.swagger.codegen.CodegenProperty;
|
||||
import io.swagger.codegen.CodegenOperation;
|
||||
@@ -11,8 +12,10 @@ import io.swagger.codegen.CliOption;
|
||||
import io.swagger.models.Model;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -37,8 +40,7 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
protected boolean supportsAsync = Boolean.TRUE;
|
||||
protected boolean supportsUWP = Boolean.FALSE;
|
||||
protected boolean generatePropertyChanged = Boolean.FALSE;
|
||||
|
||||
|
||||
protected Map<Character, String> regexModifiers;
|
||||
protected final Map<String, String> frameworks;
|
||||
|
||||
public CSharpClientCodegen() {
|
||||
@@ -124,6 +126,12 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
addSwitch(CodegenConstants.GENERATE_PROPERTY_CHANGED,
|
||||
CodegenConstants.PACKAGE_DESCRIPTION_DESC,
|
||||
this.generatePropertyChanged);
|
||||
|
||||
regexModifiers = new HashMap<Character, String>();
|
||||
regexModifiers.put('i', "IgnoreCase");
|
||||
regexModifiers.put('m', "Multiline");
|
||||
regexModifiers.put('s', "Singleline");
|
||||
regexModifiers.put('x', "IgnorePatternWhitespace");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -350,6 +358,56 @@ public class CSharpClientCodegen extends AbstractCSharpCodegen {
|
||||
return super.postProcessModels(objMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessParameter(CodegenParameter parameter) {
|
||||
postProcessPattern(parameter.pattern, parameter.vendorExtensions);
|
||||
super.postProcessParameter(parameter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
postProcessPattern(property.pattern, property.vendorExtensions);
|
||||
super.postProcessModelProperty(model, property);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The swagger pattern spec follows the Perl convention and style of modifiers. .NET
|
||||
* does not support this syntax directly so we need to convert the pattern to a .NET compatible
|
||||
* format and apply modifiers in a compatible way.
|
||||
* See https://msdn.microsoft.com/en-us/library/yd1hzczs(v=vs.110).aspx for .NET options.
|
||||
* See https://github.com/swagger-api/swagger-codegen/pull/2794 for Python's initial implementation from which this is copied.
|
||||
*/
|
||||
public void postProcessPattern(String pattern, Map<String, Object> vendorExtensions) {
|
||||
if(pattern != null) {
|
||||
int i = pattern.lastIndexOf('/');
|
||||
|
||||
//Must follow Perl /pattern/modifiers convention
|
||||
if(pattern.charAt(0) != '/' || i < 2) {
|
||||
throw new IllegalArgumentException("Pattern must follow the Perl "
|
||||
+ "/pattern/modifiers convention. "+pattern+" is not valid.");
|
||||
}
|
||||
|
||||
String regex = pattern.substring(1, i).replace("'", "\'");
|
||||
List<String> modifiers = new ArrayList<String>();
|
||||
|
||||
// perl requires an explicit modifier to be culture specific and .NET is the reverse.
|
||||
modifiers.add("CultureInvariant");
|
||||
|
||||
for(char c : pattern.substring(i).toCharArray()) {
|
||||
if(regexModifiers.containsKey(c)) {
|
||||
String modifier = regexModifiers.get(c);
|
||||
modifiers.add(modifier);
|
||||
} else if (c == 'l') {
|
||||
modifiers.remove("CultureInvariant");
|
||||
}
|
||||
}
|
||||
|
||||
vendorExtensions.put("x-regex", regex);
|
||||
vendorExtensions.put("x-modifiers", modifiers);
|
||||
}
|
||||
}
|
||||
|
||||
public void setTargetFramework(String dotnetFramework) {
|
||||
if(!frameworks.containsKey(dotnetFramework)){
|
||||
LOGGER.warn("Invalid .NET framework version, defaulting to " + this.targetFramework);
|
||||
|
||||
@@ -217,6 +217,10 @@ public class CppRestClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
if (methodResponse.getSchema() != null) {
|
||||
CodegenProperty cm = fromProperty("response", methodResponse.getSchema());
|
||||
op.vendorExtensions.put("x-codegen-response", cm);
|
||||
if(cm.datatype == "HttpContent")
|
||||
{
|
||||
op.vendorExtensions.put("x-codegen-response-ishttpcontent", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,7 +271,8 @@ public class CppRestClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
Property inner = mp.getAdditionalProperties();
|
||||
return getSwaggerType(p) + "<utility::string_t, " + getTypeDeclaration(inner) + ">";
|
||||
}
|
||||
if (p instanceof StringProperty || p instanceof DateProperty || p instanceof DateTimeProperty
|
||||
if (p instanceof StringProperty || p instanceof DateProperty
|
||||
|| p instanceof DateTimeProperty || p instanceof FileProperty
|
||||
|| languageSpecificPrimitives.contains(swaggerType)) {
|
||||
return toModelName(swaggerType);
|
||||
}
|
||||
@@ -289,7 +294,7 @@ public class CppRestClientCodegen extends DefaultCodegen implements CodegenConfi
|
||||
return "0.0";
|
||||
} else if (p instanceof FloatProperty) {
|
||||
return "0.0f";
|
||||
} else if (p instanceof IntegerProperty) {
|
||||
} else if (p instanceof IntegerProperty || p instanceof BaseIntegerProperty) {
|
||||
return "0";
|
||||
} else if (p instanceof LongProperty) {
|
||||
return "0L";
|
||||
|
||||
@@ -65,7 +65,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
modelTemplateFiles.clear();
|
||||
|
||||
apiTemplateFiles.clear();
|
||||
apiTemplateFiles.put("controller.mustache", ".py");
|
||||
|
||||
/*
|
||||
* Template Location. This is the location which templates will be read from. The generator
|
||||
@@ -122,7 +122,7 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
apiTemplateFiles.clear();
|
||||
//apiTemplateFiles.clear();
|
||||
|
||||
if (additionalProperties.containsKey(CONTROLLER_PACKAGE)) {
|
||||
this.controllerPackage = additionalProperties.get(CONTROLLER_PACKAGE).toString();
|
||||
@@ -145,10 +145,10 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
}
|
||||
|
||||
if(!new java.io.File(controllerPackage + File.separator + defaultController + ".py").exists()) {
|
||||
supportingFiles.add(new SupportingFile("controller.mustache",
|
||||
controllerPackage,
|
||||
defaultController + ".py")
|
||||
);
|
||||
//supportingFiles.add(new SupportingFile("controller.mustache",
|
||||
// controllerPackage,
|
||||
// defaultController + ".py")
|
||||
//);
|
||||
supportingFiles.add(new SupportingFile("__init__.mustache",
|
||||
controllerPackage,
|
||||
"__init__.py")
|
||||
@@ -197,15 +197,15 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
if (name == null || name.length() == 0) {
|
||||
return "DefaultController";
|
||||
}
|
||||
return initialCaps(name);
|
||||
return camelize(name, false) + "Controller";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiFilename(String name) {
|
||||
return toApiName(name);
|
||||
return underscore(toApiName(name));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,24 +228,22 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
return outputFolder + File.separator + apiPackage().replace('.', File.separatorChar);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void preprocessSwagger(Swagger swagger) {
|
||||
if(swagger != null && swagger.getPaths() != null) {
|
||||
if (swagger != null && swagger.getPaths() != null) {
|
||||
for(String pathname : swagger.getPaths().keySet()) {
|
||||
Path path = swagger.getPath(pathname);
|
||||
if(path.getOperations() != null) {
|
||||
if (path.getOperations() != null) {
|
||||
for(Map.Entry<HttpMethod, Operation> entry : path.getOperationMap().entrySet()) {
|
||||
// Normalize `operationId` and add package/class path in front, e.g.
|
||||
// controllers.default_controller.add_pet
|
||||
String httpMethod = entry.getKey().name().toLowerCase();
|
||||
Operation operation = entry.getValue();
|
||||
String operationId = getOrGenerateOperationId(operation, pathname, httpMethod);
|
||||
if(!operationId.contains(".")) {
|
||||
operationId = underscore(sanitizeName(operationId));
|
||||
operationId = controllerPackage + "." + defaultController + "." + operationId;
|
||||
}
|
||||
operation.setOperationId(operationId);
|
||||
if(operation.getTags() != null) {
|
||||
String controllerName;
|
||||
|
||||
if (operation.getTags() != null) {
|
||||
List<Map<String, String>> tags = new ArrayList<Map<String, String>>();
|
||||
for(String tag : operation.getTags()) {
|
||||
Map<String, String> value = new HashMap<String, String>();
|
||||
@@ -253,19 +251,32 @@ public class FlaskConnexionCodegen extends DefaultCodegen implements CodegenConf
|
||||
value.put("hasMore", "true");
|
||||
tags.add(value);
|
||||
}
|
||||
if(tags.size() > 0) {
|
||||
|
||||
if (tags.size() > 0) {
|
||||
tags.get(tags.size() - 1).remove("hasMore");
|
||||
}
|
||||
if(operation.getTags().size() > 0) {
|
||||
|
||||
// use only the first tag
|
||||
if (operation.getTags().size() > 0) {
|
||||
String tag = operation.getTags().get(0);
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
controllerName = tag + "_controller";
|
||||
} else {
|
||||
controllerName = "default_controller";
|
||||
}
|
||||
|
||||
operation.setVendorExtension("x-tags", tags);
|
||||
}
|
||||
else {
|
||||
// no tag found, use "default_controller" as the default
|
||||
String tag = "default_controller";
|
||||
operation.setTags(Arrays.asList(tag));
|
||||
controllerName = tag + "_controller";
|
||||
}
|
||||
|
||||
operationId = underscore(sanitizeName(operationId));
|
||||
operationId = controllerPackage + "." + controllerName + "." + operationId;
|
||||
operation.setOperationId(operationId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,11 +414,10 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
}
|
||||
|
||||
// this will only import "strings" "fmt" if there are items in pathParams
|
||||
// this will only import "fmt" if there are items in pathParams
|
||||
for (CodegenOperation operation : operations) {
|
||||
if(operation.pathParams != null && operation.pathParams.size() > 0) {
|
||||
imports.add(createMapping("import", "fmt"));
|
||||
imports.add(createMapping("import", "strings"));
|
||||
break; //just need to import once
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,15 @@ import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
protected static final String LIBRARY_JERSEY1 = "jersey1";
|
||||
protected static final String LIBRARY_JERSEY2 = "jersey2";
|
||||
|
||||
/**
|
||||
* Default library template to use. (Default:{@value #DEFAULT_LIBRARY})
|
||||
*/
|
||||
public static final String DEFAULT_LIBRARY = LIBRARY_JERSEY2;
|
||||
|
||||
public JavaJerseyServerCodegen() {
|
||||
super();
|
||||
|
||||
@@ -29,10 +38,10 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
|
||||
CliOption library = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use");
|
||||
|
||||
supportedLibraries.put("jersey1", "Jersey core 1.x");
|
||||
supportedLibraries.put("jersey2", "Jersey core 2.x (default)");
|
||||
supportedLibraries.put(LIBRARY_JERSEY1, "Jersey core 1.x");
|
||||
supportedLibraries.put(LIBRARY_JERSEY2, "Jersey core 2.x");
|
||||
library.setEnum(supportedLibraries);
|
||||
library.setDefault("jersey1");
|
||||
library.setDefault(DEFAULT_LIBRARY);
|
||||
|
||||
cliOptions.add(library);
|
||||
|
||||
@@ -71,9 +80,9 @@ public class JavaJerseyServerCodegen extends AbstractJavaJAXRSServerCodegen {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
// set jersey2 as default
|
||||
// use default library if unset
|
||||
if (StringUtils.isEmpty(library)) {
|
||||
setLibrary("jersey2");
|
||||
setLibrary(DEFAULT_LIBRARY);
|
||||
}
|
||||
|
||||
if ( additionalProperties.containsKey(CodegenConstants.IMPL_FOLDER)) {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
// clear import mapping (from default generator) as php does not use it
|
||||
// at the moment
|
||||
importMapping.clear();
|
||||
|
||||
|
||||
|
||||
supportsInheritance = true;
|
||||
outputFolder = "generated-code" + File.separator + "php";
|
||||
@@ -150,6 +150,10 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
}
|
||||
|
||||
public String toPackagePath(String packageName, String basePath) {
|
||||
return (getPackagePath() + File.separatorChar + toSrcPath(packageName, basePath));
|
||||
}
|
||||
|
||||
public String toSrcPath(String packageName, String basePath) {
|
||||
packageName = packageName.replace(invokerPackage, ""); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
if (basePath != null && basePath.length() > 0) {
|
||||
basePath = basePath.replaceAll("[\\\\/]?$", "") + File.separatorChar; // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
@@ -169,13 +173,13 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
regLastPathSeparator = "\\\\$";
|
||||
}
|
||||
|
||||
return (getPackagePath() + File.separatorChar + basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll(regFirstPathSeparator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
return (basePath
|
||||
// Replace period, backslash, forward slash with file separator in package name
|
||||
+ packageName.replaceAll("[\\.\\\\/]", Matcher.quoteReplacement(File.separator))
|
||||
// Trim prefix file separators from package path
|
||||
.replaceAll(regFirstPathSeparator, ""))
|
||||
// Trim trailing file separators from the overall path
|
||||
.replaceAll(regLastPathSeparator+ "$", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -276,6 +280,12 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
additionalProperties.put("escapedInvokerPackage", invokerPackage.replace("\\", "\\\\"));
|
||||
|
||||
// make api and model src path available in mustache template
|
||||
additionalProperties.put("apiSrcPath", "./" + toSrcPath(apiPackage, srcBasePath));
|
||||
additionalProperties.put("modelSrcPath", "./" + toSrcPath(modelPackage, srcBasePath));
|
||||
additionalProperties.put("apiTestPath", "./" + testBasePath + "/" + apiDirName);
|
||||
additionalProperties.put("modelTestPath", "./" + testBasePath + "/" + modelDirName);
|
||||
|
||||
// make api and model doc path available in mustache template
|
||||
additionalProperties.put("apiDocPath", apiDocPath);
|
||||
additionalProperties.put("modelDocPath", modelDocPath);
|
||||
@@ -290,7 +300,9 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
supportingFiles.add(new SupportingFile("composer.mustache", getPackagePath(), "composer.json"));
|
||||
supportingFiles.add(new SupportingFile("autoload.mustache", getPackagePath(), "autoload.php"));
|
||||
supportingFiles.add(new SupportingFile("README.mustache", getPackagePath(), "README.md"));
|
||||
supportingFiles.add(new SupportingFile("phpunit.xml.mustache", getPackagePath(), "phpunit.xml.dist"));
|
||||
supportingFiles.add(new SupportingFile(".travis.yml", getPackagePath(), ".travis.yml"));
|
||||
supportingFiles.add(new SupportingFile(".php_cs", getPackagePath(), ".php_cs"));
|
||||
supportingFiles.add(new SupportingFile("git_push.sh.mustache", getPackagePath(), "git_push.sh"));
|
||||
// apache v2 license
|
||||
supportingFiles.add(new SupportingFile("LICENSE", getPackagePath(), "LICENSE"));
|
||||
@@ -447,7 +459,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toModelName(String name) {
|
||||
// remove [
|
||||
// remove [
|
||||
name = name.replaceAll("\\]", "");
|
||||
|
||||
// Note: backslash ("\\") is allowed for e.g. "\\DateTime"
|
||||
@@ -472,7 +484,7 @@ public class PhpClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
if (!name.matches("^\\\\.*")) {
|
||||
name = modelNamePrefix + name + modelNameSuffix;
|
||||
}
|
||||
|
||||
|
||||
// camelize the model name
|
||||
// phone_number => PhoneNumber
|
||||
return camelize(name);
|
||||
|
||||
@@ -349,6 +349,11 @@ public class PythonClientCodegen extends DefaultCodegen implements CodegenConfig
|
||||
|
||||
@Override
|
||||
public String toParamName(String name) {
|
||||
// to avoid conflicts with 'callback' parameter for async call
|
||||
if ("callback".equals(name)) {
|
||||
return "param_callback";
|
||||
}
|
||||
|
||||
// should be the same as variable name
|
||||
return toVarName(name);
|
||||
}
|
||||
|
||||
@@ -90,4 +90,16 @@ public class StaticDocCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public String modelFileFolder() {
|
||||
return outputFolder + File.separator + sourceFolder + File.separator + "models";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,4 +149,16 @@ public class StaticHtml2Generator extends DefaultCodegen implements CodegenConfi
|
||||
public String normalizeType(String type) {
|
||||
return type.replaceAll("\\b(Boolean|Integer|Number|String|Date)\\b", "'$1'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,4 +99,17 @@ public class StaticHtmlGenerator extends DefaultCodegen implements CodegenConfig
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String escapeQuotationMark(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String escapeUnsafeCharacters(String input) {
|
||||
// just return the original string
|
||||
return input;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,219 @@
|
||||
package io.swagger.codegen.languages;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.swagger.codegen.*;
|
||||
import io.swagger.models.Operation;
|
||||
import io.swagger.models.Swagger;
|
||||
import io.swagger.util.Json;
|
||||
import io.swagger.util.Yaml;
|
||||
import org.apache.commons.lang3.BooleanUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
public class UndertowCodegen extends AbstractJavaCodegen {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(UndertowCodegen.class);
|
||||
|
||||
protected String title = "Swagger Undertow Server";
|
||||
protected String implFolder = "src/main/java";
|
||||
public UndertowCodegen() {
|
||||
super();
|
||||
|
||||
sourceFolder = "src/main/java";
|
||||
apiTestTemplateFiles.clear(); // TODO: add test template
|
||||
embeddedTemplateDir = templateDir = "undertow";
|
||||
invokerPackage = "io.swagger.handler";
|
||||
artifactId = "swagger-undertow-server";
|
||||
dateLibrary = "legacy"; //TODO: add joda support
|
||||
|
||||
// clear model and api doc template as this codegen
|
||||
// does not support auto-generated markdown doc at the moment
|
||||
//TODO: add doc templates
|
||||
modelDocTemplateFiles.remove("model_doc.mustache");
|
||||
apiDocTemplateFiles.remove("api_doc.mustache");
|
||||
|
||||
|
||||
apiPackage = System.getProperty("swagger.codegen.undertow.apipackage", "io.swagger.handler");
|
||||
modelPackage = System.getProperty("swagger.codegen.undertow.modelpackage", "io.swagger.model");
|
||||
|
||||
additionalProperties.put("title", title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.SERVER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "undertow";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelp() {
|
||||
return "Generates a Java Undertow Server application.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
apiTemplateFiles.remove("api.mustache");
|
||||
|
||||
writeOptional(outputFolder, new SupportingFile("pom.mustache", "", "pom.xml"));
|
||||
writeOptional(outputFolder, new SupportingFile("README.mustache", "", "README.md"));
|
||||
|
||||
// keep the yaml in config folder for framework validation.
|
||||
supportingFiles.add(new SupportingFile("swagger.mustache", ("src.main.resources.config").replace(".", java.io.File.separator), "swagger.json"));
|
||||
supportingFiles.add(new SupportingFile("handler.mustache", ("src.main.java.io.swagger.handler").replace(".", java.io.File.separator), "PathHandlerProvider.java"));
|
||||
supportingFiles.add(new SupportingFile("service.mustache", ("src.main.resources.META-INF.services").replace(".", java.io.File.separator), "com.networknt.server.HandlerProvider"));
|
||||
|
||||
// configuration files
|
||||
supportingFiles.add(new SupportingFile("server.json", ("src.main.resources.config").replace(".", java.io.File.separator), "server.json"));
|
||||
supportingFiles.add(new SupportingFile("security.json", ("src.main.resources.config").replace(".", java.io.File.separator), "security.json"));
|
||||
supportingFiles.add(new SupportingFile("primary.crt", ("src.main.resources.config.oauth").replace(".", java.io.File.separator), "primary.crt"));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@Override
|
||||
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
|
||||
String basePath = resourcePath;
|
||||
if (basePath.startsWith("/")) {
|
||||
basePath = basePath.substring(1);
|
||||
}
|
||||
int pos = basePath.indexOf("/");
|
||||
if (pos > 0) {
|
||||
basePath = basePath.substring(0, pos);
|
||||
}
|
||||
|
||||
if (basePath == "") {
|
||||
basePath = "default";
|
||||
} else {
|
||||
if (co.path.startsWith("/" + basePath)) {
|
||||
co.path = co.path.substring(("/" + basePath).length());
|
||||
}
|
||||
co.subresourceOperation = !co.path.isEmpty();
|
||||
}
|
||||
List<CodegenOperation> opList = operations.get(basePath);
|
||||
if (opList == null) {
|
||||
opList = new ArrayList<CodegenOperation>();
|
||||
operations.put(basePath, opList);
|
||||
}
|
||||
opList.add(co);
|
||||
co.baseName = basePath;
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||
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) {
|
||||
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);
|
||||
operation.returnContainer = "List";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Map")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Map<".length(), end);
|
||||
operation.returnContainer = "Map";
|
||||
}
|
||||
} else if (operation.returnType.startsWith("Set")) {
|
||||
String rt = operation.returnType;
|
||||
int end = rt.lastIndexOf(">");
|
||||
if (end > 0) {
|
||||
operation.returnType = rt.substring("Set<".length(), end);
|
||||
operation.returnContainer = "Set";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postProcessModelProperty(CodegenModel model, CodegenProperty property) {
|
||||
super.postProcessModelProperty(model, property);
|
||||
|
||||
//Add imports for Jackson
|
||||
if(!BooleanUtils.toBoolean(model.isEnum)) {
|
||||
model.imports.add("JsonProperty");
|
||||
|
||||
if(BooleanUtils.toBoolean(model.hasEnums)) {
|
||||
model.imports.add("JsonValue");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModelsEnum(Map<String, Object> objs) {
|
||||
objs = super.postProcessModelsEnum(objs);
|
||||
|
||||
//Add imports for Jackson
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>)objs.get("imports");
|
||||
List<Object> models = (List<Object>) objs.get("models");
|
||||
for (Object _mo : models) {
|
||||
Map<String, Object> mo = (Map<String, Object>) _mo;
|
||||
CodegenModel cm = (CodegenModel) mo.get("model");
|
||||
// for enum model
|
||||
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
|
||||
cm.imports.add(importMapping.get("JsonValue"));
|
||||
Map<String, String> item = new HashMap<String, String>();
|
||||
item.put("import", importMapping.get("JsonValue"));
|
||||
imports.add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
public String apiFilename(String templateName, String tag) {
|
||||
String result = super.apiFilename(templateName, tag);
|
||||
|
||||
if ( templateName.endsWith("api.mustache") ) {
|
||||
int ix = result.indexOf(sourceFolder);
|
||||
String beg = result.substring(0, ix);
|
||||
String end = result.substring(ix + sourceFolder.length());
|
||||
new java.io.File(beg + implFolder).mkdirs();
|
||||
result = beg + implFolder + end;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessSupportingFileData(Map<String, Object> objs) {
|
||||
Swagger swagger = (Swagger)objs.get("swagger");
|
||||
System.out.println("swagger" + swagger.toString());
|
||||
if(swagger != null) {
|
||||
try {
|
||||
//objs.put("swagger-json", Json.mapper().writeValueAsString(swagger));
|
||||
objs.put("swagger-json", Json.pretty().writeValueAsString(swagger));
|
||||
} catch (JsonProcessingException e) {
|
||||
LOGGER.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
return super.postProcessSupportingFileData(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toApiName(String name) {
|
||||
if (name.length() == 0) {
|
||||
return "DefaultHandler";
|
||||
}
|
||||
name = name.replaceAll("[^a-zA-Z0-9]+", "_"); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
|
||||
return camelize(name)+ "Handler";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user