Skip to content

Several minor fixes in the Go client code generator for Camelization of elements #2289

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public GoClientCodegen() {
"case", "defer", "go", "map", "struct",
"chan", "else", "goto", "package", "switch",
"const", "fallthrough", "if", "range", "type",
"continue", "for", "import", "return", "var")
"continue", "for", "import", "return", "var", "error")
// Added "error" as it's used so frequently that it may as well be a keyword
);

defaultIncludes = new HashSet<String>(
Expand Down Expand Up @@ -131,8 +132,22 @@ public void processOpts() {
}

@Override
public String escapeReservedWord(String name) {
return "_" + name;
public String escapeReservedWord(String name)
{
// Can't start with an underscore, as our fields need to start with an
// UppercaseLetter so that Go treats them as public/visible.

// Options?
// - MyName
// - AName
// - TheName
// - XName
// - X_Name
// ... or maybe a suffix?
// - Name_ ... think this will work.

// FIXME: This should also really be a customizable option
return camelize(name) + '_';
}

@Override
Expand Down Expand Up @@ -166,8 +181,13 @@ public String toVarName(String name) {

@Override
public String toParamName(String name) {
// should be the same as variable name
return toVarName(name);
// params should be lowerCamelCase. E.g. "person Person", instead of
// "Person Person".
//
// REVISIT: Actually, for idiomatic go, the param name should
// really should just be a letter, e.g. "p Person"), but we'll get
// around to that some other time... Maybe.
return camelize(toVarName(name), true);
}

@Override
Expand Down Expand Up @@ -200,7 +220,24 @@ else if (p instanceof MapProperty) {

return getSwaggerType(p) + "[string]" + getTypeDeclaration(inner);
}
return super.getTypeDeclaration(p);
//return super.getTypeDeclaration(p);

// Not using the supertype invocation, because we want to UpperCamelize
// the type.
String swaggerType = getSwaggerType(p);
if (typeMapping.containsKey(swaggerType)) {
return typeMapping.get(swaggerType);
}

if(typeMapping.containsValue(swaggerType)) {
return swaggerType;
}

if(languageSpecificPrimitives.contains(swaggerType)) {
return swaggerType;
}

return camelize(swaggerType, false);
}

@Override
Expand Down