fix empty operationId in java codegen

This commit is contained in:
wing328 2015-07-27 11:39:37 +08:00
parent d0baa48fcd
commit a8f580032f
2 changed files with 10 additions and 6 deletions

View File

@ -1216,7 +1216,9 @@ public class DefaultCodegen {
if (mappedType != null) { if (mappedType != null) {
addImport(m, mappedType); addImport(m, mappedType);
} }
} /** }
/**
* Underscore the given word. * Underscore the given word.
* *
* @param word The word * @param word The word
@ -1307,11 +1309,6 @@ public class DefaultCodegen {
} }
public static String camelize(String word, boolean lowercaseFirstLetter) { public static String camelize(String word, boolean lowercaseFirstLetter) {
// throw exception if method name is empty
if (StringUtils.isEmpty(word)) {
throw new RuntimeException("Empty method name (operationId) not allowed");
}
// Replace all slashes with dots (package separator) // Replace all slashes with dots (package separator)
Pattern p = Pattern.compile("\\/(.?)"); Pattern p = Pattern.compile("\\/(.?)");
Matcher m = p.matcher(word); Matcher m = p.matcher(word);

View File

@ -13,6 +13,8 @@ import java.io.File;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import org.apache.commons.lang.StringUtils;
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig { public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
protected String invokerPackage = "io.swagger.client"; protected String invokerPackage = "io.swagger.client";
protected String groupId = "io.swagger"; protected String groupId = "io.swagger";
@ -234,6 +236,11 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
@Override @Override
public String toOperationId(String operationId) { 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");
}
// method name cannot use reserved keyword, e.g. return // method name cannot use reserved keyword, e.g. return
if (reservedWords.contains(operationId)) { if (reservedWords.contains(operationId)) {
throw new RuntimeException(operationId + " (reserved word) cannot be used as method name"); throw new RuntimeException(operationId + " (reserved word) cannot be used as method name");