@@ -136,12 +136,12 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
136
136
/**
137
137
* The constant ADDITIONAL_REST_CONTROLLERS.
138
138
*/
139
- private static final List <Class <?>> ADDITIONAL_REST_CONTROLLERS = new ArrayList <>();
139
+ private static final List <Class <?>> ADDITIONAL_REST_CONTROLLERS = Collections . synchronizedList ( new ArrayList <>() );
140
140
141
141
/**
142
142
* The constant HIDDEN_REST_CONTROLLERS.
143
143
*/
144
- private static final List <Class <?>> HIDDEN_REST_CONTROLLERS = new ArrayList <>();
144
+ private static final List <Class <?>> HIDDEN_REST_CONTROLLERS = Collections . synchronizedList ( new ArrayList <>() );
145
145
146
146
/**
147
147
* The Open api builder.
@@ -304,7 +304,7 @@ public static void addHiddenRestControllers(String... classes) {
304
304
* @return the open api
305
305
*/
306
306
protected synchronized OpenAPI getOpenApi (Locale locale ) {
307
- OpenAPI openApi ;
307
+ OpenAPI openAPI ;
308
308
final Locale finalLocale = locale == null ? Locale .getDefault () : locale ;
309
309
if (openAPIService .getCachedOpenAPI (finalLocale ) == null || springDocConfigProperties .isCacheDisabled ()) {
310
310
Instant start = Instant .now ();
@@ -317,33 +317,33 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
317
317
318
318
Map <String , Object > findControllerAdvice = openAPIService .getControllerAdviceMap ();
319
319
// calculate generic responses
320
- openApi = openAPIService .getCalculatedOpenAPI ();
320
+ openAPI = openAPIService .getCalculatedOpenAPI ();
321
321
if (OpenApiVersion .OPENAPI_3_1 == springDocConfigProperties .getApiDocs ().getVersion ())
322
- openApi .openapi (OpenApiVersion .OPENAPI_3_1 .getVersion ());
322
+ openAPI .openapi (OpenApiVersion .OPENAPI_3_1 .getVersion ());
323
323
if (springDocConfigProperties .isDefaultOverrideWithGenericResponse ()) {
324
324
if (!CollectionUtils .isEmpty (mappingsMap ))
325
325
findControllerAdvice .putAll (mappingsMap );
326
- responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , finalLocale );
326
+ responseBuilder .buildGenericResponse (openAPI .getComponents (), findControllerAdvice , finalLocale );
327
327
}
328
- getPaths (mappingsMap , finalLocale );
328
+ getPaths (mappingsMap , finalLocale , openAPI );
329
329
330
330
Optional <CloudFunctionProvider > cloudFunctionProviderOptional = springDocProviders .getSpringCloudFunctionProvider ();
331
331
cloudFunctionProviderOptional .ifPresent (cloudFunctionProvider -> {
332
- List <RouterOperation > routerOperationList = cloudFunctionProvider .getRouterOperations (openApi );
332
+ List <RouterOperation > routerOperationList = cloudFunctionProvider .getRouterOperations (openAPI );
333
333
if (!CollectionUtils .isEmpty (routerOperationList ))
334
- this .calculatePath (routerOperationList , locale );
334
+ this .calculatePath (routerOperationList , locale , openAPI );
335
335
}
336
336
);
337
337
338
- if (!CollectionUtils .isEmpty (openApi .getServers ()))
338
+ if (!CollectionUtils .isEmpty (openAPI .getServers ()))
339
339
openAPIService .setServersPresent (true );
340
- openAPIService .updateServers (openApi );
340
+ openAPIService .updateServers (openAPI );
341
341
342
342
if (springDocConfigProperties .isRemoveBrokenReferenceDefinitions ())
343
- this .removeBrokenReferenceDefinitions (openApi );
343
+ this .removeBrokenReferenceDefinitions (openAPI );
344
344
345
345
// run the optional customisers
346
- List <Server > servers = openApi .getServers ();
346
+ List <Server > servers = openAPI .getServers ();
347
347
List <Server > serversCopy = null ;
348
348
try {
349
349
serversCopy = springDocProviders .jsonMapper ()
@@ -353,40 +353,43 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
353
353
LOGGER .warn ("Json Processing Exception occurred: {}" , e .getMessage ());
354
354
}
355
355
356
- openApiLocaleCustomizers .values ().forEach (openApiLocaleCustomizer -> openApiLocaleCustomizer .customise (openApi , finalLocale ));
357
- openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openApi )));
358
- if (!CollectionUtils .isEmpty (openApi .getServers ()) && !openApi .getServers ().equals (serversCopy ))
356
+ openApiLocaleCustomizers .values ().forEach (openApiLocaleCustomizer -> openApiLocaleCustomizer .customise (openAPI , finalLocale ));
357
+ openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openAPI )));
358
+ if (!CollectionUtils .isEmpty (openAPI .getServers ()) && !openAPI .getServers ().equals (serversCopy ))
359
359
openAPIService .setServersPresent (true );
360
360
361
- openAPIService .setCachedOpenAPI (openApi , finalLocale );
361
+ openAPIService .setCachedOpenAPI (openAPI , finalLocale );
362
362
openAPIService .resetCalculatedOpenAPI ();
363
363
364
364
LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
365
365
Duration .between (start , Instant .now ()).toMillis ());
366
366
}
367
367
else {
368
368
LOGGER .debug ("Fetching openApi document from cache" );
369
- openApi = openAPIService .updateServers (openAPIService .getCachedOpenAPI (finalLocale ));
369
+ openAPI = openAPIService .updateServers (openAPIService .getCachedOpenAPI (finalLocale ));
370
370
}
371
- return openApi ;
371
+ return openAPI ;
372
372
}
373
373
374
374
/**
375
375
* Gets paths.
376
376
*
377
377
* @param findRestControllers the find rest controllers
378
378
* @param locale the locale
379
+ * @param openAPI the open api
379
380
*/
380
- protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale );
381
+ protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale , OpenAPI openAPI );
381
382
382
383
/**
383
384
* Calculate path.
384
385
*
385
386
* @param handlerMethod the handler method
386
387
* @param routerOperation the router operation
387
388
* @param locale the locale
389
+ * @param openAPI the open api
388
390
*/
389
- protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation , Locale locale ) {
391
+ protected void calculatePath (HandlerMethod handlerMethod ,
392
+ RouterOperation routerOperation , Locale locale , OpenAPI openAPI ) {
390
393
String operationPath = routerOperation .getPath ();
391
394
Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
392
395
io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -395,7 +398,6 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
395
398
String [] headers = routerOperation .getHeaders ();
396
399
Map <String , String > queryParams = routerOperation .getQueryParams ();
397
400
398
- OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
399
401
Components components = openAPI .getComponents ();
400
402
Paths paths = openAPI .getPaths ();
401
403
@@ -514,8 +516,9 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
514
516
*
515
517
* @param routerOperationList the router operation list
516
518
* @param locale the locale
519
+ * @param openAPI the open api
517
520
*/
518
- protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale ) {
521
+ protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale , OpenAPI openAPI ) {
519
522
ApplicationContext applicationContext = openAPIService .getContext ();
520
523
if (!CollectionUtils .isEmpty (routerOperationList )) {
521
524
Collections .sort (routerOperationList );
@@ -545,7 +548,7 @@ protected void calculatePath(List<RouterOperation> routerOperationList, Locale l
545
548
LOGGER .error (e .getMessage ());
546
549
}
547
550
if (handlerMethod != null && isFilterCondition (handlerMethod , routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ()))
548
- calculatePath (handlerMethod , routerOperation , locale );
551
+ calculatePath (handlerMethod , routerOperation , locale , openAPI );
549
552
}
550
553
}
551
554
else if (routerOperation .getOperation () != null && StringUtils .isNotBlank (routerOperation .getOperation ().operationId ()) && isFilterCondition (routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ())) {
@@ -616,10 +619,11 @@ protected void calculatePath(RouterOperation routerOperation, Locale locale) {
616
619
* @param produces the produces
617
620
* @param headers the headers
618
621
* @param locale the locale
622
+ * @param openAPI the open api
619
623
*/
620
624
protected void calculatePath (HandlerMethod handlerMethod , String operationPath ,
621
- Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , Locale locale ) {
622
- this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers ), locale );
625
+ Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , Locale locale , OpenAPI openAPI ) {
626
+ this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers ), locale , openAPI );
623
627
}
624
628
625
629
/**
@@ -628,13 +632,15 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
628
632
* @param beanName the bean name
629
633
* @param routerFunctionVisitor the router function visitor
630
634
* @param locale the locale
635
+ * @param openAPI the open api
631
636
*/
632
- protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor , Locale locale ) {
637
+ protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor ,
638
+ Locale locale , OpenAPI openAPI ) {
633
639
boolean withRouterOperation = routerFunctionVisitor .getRouterFunctionDatas ().stream ()
634
640
.anyMatch (routerFunctionData -> routerFunctionData .getAttributes ().containsKey (OPERATION_ATTRIBUTE ));
635
641
if (withRouterOperation ) {
636
642
List <RouterOperation > operationList = routerFunctionVisitor .getRouterFunctionDatas ().stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
637
- calculatePath (operationList , locale );
643
+ calculatePath (operationList , locale , openAPI );
638
644
}
639
645
else {
640
646
List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
@@ -648,11 +654,11 @@ protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVis
648
654
else
649
655
routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
650
656
if (routerOperationList .size () == 1 )
651
- calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()), locale );
657
+ calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()), locale , openAPI );
652
658
else {
653
659
List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
654
660
mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
655
- calculatePath (operationList , locale );
661
+ calculatePath (operationList , locale , openAPI );
656
662
}
657
663
}
658
664
}
0 commit comments