21
21
* * * *
22
22
* * *
23
23
* *
24
- *
24
+ *
25
25
*/
26
26
27
27
package org .springdoc .core .customizers ;
31
31
32
32
import io .swagger .v3 .core .util .AnnotationsUtils ;
33
33
import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
34
+ import io .swagger .v3 .oas .models .Components ;
34
35
import io .swagger .v3 .oas .models .Operation ;
35
36
import io .swagger .v3 .oas .models .media .Content ;
36
37
import io .swagger .v3 .oas .models .media .MediaType ;
61
62
*
62
63
* @author bnasslahsen
63
64
*/
64
- public class ActuatorOperationCustomizer implements GlobalOperationCustomizer {
65
+ public class ActuatorOperationCustomizer implements GlobalOperationComponentsCustomizer {
65
66
66
67
/**
67
68
* The constant OPERATION.
@@ -94,11 +95,11 @@ public ActuatorOperationCustomizer(SpringDocConfigProperties springDocConfigProp
94
95
}
95
96
96
97
@ Override
97
- public Operation customize (Operation operation , HandlerMethod handlerMethod ) {
98
+ public Operation customize (Operation operation , Components components , HandlerMethod handlerMethod ) {
98
99
if (operationHasValidTag (operation )) {
99
100
Field operationField = FieldUtils .getDeclaredField (handlerMethod .getBean ().getClass (), OPERATION ,true );
100
101
if (operationField != null ) {
101
- processOperationField (handlerMethod , operation , operationField );
102
+ processOperationField (handlerMethod , operation , components , operationField );
102
103
}
103
104
setOperationSummary (operation , handlerMethod );
104
105
}
@@ -120,16 +121,17 @@ private boolean operationHasValidTag(Operation operation) {
120
121
*
121
122
* @param handlerMethod the handler method
122
123
* @param operation the operation
124
+ * @param components the components
123
125
* @param operationField the operation field
124
126
*/
125
- private void processOperationField (HandlerMethod handlerMethod , Operation operation , Field operationField ) {
127
+ private void processOperationField (HandlerMethod handlerMethod , Operation operation , Components components , Field operationField ) {
126
128
try {
127
129
Object actuatorOperation = operationField .get (handlerMethod .getBean ());
128
130
Field actuatorOperationField = FieldUtils .getDeclaredField (actuatorOperation .getClass (), OPERATION , true );
129
131
if (actuatorOperationField != null ) {
130
132
AbstractDiscoveredOperation discoveredOperation =
131
133
(AbstractDiscoveredOperation ) actuatorOperationField .get (actuatorOperation );
132
- handleOperationMethod (discoveredOperation .getOperationMethod (), operation );
134
+ handleOperationMethod (discoveredOperation .getOperationMethod (), components , operation );
133
135
}
134
136
}
135
137
catch (IllegalAccessException e ) {
@@ -141,25 +143,26 @@ private void processOperationField(HandlerMethod handlerMethod, Operation operat
141
143
* Handle operation method.
142
144
*
143
145
* @param operationMethod the operation method
146
+ * @param components the components
144
147
* @param operation the operation
145
148
*/
146
- private void handleOperationMethod (OperationMethod operationMethod , Operation operation ) {
149
+ private void handleOperationMethod (OperationMethod operationMethod , Components components , Operation operation ) {
147
150
String operationId = operationMethod .getMethod ().getName ();
148
151
operation .setOperationId (operationId );
149
152
150
153
switch (operationMethod .getOperationType ()) {
151
154
case READ :
152
- addParameters (operationMethod , operation , ParameterIn .QUERY );
155
+ addParameters (operationMethod , operation , components , ParameterIn .QUERY );
153
156
break ;
154
157
case WRITE :
155
- addWriteParameters (operationMethod , operation );
158
+ addWriteParameters (operationMethod ,components , operation );
156
159
operation .setResponses (new ApiResponses ()
157
160
.addApiResponse (String .valueOf (HttpStatus .NO_CONTENT .value ()), new ApiResponse ().description (HttpStatus .NO_CONTENT .getReasonPhrase ()))
158
161
.addApiResponse (String .valueOf (HttpStatus .BAD_REQUEST .value ()), new ApiResponse ().description (HttpStatus .BAD_REQUEST .getReasonPhrase ())));
159
162
break ;
160
163
case DELETE :
161
164
operation .setResponses (new ApiResponses ().addApiResponse (String .valueOf (HttpStatus .NO_CONTENT .value ()), new ApiResponse ().description (HttpStatus .NO_CONTENT .getReasonPhrase ())));
162
- addParameters (operationMethod , operation , ParameterIn .QUERY );
165
+ addParameters (operationMethod , operation , components , ParameterIn .QUERY );
163
166
break ;
164
167
default :
165
168
break ;
@@ -171,13 +174,14 @@ private void handleOperationMethod(OperationMethod operationMethod, Operation op
171
174
*
172
175
* @param operationMethod the operation method
173
176
* @param operation the operation
177
+ * @param components the components
174
178
* @param parameterIn the parameter in
175
179
*/
176
- private void addParameters (OperationMethod operationMethod , Operation operation , ParameterIn parameterIn ) {
180
+ private void addParameters (OperationMethod operationMethod , Operation operation , Components components , ParameterIn parameterIn ) {
177
181
for (OperationParameter operationParameter : operationMethod .getParameters ()) {
178
182
Parameter parameter = getParameterFromField (operationParameter );
179
183
if (parameter == null ) continue ;
180
- Schema <?> schema = resolveSchema (parameter );
184
+ Schema <?> schema = resolveSchema (parameter , components );
181
185
if (parameter .getAnnotation (Selector .class ) != null ) {
182
186
operation .addParametersItem (new io .swagger .v3 .oas .models .parameters .PathParameter ()
183
187
.name (parameter .getName ())
@@ -197,13 +201,14 @@ else if (isValidParameterType(parameter)) {
197
201
* Add write parameters.
198
202
*
199
203
* @param operationMethod the operation method
204
+ * @param components the components
200
205
* @param operation the operation
201
206
*/
202
- private void addWriteParameters (OperationMethod operationMethod , Operation operation ) {
207
+ private void addWriteParameters (OperationMethod operationMethod , Components components , Operation operation ) {
203
208
for (OperationParameter operationParameter : operationMethod .getParameters ()) {
204
209
Parameter parameter = getParameterFromField (operationParameter );
205
210
if (parameter == null ) continue ;
206
- Schema <?> schema = resolveSchema (parameter );
211
+ Schema <?> schema = resolveSchema (parameter , components );
207
212
if (parameter .getAnnotation (Selector .class ) != null ) {
208
213
operation .addParametersItem (new io .swagger .v3 .oas .models .parameters .PathParameter ()
209
214
.name (parameter .getName ())
@@ -237,11 +242,12 @@ private Parameter getParameterFromField(OperationParameter operationParameter) {
237
242
/**
238
243
* Resolve schema schema.
239
244
*
240
- * @param parameter the parameter
245
+ * @param parameter the parameter
246
+ * @param components
241
247
* @return the schema
242
248
*/
243
- private Schema <?> resolveSchema (Parameter parameter ) {
244
- Schema schema = AnnotationsUtils .resolveSchemaFromType (parameter .getType (), null , null , springDocConfigProperties .isOpenapi31 ());
249
+ private Schema <?> resolveSchema (Parameter parameter , Components components ) {
250
+ Schema schema = AnnotationsUtils .resolveSchemaFromType (parameter .getType (), components , null , springDocConfigProperties .isOpenapi31 ());
245
251
if (springDocConfigProperties .isOpenapi31 ()) handleSchemaTypes (schema );
246
252
return schema ;
247
253
}
@@ -271,4 +277,8 @@ private void setOperationSummary(Operation operation, HandlerMethod handlerMetho
271
277
}
272
278
}
273
279
280
+ @ Override
281
+ public Operation customize (Operation operation , HandlerMethod handlerMethod ) {
282
+ return this .customize (operation , null , handlerMethod );
283
+ }
274
284
}
0 commit comments