18
18
import org .springdoc .core .OperationBuilder ;
19
19
import org .springdoc .core .RequestBodyBuilder ;
20
20
import org .springframework .core .annotation .AnnotationUtils ;
21
+ import org .springframework .util .CollectionUtils ;
21
22
import org .springframework .web .bind .annotation .RequestMapping ;
22
23
import org .springframework .web .bind .annotation .RequestMethod ;
23
24
import org .springframework .web .method .HandlerMethod ;
28
29
import io .swagger .v3 .oas .models .OpenAPI ;
29
30
import io .swagger .v3 .oas .models .Operation ;
30
31
import io .swagger .v3 .oas .models .PathItem ;
32
+ import io .swagger .v3 .oas .models .PathItem .HttpMethod ;
31
33
import io .swagger .v3 .oas .models .Paths ;
32
34
import io .swagger .v3 .oas .models .responses .ApiResponses ;
33
35
@@ -40,6 +42,7 @@ public abstract class AbstractOpenApiResource {
40
42
protected OperationBuilder operationParser ;
41
43
protected RequestBodyBuilder requestBodyBuilder ;
42
44
protected GeneralInfoBuilder generalInfoBuilder ;
45
+ public static boolean methodOverloaded ;
43
46
44
47
protected AbstractOpenApiResource (OpenAPIBuilder openAPIBuilder , AbstractRequestBuilder requestBuilder ,
45
48
AbstractResponseBuilder responseBuilder , OperationBuilder operationParser ,
@@ -81,7 +84,41 @@ protected void calculatePath(OpenAPIBuilder openAPIBuilder, HandlerMethod handle
81
84
Components components = openAPIBuilder .getComponents ();
82
85
Paths paths = openAPIBuilder .getPaths ();
83
86
87
+ Map <HttpMethod , Operation > operationMap = null ;
88
+ if (paths .containsKey (operationPath )) {
89
+ PathItem pathItem = paths .get (operationPath );
90
+ operationMap = pathItem .readOperationsMap ();
91
+ }
92
+
84
93
for (RequestMethod requestMethod : requestMethods ) {
94
+
95
+ Operation existingOperation = null ;
96
+ if (!CollectionUtils .isEmpty (operationMap )) {
97
+ // Get existing operation definition
98
+ if (RequestMethod .GET .equals (requestMethod )) {
99
+ existingOperation = operationMap .get (HttpMethod .GET );
100
+ } else if (RequestMethod .POST .equals (requestMethod )) {
101
+ existingOperation = operationMap .get (HttpMethod .POST );
102
+ } else if (RequestMethod .PUT .equals (requestMethod )) {
103
+ existingOperation = operationMap .get (HttpMethod .PUT );
104
+ } else if (RequestMethod .DELETE .equals (requestMethod )) {
105
+ existingOperation = operationMap .get (HttpMethod .DELETE );
106
+ } else if (RequestMethod .PATCH .equals (requestMethod )) {
107
+ existingOperation = operationMap .get (HttpMethod .PATCH );
108
+ } else if (RequestMethod .TRACE .equals (requestMethod )) {
109
+ existingOperation = operationMap .get (HttpMethod .TRACE );
110
+ } else if (RequestMethod .HEAD .equals (requestMethod )) {
111
+ existingOperation = operationMap .get (HttpMethod .HEAD );
112
+ } else if (RequestMethod .OPTIONS .equals (requestMethod )) {
113
+ existingOperation = operationMap .get (HttpMethod .OPTIONS );
114
+ }
115
+ }
116
+
117
+ if (existingOperation != null ) {
118
+ methodOverloaded = true ;
119
+ }
120
+ else
121
+ methodOverloaded = false ;
85
122
// skip hidden operations
86
123
if (operationParser .isHidden (handlerMethod .getMethod ())) {
87
124
continue ;
@@ -98,7 +135,7 @@ protected void calculatePath(OpenAPIBuilder openAPIBuilder, HandlerMethod handle
98
135
99
136
mediaAttributes .calculateConsumesProduces (handlerMethod .getMethod ());
100
137
101
- Operation operation = new Operation ();
138
+ Operation operation = ( existingOperation != null ) ? existingOperation : new Operation ();
102
139
103
140
// compute tags
104
141
operation = generalInfoBuilder .buildTags (handlerMethod , operation , openAPI );
0 commit comments