Skip to content

Commit 8a17560

Browse files
committed
set commonPath only when useTags = true
1 parent 0659b25 commit 8a17560

1 file changed

Lines changed: 20 additions & 32 deletions

File tree

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

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.openapitools.codegen.languages;
1919

2020
import com.google.common.collect.ImmutableMap;
21-
import io.swagger.v3.oas.models.Operation;
2221
import lombok.Getter;
2322
import lombok.Setter;
2423
import org.apache.commons.lang3.StringUtils;
@@ -706,22 +705,29 @@ public void postProcess() {
706705
@Override
707706
public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) {
708707
OperationMap operations = objs.getOperations();
709-
// For JAXRS_SPEC library, compute commonPath similar to JavaJaxRS generators
708+
// For JAXRS_SPEC library, compute commonPath when useTags=true, otherwise default to "/"
710709
if (operations != null && Objects.equals(library, Constants.JAXRS_SPEC)) {
711-
String commonPath = null;
712-
List<CodegenOperation> ops = operations.getOperation();
713-
for (CodegenOperation operation : ops) {
714-
if (commonPath == null) {
715-
commonPath = operation.path;
716-
} else {
717-
commonPath = getCommonPath(commonPath, operation.path);
710+
if (useTags) {
711+
String commonPath = null;
712+
List<CodegenOperation> ops = operations.getOperation();
713+
for (CodegenOperation operation : ops) {
714+
if (commonPath == null) {
715+
commonPath = operation.path;
716+
} else {
717+
commonPath = getCommonPath(commonPath, operation.path);
718+
}
718719
}
720+
for (CodegenOperation co : ops) {
721+
co.path = StringUtils.removeStart(co.path, commonPath);
722+
co.subresourceOperation = co.path.length() > 1;
723+
}
724+
objs.put("commonPath", "/".equals(commonPath) ? StringUtils.EMPTY : commonPath);
725+
} else {
726+
for (CodegenOperation co : operations.getOperation()) {
727+
co.subresourceOperation = !co.path.isEmpty();
728+
}
729+
objs.put("commonPath", "/");
719730
}
720-
for (CodegenOperation co : ops) {
721-
co.path = StringUtils.removeStart(co.path, commonPath);
722-
co.subresourceOperation = co.path.length() > 1;
723-
}
724-
objs.put("commonPath", "/".equals(commonPath) ? StringUtils.EMPTY : commonPath);
725731
}
726732
// The following processing breaks the JAX-RS spec, so we only do this for the other libs.
727733
if (operations != null && !Objects.equals(library, Constants.JAXRS_SPEC)) {
@@ -783,24 +789,6 @@ public void setReturnContainer(final String returnContainer) {
783789
return objs;
784790
}
785791

786-
@Override
787-
public void addOperationToGroup(String tag, String resourcePath, Operation operation, CodegenOperation co, Map<String, List<CodegenOperation>> operations) {
788-
if (Objects.equals(library, Constants.JAXRS_SPEC) && additionalProperties.containsKey(USE_TAGS) && !useTags) {
789-
String basePath = StringUtils.substringBefore(StringUtils.removeStart(resourcePath, "/"), "/");
790-
if (!StringUtils.isEmpty(basePath)) {
791-
co.subresourceOperation = !co.path.isEmpty();
792-
}
793-
co.baseName = basePath;
794-
if (StringUtils.isEmpty(co.baseName) || StringUtils.containsAny(co.baseName, "{", "}")) {
795-
co.baseName = "default";
796-
}
797-
final List<CodegenOperation> opList = operations.computeIfAbsent(co.baseName, k -> new ArrayList<>());
798-
opList.add(co);
799-
} else {
800-
super.addOperationToGroup(tag, resourcePath, operation, co, operations);
801-
}
802-
}
803-
804792
private boolean isJavalin() {
805793
return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library);
806794
}

0 commit comments

Comments
 (0)