Skip to content

Commit ed72843

Browse files
authored
better operationId in elm client generator (#8109)
1 parent e732804 commit ed72843

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/ElmClientCodegen.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.samskivert.mustache.Template;
2424
import io.swagger.v3.oas.models.media.ArraySchema;
2525
import io.swagger.v3.oas.models.media.Schema;
26+
import org.apache.commons.lang3.StringUtils;
2627
import org.openapitools.codegen.*;
2728
import org.openapitools.codegen.meta.features.*;
2829
import org.openapitools.codegen.utils.ModelUtils;
@@ -37,6 +38,7 @@
3738
import java.util.stream.Collectors;
3839
import java.util.stream.Stream;
3940

41+
4042
import static org.openapitools.codegen.utils.StringUtils.camelize;
4143

4244
public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
@@ -174,6 +176,31 @@ public String escapeQuotationMark(String input) {
174176
return input.replace("\"", "");
175177
}
176178

179+
@Override
180+
public String toOperationId(String operationId) {
181+
// throw exception if method name is empty
182+
if (StringUtils.isEmpty(operationId)) {
183+
throw new RuntimeException("Empty method/operation name (operationId) not allowed");
184+
}
185+
186+
operationId = camelize(sanitizeName(operationId), true);
187+
188+
// method name cannot use reserved keyword, e.g. return
189+
if (isReservedWord(operationId)) {
190+
String newOperationId = camelize("call_" + operationId, true);
191+
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + newOperationId);
192+
return newOperationId;
193+
}
194+
195+
// operationId starts with a number
196+
if (operationId.matches("^\\d.*")) {
197+
LOGGER.warn(operationId + " (starting with a number) cannot be used as method sname. Renamed to " + camelize("call_" + operationId), true);
198+
operationId = camelize("call_" + operationId, true);
199+
}
200+
201+
return operationId;
202+
}
203+
177204
@Override
178205
public String toApiName(String name) {
179206
if (name.length() == 0) {

0 commit comments

Comments
 (0)