4848
4949import com .fasterxml .jackson .annotation .JsonView ;
5050import com .fasterxml .jackson .core .JsonProcessingException ;
51- import com .fasterxml .jackson .core .type .TypeReference ;
5251import com .fasterxml .jackson .databind .ObjectMapper ;
5352import com .fasterxml .jackson .dataformat .yaml .YAMLFactory ;
5453import com .fasterxml .jackson .dataformat .yaml .YAMLGenerator .Feature ;
6665import io .swagger .v3 .oas .models .media .StringSchema ;
6766import io .swagger .v3 .oas .models .parameters .Parameter ;
6867import io .swagger .v3 .oas .models .responses .ApiResponses ;
69- import io .swagger .v3 .oas .models .servers .Server ;
7068import org .apache .commons .lang3 .ArrayUtils ;
7169import org .apache .commons .lang3 .StringUtils ;
7270import org .slf4j .Logger ;
8583import org .springdoc .core .customizers .OpenApiCustomiser ;
8684import org .springdoc .core .customizers .OpenApiLocaleCustomizer ;
8785import org .springdoc .core .customizers .OperationCustomizer ;
86+ import org .springdoc .core .customizers .RouterOperationCustomizer ;
8887import org .springdoc .core .filters .OpenApiMethodFilter ;
8988import org .springdoc .core .fn .AbstractRouterFunctionVisitor ;
9089import org .springdoc .core .fn .RouterFunctionData ;
120119 * The type Abstract open api resource.
121120 * @author bnasslahsen
122121 * @author kevinraddatz
122+ * @author hyeonisism
123123 */
124124public abstract class AbstractOpenApiResource extends SpecFilter {
125125
@@ -178,6 +178,11 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
178178 */
179179 private final Optional <List <OperationCustomizer >> operationCustomizers ;
180180
181+ /**
182+ * The RouterOperation customizers.
183+ */
184+ private final Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ;
185+
181186 /**
182187 * The method filters to use.
183188 */
@@ -217,6 +222,7 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
217222 * @param operationParser the operation parser
218223 * @param operationCustomizers the operation customizers
219224 * @param openApiCustomisers the open api customisers
225+ * @param routerOperationCustomizers the router operation customisers
220226 * @param methodFilters the method filters
221227 * @param springDocConfigProperties the spring doc config properties
222228 * @param springDocProviders the spring doc providers
@@ -226,6 +232,7 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
226232 GenericResponseService responseBuilder , OperationService operationParser ,
227233 Optional <List <OperationCustomizer >> operationCustomizers ,
228234 Optional <List <OpenApiCustomiser >> openApiCustomisers ,
235+ Optional <List <RouterOperationCustomizer >> routerOperationCustomizers ,
229236 Optional <List <OpenApiMethodFilter >> methodFilters ,
230237 SpringDocConfigProperties springDocConfigProperties , SpringDocProviders springDocProviders ) {
231238 super ();
@@ -236,6 +243,7 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
236243 this .responseBuilder = responseBuilder ;
237244 this .operationParser = operationParser ;
238245 this .openApiCustomisers = openApiCustomisers ;
246+ this .routerOperationCustomizers = routerOperationCustomizers ;
239247 this .methodFilters = methodFilters ;
240248 this .springDocProviders = springDocProviders ;
241249 //add the default customizers
@@ -368,6 +376,9 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
368376 */
369377 protected void calculatePath (HandlerMethod handlerMethod ,
370378 RouterOperation routerOperation , Locale locale , OpenAPI openAPI ) {
379+
380+ routerOperation = customizeRouterOperation (routerOperation , handlerMethod );
381+
371382 String operationPath = routerOperation .getPath ();
372383 Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
373384 io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -468,7 +479,7 @@ protected void calculatePath(HandlerMethod handlerMethod,
468479 buildCallbacks (openAPI , methodAttributes , operation , apiCallbacks );
469480
470481 // allow for customisation
471- operation = customiseOperation (operation , handlerMethod );
482+ operation = customizeOperation (operation , handlerMethod );
472483
473484 PathItem pathItemObject = buildPathItem (requestMethod , operation , operationPath , paths );
474485 paths .addPathItem (operationPath , pathItemObject );
@@ -595,12 +606,15 @@ protected void calculatePath(RouterOperation routerOperation, Locale locale, Ope
595606 * @param consumes the consumes
596607 * @param produces the produces
597608 * @param headers the headers
609+ * @param params the params
598610 * @param locale the locale
599611 * @param openAPI the open api
600612 */
601613 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 );
604618 }
605619
606620 /**
@@ -781,7 +795,6 @@ public static boolean containsResponseBody(HandlerMethod handlerMethod) {
781795 return responseBodyAnnotation != null ;
782796 }
783797
784-
785798 /**
786799 * Is rest controller boolean.
787800 *
@@ -827,7 +840,7 @@ protected Set<RequestMethod> getDefaultAllowedHttpMethods() {
827840 * @param handlerMethod the handler method
828841 * @return the operation
829842 */
830- protected Operation customiseOperation (Operation operation , HandlerMethod handlerMethod ) {
843+ protected Operation customizeOperation (Operation operation , HandlerMethod handlerMethod ) {
831844 if (operationCustomizers .isPresent ()) {
832845 List <OperationCustomizer > operationCustomizerList = operationCustomizers .get ();
833846 for (OperationCustomizer operationCustomizer : operationCustomizerList )
@@ -836,6 +849,22 @@ protected Operation customiseOperation(Operation operation, HandlerMethod handle
836849 return operation ;
837850 }
838851
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+
839868 /**
840869 * Merge routers.
841870 *
0 commit comments