48
48
49
49
import com .fasterxml .jackson .annotation .JsonView ;
50
50
import com .fasterxml .jackson .core .JsonProcessingException ;
51
- import com .fasterxml .jackson .core .type .TypeReference ;
52
51
import com .fasterxml .jackson .databind .ObjectMapper ;
53
52
import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
54
53
import com .fasterxml .jackson .dataformat .yaml .YAMLGenerator .Feature ;
66
65
import io .swagger .v3 .oas .models .media .StringSchema ;
67
66
import io .swagger .v3 .oas .models .parameters .Parameter ;
68
67
import io .swagger .v3 .oas .models .responses .ApiResponses ;
69
- import io .swagger .v3 .oas .models .servers .Server ;
70
68
import org .apache .commons .lang3 .ArrayUtils ;
71
69
import org .apache .commons .lang3 .StringUtils ;
72
70
import org .slf4j .Logger ;
85
83
import org .springdoc .core .customizers .OpenApiCustomiser ;
86
84
import org .springdoc .core .customizers .OpenApiLocaleCustomizer ;
87
85
import org .springdoc .core .customizers .OperationCustomizer ;
86
+ import org .springdoc .core .customizers .RouterOperationCustomizer ;
88
87
import org .springdoc .core .filters .OpenApiMethodFilter ;
89
88
import org .springdoc .core .fn .AbstractRouterFunctionVisitor ;
90
89
import org .springdoc .core .fn .RouterFunctionData ;
120
119
* The type Abstract open api resource.
121
120
* @author bnasslahsen
122
121
* @author kevinraddatz
122
+ * @author hyeonisism
123
123
*/
124
124
public abstract class AbstractOpenApiResource extends SpecFilter {
125
125
@@ -178,6 +178,11 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
178
178
*/
179
179
private final Optional <List <OperationCustomizer >> operationCustomizers ;
180
180
181
+ /**
182
+ * The RouterOperation customizers.
183
+ */
184
+ private final Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ;
185
+
181
186
/**
182
187
* The method filters to use.
183
188
*/
@@ -217,6 +222,7 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
217
222
* @param operationParser the operation parser
218
223
* @param operationCustomizers the operation customizers
219
224
* @param openApiCustomisers the open api customisers
225
+ * @param routerOperationCustomizers the router operation customisers
220
226
* @param methodFilters the method filters
221
227
* @param springDocConfigProperties the spring doc config properties
222
228
* @param springDocProviders the spring doc providers
@@ -226,6 +232,7 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
226
232
GenericResponseService responseBuilder , OperationService operationParser ,
227
233
Optional <List <OperationCustomizer >> operationCustomizers ,
228
234
Optional <List <OpenApiCustomiser >> openApiCustomisers ,
235
+ Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ,
229
236
Optional <List <OpenApiMethodFilter >> methodFilters ,
230
237
SpringDocConfigProperties springDocConfigProperties , SpringDocProviders springDocProviders ) {
231
238
super ();
@@ -236,6 +243,7 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
236
243
this .responseBuilder = responseBuilder ;
237
244
this .operationParser = operationParser ;
238
245
this .openApiCustomisers = openApiCustomisers ;
246
+ this .routerOperationCustomizers = routerOperationCustomizers ;
239
247
this .methodFilters = methodFilters ;
240
248
this .springDocProviders = springDocProviders ;
241
249
//add the default customizers
@@ -368,6 +376,9 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
368
376
*/
369
377
protected void calculatePath (HandlerMethod handlerMethod ,
370
378
RouterOperation routerOperation , Locale locale , OpenAPI openAPI ) {
379
+
380
+ routerOperation = customizeRouterOperation (routerOperation , handlerMethod );
381
+
371
382
String operationPath = routerOperation .getPath ();
372
383
Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
373
384
io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -468,7 +479,7 @@ protected void calculatePath(HandlerMethod handlerMethod,
468
479
buildCallbacks (openAPI , methodAttributes , operation , apiCallbacks );
469
480
470
481
// allow for customisation
471
- operation = customiseOperation (operation , handlerMethod );
482
+ operation = customizeOperation (operation , handlerMethod );
472
483
473
484
PathItem pathItemObject = buildPathItem (requestMethod , operation , operationPath , paths );
474
485
paths .addPathItem (operationPath , pathItemObject );
@@ -595,12 +606,15 @@ protected void calculatePath(RouterOperation routerOperation, Locale locale, Ope
595
606
* @param consumes the consumes
596
607
* @param produces the produces
597
608
* @param headers the headers
609
+ * @param params the params
598
610
* @param locale the locale
599
611
* @param openAPI the open api
600
612
*/
601
613
protected void calculatePath (HandlerMethod handlerMethod , String operationPath ,
602
- Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , Locale locale , OpenAPI openAPI ) {
603
- this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers ), locale , openAPI );
614
+ Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , String [] params , Locale locale , OpenAPI openAPI ) {
615
+ this .calculatePath (handlerMethod ,
616
+ new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers , params ),
617
+ locale , openAPI );
604
618
}
605
619
606
620
/**
@@ -781,7 +795,6 @@ public static boolean containsResponseBody(HandlerMethod handlerMethod) {
781
795
return responseBodyAnnotation != null ;
782
796
}
783
797
784
-
785
798
/**
786
799
* Is rest controller boolean.
787
800
*
@@ -827,7 +840,7 @@ protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
827
840
* @param handlerMethod the handler method
828
841
* @return the operation
829
842
*/
830
- protected Operation customiseOperation (Operation operation , HandlerMethod handlerMethod ) {
843
+ protected Operation customizeOperation (Operation operation , HandlerMethod handlerMethod ) {
831
844
if (operationCustomizers .isPresent ()) {
832
845
List <OperationCustomizer > operationCustomizerList = operationCustomizers .get ();
833
846
for (OperationCustomizer operationCustomizer : operationCustomizerList )
@@ -836,6 +849,22 @@ protected Operation customiseOperation(Operation operation, HandlerMethod handle
836
849
return operation ;
837
850
}
838
851
852
+ /**
853
+ * Customise router operation
854
+ * @param routerOperation
855
+ * @param handlerMethod
856
+ * @return the router operation
857
+ */
858
+ protected RouterOperation customizeRouterOperation (RouterOperation routerOperation , HandlerMethod handlerMethod ) {
859
+ if (routerOperationCustomizers .isPresent ()) {
860
+ List <RouterOperationCustomizer > routerOperationCustomizerList = routerOperationCustomizers .get ();
861
+ for (RouterOperationCustomizer routerOperationCustomizer : routerOperationCustomizerList ) {
862
+ routerOperation = routerOperationCustomizer .customize (routerOperation , handlerMethod );
863
+ }
864
+ }
865
+ return routerOperation ;
866
+ }
867
+
839
868
/**
840
869
* Merge routers.
841
870
*
0 commit comments