@@ -136,12 +136,12 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
136136 /**
137137 * The constant ADDITIONAL_REST_CONTROLLERS.
138138 */
139- private static final List <Class <?>> ADDITIONAL_REST_CONTROLLERS = new ArrayList <>();
139+ private static final List <Class <?>> ADDITIONAL_REST_CONTROLLERS = Collections . synchronizedList ( new ArrayList <>() );
140140
141141 /**
142142 * The constant HIDDEN_REST_CONTROLLERS.
143143 */
144- private static final List <Class <?>> HIDDEN_REST_CONTROLLERS = new ArrayList <>();
144+ private static final List <Class <?>> HIDDEN_REST_CONTROLLERS = Collections . synchronizedList ( new ArrayList <>() );
145145
146146 /**
147147 * The Open api builder.
@@ -304,7 +304,7 @@ public static void addHiddenRestControllers(String... classes) {
304304 * @return the open api
305305 */
306306 protected synchronized OpenAPI getOpenApi (Locale locale ) {
307- OpenAPI openApi ;
307+ OpenAPI openAPI ;
308308 final Locale finalLocale = locale == null ? Locale .getDefault () : locale ;
309309 if (openAPIService .getCachedOpenAPI (finalLocale ) == null || springDocConfigProperties .isCacheDisabled ()) {
310310 Instant start = Instant .now ();
@@ -317,33 +317,33 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
317317
318318 Map <String , Object > findControllerAdvice = openAPIService .getControllerAdviceMap ();
319319 // calculate generic responses
320- openApi = openAPIService .getCalculatedOpenAPI ();
320+ openAPI = openAPIService .getCalculatedOpenAPI ();
321321 if (OpenApiVersion .OPENAPI_3_1 == springDocConfigProperties .getApiDocs ().getVersion ())
322- openApi .openapi (OpenApiVersion .OPENAPI_3_1 .getVersion ());
322+ openAPI .openapi (OpenApiVersion .OPENAPI_3_1 .getVersion ());
323323 if (springDocConfigProperties .isDefaultOverrideWithGenericResponse ()) {
324324 if (!CollectionUtils .isEmpty (mappingsMap ))
325325 findControllerAdvice .putAll (mappingsMap );
326- responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , finalLocale );
326+ responseBuilder .buildGenericResponse (openAPI .getComponents (), findControllerAdvice , finalLocale );
327327 }
328- getPaths (mappingsMap , finalLocale );
328+ getPaths (mappingsMap , finalLocale , openAPI );
329329
330330 Optional <CloudFunctionProvider > cloudFunctionProviderOptional = springDocProviders .getSpringCloudFunctionProvider ();
331331 cloudFunctionProviderOptional .ifPresent (cloudFunctionProvider -> {
332- List <RouterOperation > routerOperationList = cloudFunctionProvider .getRouterOperations (openApi );
332+ List <RouterOperation > routerOperationList = cloudFunctionProvider .getRouterOperations (openAPI );
333333 if (!CollectionUtils .isEmpty (routerOperationList ))
334- this .calculatePath (routerOperationList , locale );
334+ this .calculatePath (routerOperationList , locale , openAPI );
335335 }
336336 );
337337
338- if (!CollectionUtils .isEmpty (openApi .getServers ()))
338+ if (!CollectionUtils .isEmpty (openAPI .getServers ()))
339339 openAPIService .setServersPresent (true );
340- openAPIService .updateServers (openApi );
340+ openAPIService .updateServers (openAPI );
341341
342342 if (springDocConfigProperties .isRemoveBrokenReferenceDefinitions ())
343- this .removeBrokenReferenceDefinitions (openApi );
343+ this .removeBrokenReferenceDefinitions (openAPI );
344344
345345 // run the optional customisers
346- List <Server > servers = openApi .getServers ();
346+ List <Server > servers = openAPI .getServers ();
347347 List <Server > serversCopy = null ;
348348 try {
349349 serversCopy = springDocProviders .jsonMapper ()
@@ -353,40 +353,43 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
353353 LOGGER .warn ("Json Processing Exception occurred: {}" , e .getMessage ());
354354 }
355355
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 ))
359359 openAPIService .setServersPresent (true );
360360
361- openAPIService .setCachedOpenAPI (openApi , finalLocale );
361+ openAPIService .setCachedOpenAPI (openAPI , finalLocale );
362362 openAPIService .resetCalculatedOpenAPI ();
363363
364364 LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
365365 Duration .between (start , Instant .now ()).toMillis ());
366366 }
367367 else {
368368 LOGGER .debug ("Fetching openApi document from cache" );
369- openApi = openAPIService .updateServers (openAPIService .getCachedOpenAPI (finalLocale ));
369+ openAPI = openAPIService .updateServers (openAPIService .getCachedOpenAPI (finalLocale ));
370370 }
371- return openApi ;
371+ return openAPI ;
372372 }
373373
374374 /**
375375 * Gets paths.
376376 *
377377 * @param findRestControllers the find rest controllers
378378 * @param locale the locale
379+ * @param openAPI the open api
379380 */
380- protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale );
381+ protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale , OpenAPI openAPI );
381382
382383 /**
383384 * Calculate path.
384385 *
385386 * @param handlerMethod the handler method
386387 * @param routerOperation the router operation
387388 * @param locale the locale
389+ * @param openAPI the open api
388390 */
389- protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation , Locale locale ) {
391+ protected void calculatePath (HandlerMethod handlerMethod ,
392+ RouterOperation routerOperation , Locale locale , OpenAPI openAPI ) {
390393 String operationPath = routerOperation .getPath ();
391394 Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
392395 io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -395,7 +398,6 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
395398 String [] headers = routerOperation .getHeaders ();
396399 Map <String , String > queryParams = routerOperation .getQueryParams ();
397400
398- OpenAPI openAPI = openAPIService .getCalculatedOpenAPI ();
399401 Components components = openAPI .getComponents ();
400402 Paths paths = openAPI .getPaths ();
401403
@@ -514,8 +516,9 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
514516 *
515517 * @param routerOperationList the router operation list
516518 * @param locale the locale
519+ * @param openAPI the open api
517520 */
518- protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale ) {
521+ protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale , OpenAPI openAPI ) {
519522 ApplicationContext applicationContext = openAPIService .getContext ();
520523 if (!CollectionUtils .isEmpty (routerOperationList )) {
521524 Collections .sort (routerOperationList );
@@ -545,7 +548,7 @@ protected void calculatePath(List<RouterOperation> routerOperationList, Locale l
545548 LOGGER .error (e .getMessage ());
546549 }
547550 if (handlerMethod != null && isFilterCondition (handlerMethod , routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ()))
548- calculatePath (handlerMethod , routerOperation , locale );
551+ calculatePath (handlerMethod , routerOperation , locale , openAPI );
549552 }
550553 }
551554 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) {
616619 * @param produces the produces
617620 * @param headers the headers
618621 * @param locale the locale
622+ * @param openAPI the open api
619623 */
620624 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 );
623627 }
624628
625629 /**
@@ -628,13 +632,15 @@ protected void calculatePath(HandlerMethod handlerMethod, String operationPath,
628632 * @param beanName the bean name
629633 * @param routerFunctionVisitor the router function visitor
630634 * @param locale the locale
635+ * @param openAPI the open api
631636 */
632- protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor , Locale locale ) {
637+ protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor ,
638+ Locale locale , OpenAPI openAPI ) {
633639 boolean withRouterOperation = routerFunctionVisitor .getRouterFunctionDatas ().stream ()
634640 .anyMatch (routerFunctionData -> routerFunctionData .getAttributes ().containsKey (OPERATION_ATTRIBUTE ));
635641 if (withRouterOperation ) {
636642 List <RouterOperation > operationList = routerFunctionVisitor .getRouterFunctionDatas ().stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
637- calculatePath (operationList , locale );
643+ calculatePath (operationList , locale , openAPI );
638644 }
639645 else {
640646 List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
@@ -648,11 +654,11 @@ protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVis
648654 else
649655 routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
650656 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 );
652658 else {
653659 List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
654660 mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
655- calculatePath (operationList , locale );
661+ calculatePath (operationList , locale , openAPI );
656662 }
657663 }
658664 }
0 commit comments