35
35
import java .util .HashSet ;
36
36
import java .util .LinkedHashMap ;
37
37
import java .util .List ;
38
+ import java .util .Locale ;
38
39
import java .util .Map ;
39
40
import java .util .Objects ;
40
41
import java .util .Optional ;
@@ -227,6 +228,13 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
227
228
Executors .newSingleThreadExecutor ().execute (this ::getOpenApi );
228
229
}
229
230
231
+ /**
232
+ * Gets open api.
233
+ */
234
+ private void getOpenApi () {
235
+ this .getOpenApi (Locale .getDefault ());
236
+ }
237
+
230
238
/**
231
239
* Add rest controllers.
232
240
*
@@ -265,14 +273,14 @@ public static void addHiddenRestControllers(String... classes) {
265
273
266
274
/**
267
275
* Gets open api.
268
- *
276
+ * @param locale the locale
269
277
* @return the open api
270
278
*/
271
- protected synchronized OpenAPI getOpenApi () {
279
+ protected synchronized OpenAPI getOpenApi (Locale locale ) {
272
280
OpenAPI openApi ;
273
281
if (openAPIService .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
274
282
Instant start = Instant .now ();
275
- openAPIService .build ();
283
+ openAPIService .build (locale );
276
284
Map <String , Object > mappingsMap = openAPIService .getMappingsMap ().entrySet ().stream ()
277
285
.filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
278
286
Hidden .class ) == null ))
@@ -285,9 +293,9 @@ protected synchronized OpenAPI getOpenApi() {
285
293
if (springDocConfigProperties .isOverrideWithGenericResponse () && !CollectionUtils .isEmpty (findControllerAdvice )) {
286
294
if (!CollectionUtils .isEmpty (mappingsMap ))
287
295
findControllerAdvice .putAll (mappingsMap );
288
- responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice );
296
+ responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , locale );
289
297
}
290
- getPaths (mappingsMap );
298
+ getPaths (mappingsMap , locale );
291
299
if (!CollectionUtils .isEmpty (openApi .getServers ()))
292
300
openAPIService .setServersPresent (true );
293
301
openAPIService .updateServers (openApi );
@@ -318,16 +326,18 @@ protected synchronized OpenAPI getOpenApi() {
318
326
* Gets paths.
319
327
*
320
328
* @param findRestControllers the find rest controllers
329
+ * @param locale the locale
321
330
*/
322
- protected abstract void getPaths (Map <String , Object > findRestControllers );
331
+ protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale );
323
332
324
333
/**
325
334
* Calculate path.
326
335
*
327
336
* @param handlerMethod the handler method
328
337
* @param routerOperation the router operation
338
+ * @param locale the locale
329
339
*/
330
- protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation ) {
340
+ protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation , Locale locale ) {
331
341
String operationPath = routerOperation .getPath ();
332
342
Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
333
343
io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -358,7 +368,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
358
368
RequestMapping reqMappingClass = AnnotatedElementUtils .findMergedAnnotation (handlerMethod .getBeanType (),
359
369
RequestMapping .class );
360
370
361
- MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers );
371
+ MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , locale );
362
372
methodAttributes .setMethodOverloaded (existingOperation != null );
363
373
//Use the javadoc return if present
364
374
if (javadocProvider != null ) {
@@ -389,7 +399,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
389
399
fillParametersList (operation , queryParams , methodAttributes );
390
400
391
401
// compute tags
392
- operation = openAPIService .buildTags (handlerMethod , operation , openAPI );
402
+ operation = openAPIService .buildTags (handlerMethod , operation , openAPI , locale );
393
403
394
404
io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = AnnotatedElementUtils .findMergedAnnotation (method ,
395
405
io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
@@ -444,8 +454,9 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
444
454
* Calculate path.
445
455
*
446
456
* @param routerOperationList the router operation list
457
+ * @param locale the locale
447
458
*/
448
- protected void calculatePath (List <RouterOperation > routerOperationList ) {
459
+ protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale ) {
449
460
ApplicationContext applicationContext = openAPIService .getContext ();
450
461
if (!CollectionUtils .isEmpty (routerOperationList )) {
451
462
Collections .sort (routerOperationList );
@@ -475,14 +486,14 @@ protected void calculatePath(List<RouterOperation> routerOperationList) {
475
486
LOGGER .error (e .getMessage ());
476
487
}
477
488
if (handlerMethod != null && isFilterCondition (handlerMethod , routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ()))
478
- calculatePath (handlerMethod , routerOperation );
489
+ calculatePath (handlerMethod , routerOperation , locale );
479
490
}
480
491
}
481
492
else if (routerOperation .getOperation () != null && StringUtils .isNotBlank (routerOperation .getOperation ().operationId ()) && isFilterCondition (routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ())) {
482
- calculatePath (routerOperation );
493
+ calculatePath (routerOperation , locale );
483
494
}
484
495
else if (routerOperation .getOperationModel () != null && StringUtils .isNotBlank (routerOperation .getOperationModel ().getOperationId ()) && isFilterCondition (routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ())) {
485
- calculatePath (routerOperation );
496
+ calculatePath (routerOperation , locale );
486
497
}
487
498
}
488
499
}
@@ -492,8 +503,9 @@ else if (routerOperation.getOperationModel() != null && StringUtils.isNotBlank(r
492
503
* Calculate path.
493
504
*
494
505
* @param routerOperation the router operation
506
+ * @param locale the locale
495
507
*/
496
- protected void calculatePath (RouterOperation routerOperation ) {
508
+ protected void calculatePath (RouterOperation routerOperation , Locale locale ) {
497
509
String operationPath = routerOperation .getPath ();
498
510
io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
499
511
String [] methodConsumes = routerOperation .getConsumes ();
@@ -510,7 +522,7 @@ protected void calculatePath(RouterOperation routerOperation) {
510
522
}
511
523
for (RequestMethod requestMethod : routerOperation .getMethods ()) {
512
524
Operation existingOperation = getExistingOperation (operationMap , requestMethod );
513
- MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers );
525
+ MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , locale );
514
526
methodAttributes .setMethodOverloaded (existingOperation != null );
515
527
Operation operation = getOperation (routerOperation , existingOperation );
516
528
if (apiOperation != null )
@@ -541,24 +553,26 @@ protected void calculatePath(RouterOperation routerOperation) {
541
553
* @param handlerMethod the handler method
542
554
* @param operationPath the operation path
543
555
* @param requestMethods the request methods
556
+ * @param locale the locale
544
557
*/
545
558
protected void calculatePath (HandlerMethod handlerMethod , String operationPath ,
546
- Set <RequestMethod > requestMethods ) {
547
- this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()])));
559
+ Set <RequestMethod > requestMethods , Locale locale ) {
560
+ this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()])), locale );
548
561
}
549
562
550
563
/**
551
564
* Gets router function paths.
552
565
*
553
566
* @param beanName the bean name
554
567
* @param routerFunctionVisitor the router function visitor
568
+ * @param locale the locale
555
569
*/
556
- protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor ) {
570
+ protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor , Locale locale ) {
557
571
boolean withRouterOperation = routerFunctionVisitor .getRouterFunctionDatas ().stream ()
558
572
.anyMatch (routerFunctionData -> routerFunctionData .getAttributes ().containsKey (OPERATION_ATTRIBUTE ));
559
573
if (withRouterOperation ) {
560
574
List <RouterOperation > operationList = routerFunctionVisitor .getRouterFunctionDatas ().stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
561
- calculatePath (operationList );
575
+ calculatePath (operationList , locale );
562
576
}
563
577
else {
564
578
List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
@@ -572,11 +586,11 @@ protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVis
572
586
else
573
587
routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
574
588
if (routerOperationList .size () == 1 )
575
- calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()));
589
+ calculatePath (routerOperationList .stream ().map (routerOperation -> new RouterOperation (routerOperation , routerFunctionVisitor .getRouterFunctionDatas ().get (0 ))).collect (Collectors .toList ()), locale );
576
590
else {
577
591
List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
578
592
mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
579
- calculatePath (operationList );
593
+ calculatePath (operationList , locale );
580
594
}
581
595
}
582
596
}
0 commit comments