66
66
import org .apache .commons .lang3 .StringUtils ;
67
67
import org .slf4j .Logger ;
68
68
import org .slf4j .LoggerFactory ;
69
- import org .springdoc .core .AbstractRequestBuilder ;
69
+ import org .springdoc .core .AbstractRequestService ;
70
70
import 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 ;
73
73
import 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 ;
76
76
import org .springdoc .core .SpringDocConfigProperties ;
77
77
import org .springdoc .core .SpringDocConfigProperties .GroupConfig ;
78
78
import org .springdoc .core .annotations .RouterOperations ;
93
93
import org .springframework .web .bind .annotation .RequestMethod ;
94
94
import org .springframework .web .method .HandlerMethod ;
95
95
96
+ import static org .springdoc .core .Constants .OPERATION_ATTRIBUTE ;
96
97
import static org .springdoc .core .converters .SchemaPropertyDeprecatingConverter .isDeprecated ;
97
98
98
99
/**
@@ -119,12 +120,12 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
119
120
/**
120
121
* The Open api builder.
121
122
*/
122
- protected OpenAPIBuilder openAPIBuilder ;
123
+ protected OpenAPIService openAPIService ;
123
124
124
125
/**
125
126
* The open api builder object factory.
126
127
*/
127
- private final ObjectFactory <OpenAPIBuilder > openAPIBuilderObjectFactory ;
128
+ private final ObjectFactory <OpenAPIService > openAPIBuilderObjectFactory ;
128
129
129
130
/**
130
131
* The Spring doc config properties.
@@ -139,17 +140,17 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
139
140
/**
140
141
* The Request builder.
141
142
*/
142
- private final AbstractRequestBuilder requestBuilder ;
143
+ private final AbstractRequestService requestBuilder ;
143
144
144
145
/**
145
146
* The Response builder.
146
147
*/
147
- private final GenericResponseBuilder responseBuilder ;
148
+ private final GenericResponseService responseBuilder ;
148
149
149
150
/**
150
151
* The Operation parser.
151
152
*/
152
- private final OperationBuilder operationParser ;
153
+ private final OperationService operationParser ;
153
154
154
155
/**
155
156
* The Open api customisers.
@@ -184,17 +185,17 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
184
185
* @param springDocConfigProperties the spring doc config properties
185
186
* @param actuatorProvider the actuator provider
186
187
*/
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 ,
190
191
Optional <List <OperationCustomizer >> operationCustomizers ,
191
192
Optional <List <OpenApiCustomiser >> openApiCustomisers ,
192
193
SpringDocConfigProperties springDocConfigProperties ,
193
194
Optional <ActuatorProvider > actuatorProvider ) {
194
195
super ();
195
196
this .groupName = Objects .requireNonNull (groupName , "groupName" );
196
197
this .openAPIBuilderObjectFactory = openAPIBuilderObjectFactory ;
197
- this .openAPIBuilder = openAPIBuilderObjectFactory .getObject ();
198
+ this .openAPIService = openAPIBuilderObjectFactory .getObject ();
198
199
this .requestBuilder = requestBuilder ;
199
200
this .responseBuilder = responseBuilder ;
200
201
this .operationParser = operationParser ;
@@ -251,44 +252,44 @@ public static void addHiddenRestControllers(String... classes) {
251
252
*/
252
253
protected synchronized OpenAPI getOpenApi () {
253
254
OpenAPI openApi ;
254
- if (openAPIBuilder .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
255
+ if (openAPIService .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
255
256
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 ()
258
259
.filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
259
260
Hidden .class ) == null ))
260
261
.filter (controller -> !AbstractOpenApiResource .isHiddenRestControllers (controller .getValue ().getClass ()))
261
262
.collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (a1 , a2 ) -> a1 ));
262
263
263
- Map <String , Object > findControllerAdvice = openAPIBuilder .getControllerAdviceMap ();
264
+ Map <String , Object > findControllerAdvice = openAPIService .getControllerAdviceMap ();
264
265
// calculate generic responses
265
- openApi = openAPIBuilder .getCalculatedOpenAPI ();
266
+ openApi = openAPIService .getCalculatedOpenAPI ();
266
267
if (springDocConfigProperties .isOverrideWithGenericResponse () && !CollectionUtils .isEmpty (findControllerAdvice )) {
267
268
if (!CollectionUtils .isEmpty (mappingsMap ))
268
269
findControllerAdvice .putAll (mappingsMap );
269
270
responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice );
270
271
}
271
272
getPaths (mappingsMap );
272
273
if (!CollectionUtils .isEmpty (openApi .getServers ()))
273
- openAPIBuilder .setServersPresent (true );
274
- openAPIBuilder .updateServers (openApi );
274
+ openAPIService .setServersPresent (true );
275
+ openAPIService .updateServers (openApi );
275
276
276
277
if (springDocConfigProperties .isRemoveBrokenReferenceDefinitions ())
277
278
this .removeBrokenReferenceDefinitions (openApi );
278
279
279
280
// run the optional customisers
280
281
openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openApi )));
281
282
282
- openAPIBuilder .setCachedOpenAPI (openApi );
283
- openAPIBuilder .resetCalculatedOpenAPI ();
283
+ openAPIService .setCachedOpenAPI (openApi );
284
+ openAPIService .resetCalculatedOpenAPI ();
284
285
285
286
LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
286
287
Duration .between (start , Instant .now ()).toMillis ());
287
288
}
288
289
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 ());
292
293
}
293
294
return openApi ;
294
295
}
@@ -315,7 +316,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
315
316
String [] headers = routerOperation .getHeaders ();
316
317
Map <String , String > queryParams = routerOperation .getQueryParams ();
317
318
318
- OpenAPI openAPI = openAPIBuilder .getCalculatedOpenAPI ();
319
+ OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
319
320
Components components = openAPI .getComponents ();
320
321
Paths paths = openAPI .getPaths ();
321
322
@@ -361,7 +362,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
361
362
fillParametersList (operation , queryParams , methodAttributes );
362
363
363
364
// compute tags
364
- operation = openAPIBuilder .buildTags (handlerMethod , operation , openAPI );
365
+ operation = openAPIService .buildTags (handlerMethod , operation , openAPI );
365
366
366
367
io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = AnnotatedElementUtils .findMergedAnnotation (method ,
367
368
io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
@@ -411,7 +412,7 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
411
412
* @param routerOperationList the router operation list
412
413
*/
413
414
protected void calculatePath (List <RouterOperation > routerOperationList ) {
414
- ApplicationContext applicationContext = openAPIBuilder .getContext ();
415
+ ApplicationContext applicationContext = openAPIService .getContext ();
415
416
if (!CollectionUtils .isEmpty (routerOperationList )) {
416
417
Collections .sort (routerOperationList );
417
418
for (RouterOperation routerOperation : routerOperationList ) {
@@ -464,7 +465,7 @@ protected void calculatePath(RouterOperation routerOperation) {
464
465
String [] headers = routerOperation .getHeaders ();
465
466
Map <String , String > queryParams = routerOperation .getQueryParams ();
466
467
467
- OpenAPI openAPI = openAPIBuilder .getCalculatedOpenAPI ();
468
+ OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
468
469
Paths paths = openAPI .getPaths ();
469
470
Map <HttpMethod , Operation > operationMap = null ;
470
471
if (paths .containsKey (operationPath )) {
@@ -515,22 +516,30 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
515
516
* @param routerFunctionVisitor the router function visitor
516
517
*/
517
518
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 );
525
524
}
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 ()));
530
525
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
+ }
534
543
}
535
544
}
536
545
@@ -839,7 +848,7 @@ private void fillParametersList(Operation operation, Map<String, String> queryPa
839
848
List <Parameter > parametersList = operation .getParameters ();
840
849
if (parametersList == null )
841
850
parametersList = new ArrayList <>();
842
- Collection <Parameter > headersMap = AbstractRequestBuilder .getHeaders (methodAttributes , new LinkedHashMap <>());
851
+ Collection <Parameter > headersMap = AbstractRequestService .getHeaders (methodAttributes , new LinkedHashMap <>());
843
852
parametersList .addAll (headersMap );
844
853
if (!CollectionUtils .isEmpty (queryParams )) {
845
854
for (Map .Entry <String , String > entry : queryParams .entrySet ()) {
@@ -848,7 +857,7 @@ private void fillParametersList(Operation operation, Map<String, String> queryPa
848
857
parameter .setSchema (new StringSchema ()._default (entry .getValue ()));
849
858
parameter .setRequired (true );
850
859
parameter .setIn (ParameterIn .QUERY .toString ());
851
- GenericParameterBuilder .mergeParameter (parametersList , parameter );
860
+ GenericParameterService .mergeParameter (parametersList , parameter );
852
861
}
853
862
operation .setParameters (parametersList );
854
863
}
@@ -992,8 +1001,8 @@ else if (existingOperation != null) {
992
1001
* Init open api builder.
993
1002
*/
994
1003
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 ();
997
1006
}
998
1007
}
999
1008
0 commit comments