|
23 | 23 | import com.samskivert.mustache.Template;
|
24 | 24 | import io.swagger.v3.oas.models.media.ArraySchema;
|
25 | 25 | import io.swagger.v3.oas.models.media.Schema;
|
| 26 | +import org.apache.commons.lang3.StringUtils; |
26 | 27 | import org.openapitools.codegen.*;
|
27 | 28 | import org.openapitools.codegen.meta.features.*;
|
28 | 29 | import org.openapitools.codegen.utils.ModelUtils;
|
|
37 | 38 | import java.util.stream.Collectors;
|
38 | 39 | import java.util.stream.Stream;
|
39 | 40 |
|
| 41 | + |
40 | 42 | import static org.openapitools.codegen.utils.StringUtils.camelize;
|
41 | 43 |
|
42 | 44 | public class ElmClientCodegen extends DefaultCodegen implements CodegenConfig {
|
@@ -174,6 +176,31 @@ public String escapeQuotationMark(String input) {
|
174 | 176 | return input.replace("\"", "");
|
175 | 177 | }
|
176 | 178 |
|
| 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 | + |
177 | 204 | @Override
|
178 | 205 | public String toApiName(String name) {
|
179 | 206 | if (name.length() == 0) {
|
|
0 commit comments