add better reserved keyword handling for c#

This commit is contained in:
wing328
2016-02-25 15:35:05 +08:00
parent a351724365
commit 329223f364
6 changed files with 37 additions and 35 deletions

View File

@@ -276,14 +276,15 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
@Override
public String toOperationId(String operationId) {
// throw exception if method name is empty
// throw exception if method name is empty (should not occur as an auto-generated method name will be used)
if (StringUtils.isEmpty(operationId)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// 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");
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + camelize(sanitizeName("call_" + operationId)));
operationId = "call_" + operationId;
}
return camelize(sanitizeName(operationId));
@@ -471,7 +472,8 @@ public abstract class AbstractCSharpCodegen extends DefaultCodegen implements Co
// model name cannot use reserved keyword, e.g. return
if (reservedWords.contains(name)) {
throw new RuntimeException(name + " (reserved word) cannot be used as a model name");
LOGGER.warn(name + " (reserved word) cannot be used as model name. Renamed to " + camelize("object_" + name));
name = "object_" + name; // e.g. return => ObjectReturn (after camelize)
}
// camelize the model name