6666import org .apache .commons .lang3 .StringUtils ;
6767import org .slf4j .Logger ;
6868import org .slf4j .LoggerFactory ;
69- import org .springdoc .core .AbstractRequestBuilder ;
69+ import org .springdoc .core .AbstractRequestService ;
7070import org .springdoc .core .ActuatorProvider ;
71- import org .springdoc .core .GenericParameterBuilder ;
72- import org .springdoc .core .GenericResponseBuilder ;
71+ import org .springdoc .core .GenericParameterService ;
72+ import org .springdoc .core .GenericResponseService ;
7373import org .springdoc .core .MethodAttributes ;
74- import org .springdoc .core .OpenAPIBuilder ;
75- import org .springdoc .core .OperationBuilder ;
74+ import org .springdoc .core .OpenAPIService ;
75+ import org .springdoc .core .OperationService ;
7676import org .springdoc .core .SpringDocConfigProperties ;
7777import org .springdoc .core .SpringDocConfigProperties .GroupConfig ;
7878import org .springdoc .core .annotations .RouterOperations ;
9393import org .springframework .web .bind .annotation .RequestMethod ;
9494import org .springframework .web .method .HandlerMethod ;
9595
96+ import static org .springdoc .core .Constants .OPERATION_ATTRIBUTE ;
9697import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .isDeprecated ;
9798
9899/**
@@ -119,12 +120,12 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
119120 /**
120121 * The Open api builder.
121122 */
122- protected OpenAPIBuilder openAPIBuilder ;
123+ protected OpenAPIService openAPIService ;
123124
124125 /**
125126 * The open api builder object factory.
126127 */
127- private final ObjectFactory <OpenAPIBuilder > openAPIBuilderObjectFactory ;
128+ private final ObjectFactory <OpenAPIService > openAPIBuilderObjectFactory ;
128129
129130 /**
130131 * The Spring doc config properties.
@@ -139,17 +140,17 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
139140 /**
140141 * The Request builder.
141142 */
142- private final AbstractRequestBuilder requestBuilder ;
143+ private final AbstractRequestService requestBuilder ;
143144
144145 /**
145146 * The Response builder.
146147 */
147- private final GenericResponseBuilder responseBuilder ;
148+ private final GenericResponseService responseBuilder ;
148149
149150 /**
150151 * The Operation parser.
151152 */
152- private final OperationBuilder operationParser ;
153+ private final OperationService operationParser ;
153154
154155 /**
155156 * The Open api customisers.
@@ -184,17 +185,17 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
184185 * @param springDocConfigProperties the spring doc config properties
185186 * @param actuatorProvider the actuator provider
186187 */
187- protected AbstractOpenApiResource (String groupName , ObjectFactory <OpenAPIBuilder > openAPIBuilderObjectFactory ,
188- AbstractRequestBuilder requestBuilder ,
189- GenericResponseBuilder responseBuilder , OperationBuilder operationParser ,
188+ protected AbstractOpenApiResource (String groupName , ObjectFactory <OpenAPIService > openAPIBuilderObjectFactory ,
189+ AbstractRequestService requestBuilder ,
190+ GenericResponseService responseBuilder , OperationService operationParser ,
190191 Optional <List <OperationCustomizer >> operationCustomizers ,
191192 Optional <List <OpenApiCustomiser >> openApiCustomisers ,
192193 SpringDocConfigProperties springDocConfigProperties ,
193194 Optional <ActuatorProvider > actuatorProvider ) {
194195 super ();
195196 this .groupName = Objects .requireNonNull (groupName , "groupName" );
196197 this .openAPIBuilderObjectFactory = openAPIBuilderObjectFactory ;
197- this .openAPIBuilder = openAPIBuilderObjectFactory .getObject ();
198+ this .openAPIService = openAPIBuilderObjectFactory .getObject ();
198199 this .requestBuilder = requestBuilder ;
199200 this .responseBuilder = responseBuilder ;
200201 this .operationParser = operationParser ;
@@ -251,44 +252,44 @@ public static void addHiddenRestControllers(String... classes) {
251252 */
252253 protected synchronized OpenAPI getOpenApi () {
253254 OpenAPI openApi ;
254- if (openAPIBuilder .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
255+ if (openAPIService .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
255256 Instant start = Instant .now ();
256- openAPIBuilder .build ();
257- Map <String , Object > mappingsMap = openAPIBuilder .getMappingsMap ().entrySet ().stream ()
257+ openAPIService .build ();
258+ Map <String , Object > mappingsMap = openAPIService .getMappingsMap ().entrySet ().stream ()
258259 .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
259260 Hidden .class ) == null ))
260261 .filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getClass ()))
261262 .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
262263
263- Map <String , Object > findControllerAdvice = openAPIBuilder .getControllerAdviceMap ();
264+ Map <String , Object > findControllerAdvice = openAPIService .getControllerAdviceMap ();
264265 // calculate generic responses
265- openApi = openAPIBuilder .getCalculatedOpenAPI ();
266+ openApi = openAPIService .getCalculatedOpenAPI ();
266267 if (springDocConfigProperties .isOverrideWithGenericResponse () && !CollectionUtils .isEmpty (findControllerAdvice )) {
267268 if (!CollectionUtils .isEmpty (mappingsMap ))
268269 findControllerAdvice .putAll (mappingsMap );
269270 responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice );
270271 }
271272 getPaths (mappingsMap );
272273 if (!CollectionUtils .isEmpty (openApi .getServers ()))
273- openAPIBuilder .setServersPresent (true );
274- openAPIBuilder .updateServers (openApi );
274+ openAPIService .setServersPresent (true );
275+ openAPIService .updateServers (openApi );
275276
276277 if (springDocConfigProperties .isRemoveBrokenReferenceDefinitions ())
277278 this .removeBrokenReferenceDefinitions (openApi );
278279
279280 // run the optional customisers
280281 openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openApi )));
281282
282- openAPIBuilder .setCachedOpenAPI (openApi );
283- openAPIBuilder .resetCalculatedOpenAPI ();
283+ openAPIService .setCachedOpenAPI (openApi );
284+ openAPIService .resetCalculatedOpenAPI ();
284285
285286 LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
286287 Duration .between (start , Instant .now ()).toMillis ());
287288 }
288289 else {
289- if (!CollectionUtils .isEmpty (openAPIBuilder .getCachedOpenAPI ().getServers ()))
290- openAPIBuilder .setServersPresent (true );
291- openApi = openAPIBuilder .updateServers (openAPIBuilder .getCachedOpenAPI ());
290+ if (!CollectionUtils .isEmpty (openAPIService .getCachedOpenAPI ().getServers ()))
291+ openAPIService .setServersPresent (true );
292+ openApi = openAPIService .updateServers (openAPIService .getCachedOpenAPI ());
292293 }
293294 return openApi ;
294295 }
@@ -315,7 +316,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
315316 String [] headers = routerOperation .getHeaders ();
316317 Map <String , String > queryParams = routerOperation .getQueryParams ();
317318
318- OpenAPI openAPI = openAPIBuilder .getCalculatedOpenAPI ();
319+ OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
319320 Components components = openAPI .getComponents ();
320321 Paths paths = openAPI .getPaths ();
321322
@@ -361,7 +362,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
361362 fillParametersList (operation , queryParams , methodAttributes );
362363
363364 // compute tags
364- operation = openAPIBuilder .buildTags (handlerMethod , operation , openAPI );
365+ operation = openAPIService .buildTags (handlerMethod , operation , openAPI );
365366
366367 io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = AnnotatedElementUtils .findMergedAnnotation (method ,
367368 io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
@@ -411,7 +412,7 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
411412 * @param routerOperationList the router operation list
412413 */
413414 protected void calculatePath (List <RouterOperation > routerOperationList ) {
414- ApplicationContext applicationContext = openAPIBuilder .getContext ();
415+ ApplicationContext applicationContext = openAPIService .getContext ();
415416 if (!CollectionUtils .isEmpty (routerOperationList )) {
416417 Collections .sort (routerOperationList );
417418 for (RouterOperation routerOperation : routerOperationList ) {
@@ -464,7 +465,7 @@ protected void calculatePath(RouterOperation routerOperation) {
464465 String [] headers = routerOperation .getHeaders ();
465466 Map <String , String > queryParams = routerOperation .getQueryParams ();
466467
467- OpenAPI openAPI = openAPIBuilder .getCalculatedOpenAPI ();
468+ OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
468469 Paths paths = openAPI .getPaths ();
469470 Map <HttpMethod , Operation > operationMap = null ;
470471 if (paths .containsKey (operationPath )) {
@@ -515,22 +516,30 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
515516 * @param routerFunctionVisitor the router function visitor
516517 */
517518 protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor ) {
518- List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
519- ApplicationContext applicationContext = openAPIBuilder .getContext ();
520- RouterOperations routerOperations = applicationContext .findAnnotationOnBean (beanName , RouterOperations .class );
521- if (routerOperations == null ) {
522- org .springdoc .core .annotations .RouterOperation routerOperation = applicationContext .findAnnotationOnBean (beanName , org .springdoc .core .annotations .RouterOperation .class );
523- if (routerOperation != null )
524- routerOperationList .add (routerOperation );
519+ boolean withRouterOperation = routerFunctionVisitor .getRouterFunctionDatas ().stream ()
520+ .anyMatch (routerFunctionData -> routerFunctionData .getAttributes ().containsKey (OPERATION_ATTRIBUTE ));
521+ if (withRouterOperation ) {
522+ List <RouterOperation > operationList = routerFunctionVisitor .getRouterFunctionDatas ().stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
523+ calculatePath (operationList );
525524 }
526- else
527- routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
528- if (routerOperationList .size () == 1 )
529- calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()));
530525 else {
531- List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
532- mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
533- calculatePath (operationList );
526+ List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
527+ ApplicationContext applicationContext = openAPIService .getContext ();
528+ RouterOperations routerOperations = applicationContext .findAnnotationOnBean (beanName , RouterOperations .class );
529+ if (routerOperations == null ) {
530+ org .springdoc .core .annotations .RouterOperation routerOperation = applicationContext .findAnnotationOnBean (beanName , org .springdoc .core .annotations .RouterOperation .class );
531+ if (routerOperation != null )
532+ routerOperationList .add (routerOperation );
533+ }
534+ else
535+ routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
536+ if (routerOperationList .size () == 1 )
537+ calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()));
538+ else {
539+ List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
540+ mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
541+ calculatePath (operationList );
542+ }
534543 }
535544 }
536545
@@ -839,7 +848,7 @@ private void fillParametersList(Operation operation, Map<String, String> queryPa
839848 List <Parameter > parametersList = operation .getParameters ();
840849 if (parametersList == null )
841850 parametersList = new ArrayList <>();
842- Collection <Parameter > headersMap = AbstractRequestBuilder .getHeaders (methodAttributes , new LinkedHashMap <>());
851+ Collection <Parameter > headersMap = AbstractRequestService .getHeaders (methodAttributes , new LinkedHashMap <>());
843852 parametersList .addAll (headersMap );
844853 if (!CollectionUtils .isEmpty (queryParams )) {
845854 for (Map .Entry <String , String > entry : queryParams .entrySet ()) {
@@ -848,7 +857,7 @@ private void fillParametersList(Operation operation, Map<String, String> queryPa
848857 parameter .setSchema (new StringSchema ()._default (entry .getValue ()));
849858 parameter .setRequired (true );
850859 parameter .setIn (ParameterIn .QUERY .toString ());
851- GenericParameterBuilder .mergeParameter (parametersList , parameter );
860+ GenericParameterService .mergeParameter (parametersList , parameter );
852861 }
853862 operation .setParameters (parametersList );
854863 }
@@ -992,8 +1001,8 @@ else if (existingOperation != null) {
9921001 * Init open api builder.
9931002 */
9941003 protected void initOpenAPIBuilder () {
995- if (openAPIBuilder .getCachedOpenAPI () != null && springDocConfigProperties .isCacheDisabled ()) {
996- openAPIBuilder = openAPIBuilderObjectFactory .getObject ();
1004+ if (openAPIService .getCachedOpenAPI () != null && springDocConfigProperties .isCacheDisabled ()) {
1005+ openAPIService = openAPIBuilderObjectFactory .getObject ();
9971006 }
9981007 }
9991008
0 commit comments