Merge pull request #2655 from kolyjjj/issue2621

include underscore when generating nodejs controller and service method
This commit is contained in:
wing328 2016-04-21 23:35:17 +08:00
commit b847838a0c
2 changed files with 21 additions and 5 deletions

View File

@ -2319,18 +2319,28 @@ public class DefaultCodegen {
*/
@SuppressWarnings("static-method")
public String removeNonNameElementToCamelCase(String name) {
String nonNameElementPattern = "[-_:;#]";
name = StringUtils.join(Lists.transform(Lists.newArrayList(name.split(nonNameElementPattern)), new Function<String, String>() { // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
return removeNonNameElementToCamelCase(name, "[-_:;#]");
}
/**
* Remove characters that is not good to be included in method name from the input and camelize it
*
* @param name string to be camelize
* @param nonNameElementPattern a regex pattern of the characters that is not good to be included in name
* @return camelized string
*/
protected String removeNonNameElementToCamelCase(final String name, final String nonNameElementPattern) {
String result = StringUtils.join(Lists.transform(Lists.newArrayList(name.split(nonNameElementPattern)), new Function<String, String>() {
@Nullable
@Override
public String apply(String input) {
return StringUtils.capitalize(input);
}
}), "");
if (name.length() > 0) {
name = name.substring(0, 1).toLowerCase() + name.substring(1);
if (result.length() > 0) {
result = result.substring(0, 1).toLowerCase() + result.substring(1);
}
return name;
return result;
}
/**

View File

@ -314,4 +314,10 @@ public class NodeJSServerCodegen extends DefaultCodegen implements CodegenConfig
}
return super.postProcessSupportingFileData(objs);
}
@Override
public String removeNonNameElementToCamelCase(String name) {
return removeNonNameElementToCamelCase(name, "[-:;#]");
}
}