|
18 | 18 | package org.openapitools.codegen.languages; |
19 | 19 |
|
20 | 20 | import com.google.common.collect.ImmutableMap; |
21 | | -import io.swagger.v3.oas.models.Operation; |
22 | 21 | import lombok.Getter; |
23 | 22 | import lombok.Setter; |
24 | 23 | import org.apache.commons.lang3.StringUtils; |
@@ -706,22 +705,29 @@ public void postProcess() { |
706 | 705 | @Override |
707 | 706 | public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<ModelMap> allModels) { |
708 | 707 | 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 "/" |
710 | 709 | 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 | + } |
718 | 719 | } |
| 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", "/"); |
719 | 730 | } |
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 | 731 | } |
726 | 732 | // The following processing breaks the JAX-RS spec, so we only do this for the other libs. |
727 | 733 | if (operations != null && !Objects.equals(library, Constants.JAXRS_SPEC)) { |
@@ -783,24 +789,6 @@ public void setReturnContainer(final String returnContainer) { |
783 | 789 | return objs; |
784 | 790 | } |
785 | 791 |
|
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 | | - |
804 | 792 | private boolean isJavalin() { |
805 | 793 | return Constants.JAVALIN5.equals(library) || Constants.JAVALIN6.equals(library); |
806 | 794 | } |
|
0 commit comments