forked from loafle/openapi-generator-original
Merge branch '2.3.0' of https://github.com/swagger-api/swagger-codegen into 2.3.0
This commit is contained in:
commit
9936018090
@ -151,7 +151,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
additionalProperties.put(CodegenConstants.PACKAGE_NAME, packageName);
|
||||||
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
additionalProperties.put(CodegenConstants.PACKAGE_VERSION, packageVersion);
|
||||||
|
|
||||||
additionalProperties.put("apiDocPath", apiDocPath);
|
additionalProperties.put("apiDocPath", apiDocPath);
|
||||||
additionalProperties.put("modelDocPath", modelDocPath);
|
additionalProperties.put("modelDocPath", modelDocPath);
|
||||||
|
|
||||||
@ -180,10 +180,10 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// - XName
|
// - XName
|
||||||
// - X_Name
|
// - X_Name
|
||||||
// ... or maybe a suffix?
|
// ... or maybe a suffix?
|
||||||
// - Name_ ... think this will work.
|
// - Name_ ... think this will work.
|
||||||
if(this.reservedWordsMappings().containsKey(name)) {
|
if(this.reservedWordsMappings().containsKey(name)) {
|
||||||
return this.reservedWordsMappings().get(name);
|
return this.reservedWordsMappings().get(name);
|
||||||
}
|
}
|
||||||
return camelize(name) + '_';
|
return camelize(name) + '_';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,7 +465,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return objs;
|
return postProcessModelsEnum(objs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -499,4 +499,65 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
return customImport;
|
return customImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumValue(String value, String datatype) {
|
||||||
|
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return escapeText(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumDefaultValue(String value, String datatype) {
|
||||||
|
return datatype + "_" + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumVarName(String name, String datatype) {
|
||||||
|
if (name.length() == 0) {
|
||||||
|
return "EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
// number
|
||||||
|
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||||
|
String varName = name;
|
||||||
|
varName = varName.replaceAll("-", "MINUS_");
|
||||||
|
varName = varName.replaceAll("\\+", "PLUS_");
|
||||||
|
varName = varName.replaceAll("\\.", "_DOT_");
|
||||||
|
return varName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for symbol, e.g. $, #
|
||||||
|
if (getSymbolName(name) != null) {
|
||||||
|
return getSymbolName(name).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// string
|
||||||
|
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||||
|
enumName = enumName.replaceFirst("^_", "");
|
||||||
|
enumName = enumName.replaceFirst("_$", "");
|
||||||
|
|
||||||
|
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
|
||||||
|
return escapeReservedWord(enumName);
|
||||||
|
} else {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumName(CodegenProperty property) {
|
||||||
|
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||||
|
|
||||||
|
// remove [] for array or map of enum
|
||||||
|
enumName = enumName.replace("[]", "");
|
||||||
|
|
||||||
|
if (enumName.matches("\\d.*")) { // starts with number
|
||||||
|
return "_" + enumName;
|
||||||
|
} else {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,7 +34,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
protected int serverPort = 8080;
|
protected int serverPort = 8080;
|
||||||
protected String projectName = "swagger-server";
|
protected String projectName = "swagger-server";
|
||||||
protected String apiPath = "go";
|
protected String apiPath = "go";
|
||||||
|
|
||||||
public GoServerCodegen() {
|
public GoServerCodegen() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
@ -160,8 +160,8 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
);
|
);
|
||||||
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
|
supportingFiles.add(new SupportingFile("main.mustache", "", "main.go"));
|
||||||
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
|
supportingFiles.add(new SupportingFile("routers.mustache", apiPath, "routers.go"));
|
||||||
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go"));
|
supportingFiles.add(new SupportingFile("logger.mustache", apiPath, "logger.go"));
|
||||||
supportingFiles.add(new SupportingFile("app.mustache", apiPath, "app.yaml"));
|
supportingFiles.add(new SupportingFile("app.mustache", apiPath, "app.yaml"));
|
||||||
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md"));
|
writeOptional(outputFolder, new SupportingFile("README.mustache", apiPath, "README.md"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +222,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public String escapeReservedWord(String name) {
|
public String escapeReservedWord(String name) {
|
||||||
if(this.reservedWordsMappings().containsKey(name)) {
|
if(this.reservedWordsMappings().containsKey(name)) {
|
||||||
return this.reservedWordsMappings().get(name);
|
return this.reservedWordsMappings().get(name);
|
||||||
}
|
}
|
||||||
return "_" + name; // add an underscore to the name
|
return "_" + name; // add an underscore to the name
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
|
|
||||||
return toModelName(swaggerType);
|
return toModelName(swaggerType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSwaggerType(Property p) {
|
public String getSwaggerType(Property p) {
|
||||||
String swaggerType = super.getSwaggerType(p);
|
String swaggerType = super.getSwaggerType(p);
|
||||||
@ -341,4 +341,69 @@ public class GoServerCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumValue(String value, String datatype) {
|
||||||
|
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||||
|
return value;
|
||||||
|
} else {
|
||||||
|
return "\'" + escapeText(value) + "\'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumDefaultValue(String value, String datatype) {
|
||||||
|
return datatype + "_" + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumVarName(String name, String datatype) {
|
||||||
|
if (name.length() == 0) {
|
||||||
|
return "EMPTY";
|
||||||
|
}
|
||||||
|
|
||||||
|
// number
|
||||||
|
if ("int".equals(datatype) || "double".equals(datatype) || "float".equals(datatype)) {
|
||||||
|
String varName = name;
|
||||||
|
varName = varName.replaceAll("-", "MINUS_");
|
||||||
|
varName = varName.replaceAll("\\+", "PLUS_");
|
||||||
|
varName = varName.replaceAll("\\.", "_DOT_");
|
||||||
|
return varName;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for symbol, e.g. $, #
|
||||||
|
if (getSymbolName(name) != null) {
|
||||||
|
return getSymbolName(name).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
// string
|
||||||
|
String enumName = sanitizeName(underscore(name).toUpperCase());
|
||||||
|
enumName = enumName.replaceFirst("^_", "");
|
||||||
|
enumName = enumName.replaceFirst("_$", "");
|
||||||
|
|
||||||
|
if (isReservedWord(enumName) || enumName.matches("\\d.*")) { // reserved word or starts with number
|
||||||
|
return escapeReservedWord(enumName);
|
||||||
|
} else {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toEnumName(CodegenProperty property) {
|
||||||
|
String enumName = underscore(toModelName(property.name)).toUpperCase();
|
||||||
|
|
||||||
|
// remove [] for array or map of enum
|
||||||
|
enumName = enumName.replace("[]", "");
|
||||||
|
|
||||||
|
if (enumName.matches("\\d.*")) { // starts with number
|
||||||
|
return "_" + enumName;
|
||||||
|
} else {
|
||||||
|
return enumName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
|
// process enum in models
|
||||||
|
return postProcessModelsEnum(objs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,21 @@ package {{packageName}}
|
|||||||
import ({{/imports}}{{#imports}}
|
import ({{/imports}}{{#imports}}
|
||||||
"{{import}}"{{/imports}}{{#imports}}
|
"{{import}}"{{/imports}}{{#imports}}
|
||||||
)
|
)
|
||||||
{{/imports}}{{#model}}{{#description}}
|
{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}}
|
||||||
|
type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
|
||||||
|
|
||||||
|
// List of {{{name}}}
|
||||||
|
const (
|
||||||
|
{{#allowableValues}}
|
||||||
|
{{#enumVars}}
|
||||||
|
{{name}} {{{classname}}} = "{{{value}}}"
|
||||||
|
{{/enumVars}}
|
||||||
|
{{/allowableValues}}
|
||||||
|
){{/isEnum}}{{^isEnum}}{{#description}}
|
||||||
// {{{description}}}{{/description}}
|
// {{{description}}}{{/description}}
|
||||||
type {{classname}} struct {
|
type {{classname}} struct {
|
||||||
{{#vars}}{{#description}}
|
{{#vars}}{{#description}}
|
||||||
// {{{description}}}{{/description}}
|
// {{{description}}}{{/description}}
|
||||||
{{name}} {{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"`
|
{{name}} {{^isEnum}}{{^isPrimitiveType}}{{^isContainer}}{{^isDateTime}}*{{/isDateTime}}{{/isContainer}}{{/isPrimitiveType}}{{/isEnum}}{{{datatype}}} `json:"{{baseName}}{{^required}},omitempty{{/required}}"`
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
}
|
}{{/isEnum}}{{/model}}{{/models}}
|
||||||
{{/model}}{{/models}}
|
|
||||||
|
@ -10,5 +10,11 @@
|
|||||||
|
|
||||||
package petstore
|
package petstore
|
||||||
|
|
||||||
type EnumClass struct {
|
type EnumClass string
|
||||||
}
|
|
||||||
|
// List of EnumClass
|
||||||
|
const (
|
||||||
|
ABC EnumClass = "_abc"
|
||||||
|
EFG EnumClass = "-efg"
|
||||||
|
XYZ EnumClass = "(xyz)"
|
||||||
|
)
|
||||||
|
@ -10,5 +10,11 @@
|
|||||||
|
|
||||||
package petstore
|
package petstore
|
||||||
|
|
||||||
type OuterEnum struct {
|
type OuterEnum string
|
||||||
}
|
|
||||||
|
// List of OuterEnum
|
||||||
|
const (
|
||||||
|
PLACED OuterEnum = "placed"
|
||||||
|
APPROVED OuterEnum = "approved"
|
||||||
|
DELIVERED OuterEnum = "delivered"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user