[Go] Add more test cases and fix numeric form/header parameters (#3574)

* add more tests for go, fix numeric form/header parameters

* update go sample
This commit is contained in:
wing328
2016-08-11 14:28:31 +08:00
committed by GitHub
parent f41264c958
commit 752ba61e67
17 changed files with 95 additions and 28 deletions

View File

@@ -47,6 +47,11 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
setReservedWordsLowerCase(
Arrays.asList(
// data type
"string", "bool", "uint", "uint8", "uint16", "uint32", "uint64",
"int", "int8", "int16", "int32", "int64", "float32", "float64",
"complex64", "complex128", "rune", "byte", "uintptr",
"break", "default", "func", "interface", "select",
"case", "defer", "go", "map", "struct",
"chan", "else", "goto", "package", "switch",
@@ -91,6 +96,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
typeMapping.put("double", "float64");
typeMapping.put("boolean", "bool");
typeMapping.put("string", "string");
typeMapping.put("UUID", "string");
typeMapping.put("date", "time.Time");
typeMapping.put("DateTime", "time.Time");
typeMapping.put("password", "string");
@@ -192,9 +198,13 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
name = camelize(name);
// for reserved word or word starting with number, append _
if(isReservedWord(name) || name.matches("^\\d.*"))
if (isReservedWord(name))
name = escapeReservedWord(name);
// for reserved word or word starting with number, append _
if (name.matches("^\\d.*"))
name = "Var" + name;
return name;
}
@@ -230,10 +240,16 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
// model name cannot use reserved keyword, e.g. return
if (isReservedWord(name)) {
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("model_" + name));
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + ("model_" + name));
name = "model_" + name; // e.g. return => ModelReturn (after camelize)
}
// model name starts with number
if (name.matches("^\\d.*")) {
LOGGER.warn(name + " (model name starts with number) cannot be used as model name. Renamed to " + ("model_" + name));
name = "model_" + name; // e.g. 200Response => Model200Response (after camelize)
}
return underscore(name);
}