forked from loafle/openapi-generator-original
Ruby client: handle empty/reserved operation id
by using a normalized one instead of throwing errors
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user