Ruby client: handle empty/reserved operation id

by using a normalized one instead of throwing errors
This commit is contained in:
xhh
2016-02-25 11:48:30 +08:00
parent 484ed848ac
commit 84c6b869f8
3 changed files with 21 additions and 16 deletions

View File

@@ -38,6 +38,7 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String gemAuthor = "";
protected String gemAuthorEmail = "";
protected static int emptyMethodNameCounter = 0;
public RubyClientCodegen() {
super();
@@ -409,14 +410,18 @@ public class RubyClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
// rename to empty_method_name_1 (e.g.) if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
operationId = underscore("empty_method_name_" + emptyMethodNameCounter++);
LOGGER.warn("Empty method name (operationId) found. Renamed to " + operationId);
return operationId;
}
// method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");
String newOperationId = underscore("call_" + operationId);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}
return underscore(sanitizeName(operationId));