better operation id handling in scala generators (#2490)

This commit is contained in:
William Cheng
2019-03-25 13:13:09 +08:00
committed by GitHub
parent 5074f4d9c5
commit 3e065db2c6
6 changed files with 90 additions and 32 deletions

View File

@@ -333,4 +333,29 @@ public abstract class AbstractScalaCodegen extends DefaultCodegen {
}
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
}
operationId = camelize(sanitizeName(operationId), true);
// method name cannot use reserved keyword, e.g. return
if (isReservedWord(operationId)) {
String newOperationId = camelize("call_" + operationId, true);
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
return newOperationId;
}
// operationId starts with a number
if (operationId.matches("^\\d.*")) {
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
operationId = camelize("call_" + operationId, true);
}
return operationId;
}
}

View File

@@ -235,16 +235,6 @@ public class ScalaAkkaClientCodegen extends AbstractScalaCodegen implements Code
return codegenSecurities;
}
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
return super.toOperationId(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, operationId));
}
@Override
public String toParamName(String name) {
return formatIdentifier(name, false);