Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit e58a514

Browse files
committed
feat:The operationId value in the openapi.json file generated by the openapi plugin remains the same as the default rule of springdoc-openapi
1 parent 11783c0 commit e58a514

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

src/main/java/com/ly/doc/builder/openapi/OpenApiBuilder.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.apache.commons.lang3.StringUtils;
3737

3838
import java.util.*;
39-
import java.util.stream.Collectors;
4039

4140
/**
4241
*
@@ -52,6 +51,11 @@ public class OpenApiBuilder extends AbstractOpenApiBuilder {
5251
*/
5352
private static final OpenApiBuilder INSTANCE = new OpenApiBuilder();
5453

54+
/**
55+
* OperationId OrderNo Map
56+
*/
57+
private static final Map<String, Integer> OPERATIONID_ORDER_NO_MAP = new HashMap<>();
58+
5559
/**
5660
* private constructor
5761
*/
@@ -148,8 +152,19 @@ public Map<String, Object> buildPathUrlsRequest(ApiConfig apiConfig, ApiMethodDo
148152
request.put("deprecated", apiMethodDoc.isDeprecated());
149153
List<String> paths = OpenApiSchemaUtil.getPatternResult("[A-Za-z0-9_{}]*", apiMethodDoc.getPath());
150154
paths.add(apiMethodDoc.getType());
151-
String operationId = paths.stream().filter(StringUtils::isNotEmpty).collect(Collectors.joining("-"));
152-
request.put("operationId", operationId);
155+
156+
// add operationId
157+
String methodName = apiMethodDoc.getMethodName();
158+
if (OPERATIONID_ORDER_NO_MAP.containsKey(methodName)) {
159+
int order = OPERATIONID_ORDER_NO_MAP.get(methodName);
160+
request.put("operationId", methodName + "_" + order);
161+
OPERATIONID_ORDER_NO_MAP.put(methodName, order + 1);
162+
}
163+
else {
164+
request.put("operationId", methodName);
165+
OPERATIONID_ORDER_NO_MAP.put(methodName, 1);
166+
}
167+
153168
// add extension attribution
154169
if (apiMethodDoc.getExtensions() != null) {
155170
apiMethodDoc.getExtensions().forEach((key, value) -> request.put("x-" + key, value));

0 commit comments

Comments
 (0)