87
87
import org .springdoc .core .SpringDocConfigProperties .GroupConfig ;
88
88
import org .springdoc .core .annotations .RouterOperations ;
89
89
import org .springdoc .core .customizers .OpenApiCustomiser ;
90
+ import org .springdoc .core .customizers .OpenApiLocaleCustomizer ;
90
91
import org .springdoc .core .customizers .OperationCustomizer ;
91
92
import org .springdoc .core .fn .AbstractRouterFunctionVisitor ;
92
93
import org .springdoc .core .fn .RouterFunctionData ;
@@ -196,6 +197,11 @@ public abstract class AbstractOpenApiResource extends SpecFilter {
196
197
*/
197
198
private static Class <?> modelAndViewClass ;
198
199
200
+ /**
201
+ * The OpenApi with locale customizers.
202
+ */
203
+ private final Map <String , OpenApiLocaleCustomizer > openApiLocaleCustomizers ;
204
+
199
205
static {
200
206
try {
201
207
modelAndViewClass = Class .forName ("org.springframework.web.servlet.ModelAndView" );
@@ -243,6 +249,7 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
243
249
this .optionalActuatorProvider = actuatorProvider ;
244
250
if (springDocConfigProperties .isPreLoadingEnabled ())
245
251
Executors .newSingleThreadExecutor ().execute (this ::getOpenApi );
252
+ this .openApiLocaleCustomizers = openAPIService .getContext ().getBeansOfType (OpenApiLocaleCustomizer .class );
246
253
}
247
254
248
255
/**
@@ -295,10 +302,10 @@ public static void addHiddenRestControllers(String... classes) {
295
302
*/
296
303
protected synchronized OpenAPI getOpenApi (Locale locale ) {
297
304
OpenAPI openApi ;
298
- locale = locale == null ? Locale .getDefault () : locale ;
299
- if (openAPIService .getCachedOpenAPI (locale ) == null || springDocConfigProperties .isCacheDisabled ()) {
305
+ final Locale finalLocale = locale == null ? Locale .getDefault () : locale ;
306
+ if (openAPIService .getCachedOpenAPI (finalLocale ) == null || springDocConfigProperties .isCacheDisabled ()) {
300
307
Instant start = Instant .now ();
301
- openAPIService .build (locale );
308
+ openAPIService .build (finalLocale );
302
309
Map <String , Object > mappingsMap = openAPIService .getMappingsMap ().entrySet ().stream ()
303
310
.filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
304
311
Hidden .class ) == null ))
@@ -311,9 +318,9 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
311
318
if (springDocConfigProperties .isOverrideWithGenericResponse () && !CollectionUtils .isEmpty (findControllerAdvice )) {
312
319
if (!CollectionUtils .isEmpty (mappingsMap ))
313
320
findControllerAdvice .putAll (mappingsMap );
314
- responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , locale );
321
+ responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , finalLocale );
315
322
}
316
- getPaths (mappingsMap , locale );
323
+ getPaths (mappingsMap , finalLocale );
317
324
if (!CollectionUtils .isEmpty (openApi .getServers ()))
318
325
openAPIService .setServersPresent (true );
319
326
openAPIService .updateServers (openApi );
@@ -332,19 +339,20 @@ protected synchronized OpenAPI getOpenApi(Locale locale) {
332
339
LOGGER .warn ("Json Processing Exception occurred: {}" , e .getMessage ());
333
340
}
334
341
342
+ openApiLocaleCustomizers .values ().forEach (openApiLocaleCustomizer -> openApiLocaleCustomizer .customise (openApi , finalLocale ));
335
343
openApiCustomisers .ifPresent (apiCustomisers -> apiCustomisers .forEach (openApiCustomiser -> openApiCustomiser .customise (openApi )));
336
344
if (!CollectionUtils .isEmpty (openApi .getServers ()) && !openApi .getServers ().equals (serversCopy ))
337
345
openAPIService .setServersPresent (true );
338
346
339
- openAPIService .setCachedOpenAPI (openApi , locale );
347
+ openAPIService .setCachedOpenAPI (openApi , finalLocale );
340
348
openAPIService .resetCalculatedOpenAPI ();
341
349
342
350
LOGGER .info ("Init duration for springdoc-openapi is: {} ms" ,
343
351
Duration .between (start , Instant .now ()).toMillis ());
344
352
}
345
353
else {
346
354
LOGGER .debug ("Fetching openApi document from cache" );
347
- openApi = openAPIService .updateServers (openAPIService .getCachedOpenAPI (locale ));
355
+ openApi = openAPIService .updateServers (openAPIService .getCachedOpenAPI (finalLocale ));
348
356
}
349
357
return openApi ;
350
358
}
0 commit comments