Skip to content

Commit 8c51a1c

Browse files
committed
extract regex to reusable Pattern
1 parent 10b6ab9 commit 8c51a1c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.List;
3737
import java.util.Map;
3838
import java.util.function.Predicate;
39+
import java.util.regex.Pattern;
3940
import java.util.stream.Collectors;
4041
import java.util.stream.Stream;
4142

@@ -115,6 +116,7 @@ public class KotlinClientCodegen extends AbstractKotlinCodegen {
115116
public static final String COMPANION_OBJECT = "companionObject";
116117

117118
protected static final String VENDOR_EXTENSION_BASE_NAME_LITERAL = "x-base-name-literal";
119+
private static final Pattern RETROFIT_PATH_PARAM_NAME_PATTERN = Pattern.compile("[a-zA-Z][a-zA-Z0-9_-]*");
118120

119121

120122
@Setter protected String dateLibrary = DateLibrary.JAVA8.value;
@@ -1068,7 +1070,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
10681070
if (JVM_RETROFIT2.equals(getLibrary())) {
10691071
for (CodegenParameter param : operation.allParams) {
10701072
if (param.isPathParam) {
1071-
boolean validRetrofitName = param.baseName.matches("[a-zA-Z][a-zA-Z0-9_-]*");
1073+
boolean validRetrofitName = RETROFIT_PATH_PARAM_NAME_PATTERN.matcher(param.baseName).matches();
10721074
if (validRetrofitName) {
10731075
param.vendorExtensions.put("x-retrofit-path-name", param.baseName);
10741076
} else {

0 commit comments

Comments
 (0)