3535import java .util .HashSet ;
3636import java .util .LinkedHashMap ;
3737import java .util .List ;
38+ import java .util .Locale ;
3839import java .util .Map ;
3940import java .util .Objects ;
4041import java .util .Optional ;
@@ -227,6 +228,13 @@ protected AbstractOpenApiResource(String groupName, ObjectFactory<OpenAPIService
227228 Executors .newSingleThreadExecutor ().execute (this ::getOpenApi );
228229 }
229230
231+ /**
232+ * Gets open api.
233+ */
234+ private void getOpenApi () {
235+ this .getOpenApi (Locale .getDefault ());
236+ }
237+
230238 /**
231239 * Add rest controllers.
232240 *
@@ -265,14 +273,14 @@ public static void addHiddenRestControllers(String... classes) {
265273
266274 /**
267275 * Gets open api.
268- *
276+ * @param locale the locale
269277 * @return the open api
270278 */
271- protected synchronized OpenAPI getOpenApi () {
279+ protected synchronized OpenAPI getOpenApi (Locale locale ) {
272280 OpenAPI openApi ;
273281 if (openAPIService .getCachedOpenAPI () == null || springDocConfigProperties .isCacheDisabled ()) {
274282 Instant start = Instant .now ();
275- openAPIService .build ();
283+ openAPIService .build (locale );
276284 Map <String , Object > mappingsMap = openAPIService .getMappingsMap ().entrySet ().stream ()
277285 .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
278286 Hidden .class ) == null ))
@@ -285,9 +293,9 @@ protected synchronized OpenAPI getOpenApi() {
285293 if (springDocConfigProperties .isOverrideWithGenericResponse () && !CollectionUtils .isEmpty (findControllerAdvice )) {
286294 if (!CollectionUtils .isEmpty (mappingsMap ))
287295 findControllerAdvice .putAll (mappingsMap );
288- responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice );
296+ responseBuilder .buildGenericResponse (openApi .getComponents (), findControllerAdvice , locale );
289297 }
290- getPaths (mappingsMap );
298+ getPaths (mappingsMap , locale );
291299 if (!CollectionUtils .isEmpty (openApi .getServers ()))
292300 openAPIService .setServersPresent (true );
293301 openAPIService .updateServers (openApi );
@@ -318,16 +326,18 @@ protected synchronized OpenAPI getOpenApi() {
318326 * Gets paths.
319327 *
320328 * @param findRestControllers the find rest controllers
329+ * @param locale the locale
321330 */
322- protected abstract void getPaths (Map <String , Object > findRestControllers );
331+ protected abstract void getPaths (Map <String , Object > findRestControllers , Locale locale );
323332
324333 /**
325334 * Calculate path.
326335 *
327336 * @param handlerMethod the handler method
328337 * @param routerOperation the router operation
338+ * @param locale the locale
329339 */
330- protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation ) {
340+ protected void calculatePath (HandlerMethod handlerMethod , RouterOperation routerOperation , Locale locale ) {
331341 String operationPath = routerOperation .getPath ();
332342 Set <RequestMethod > requestMethods = new HashSet <>(Arrays .asList (routerOperation .getMethods ()));
333343 io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
@@ -358,7 +368,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
358368 RequestMapping reqMappingClass = AnnotatedElementUtils .findMergedAnnotation (handlerMethod .getBeanType (),
359369 RequestMapping .class );
360370
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 );
362372 methodAttributes .setMethodOverloaded (existingOperation != null );
363373 //Use the javadoc return if present
364374 if (javadocProvider != null ) {
@@ -389,7 +399,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
389399 fillParametersList (operation , queryParams , methodAttributes );
390400
391401 // compute tags
392- operation = openAPIService .buildTags (handlerMethod , operation , openAPI );
402+ operation = openAPIService .buildTags (handlerMethod , operation , openAPI , locale );
393403
394404 io .swagger .v3 .oas .annotations .parameters .RequestBody requestBodyDoc = AnnotatedElementUtils .findMergedAnnotation (method ,
395405 io .swagger .v3 .oas .annotations .parameters .RequestBody .class );
@@ -444,8 +454,9 @@ private void buildCallbacks(OpenAPI openAPI, MethodAttributes methodAttributes,
444454 * Calculate path.
445455 *
446456 * @param routerOperationList the router operation list
457+ * @param locale the locale
447458 */
448- protected void calculatePath (List <RouterOperation > routerOperationList ) {
459+ protected void calculatePath (List <RouterOperation > routerOperationList , Locale locale ) {
449460 ApplicationContext applicationContext = openAPIService .getContext ();
450461 if (!CollectionUtils .isEmpty (routerOperationList )) {
451462 Collections .sort (routerOperationList );
@@ -475,14 +486,14 @@ protected void calculatePath(List<RouterOperation> routerOperationList) {
475486 LOGGER .error (e .getMessage ());
476487 }
477488 if (handlerMethod != null && isFilterCondition (handlerMethod , routerOperation .getPath (), routerOperation .getProduces (), routerOperation .getConsumes (), routerOperation .getHeaders ()))
478- calculatePath (handlerMethod , routerOperation );
489+ calculatePath (handlerMethod , routerOperation , locale );
479490 }
480491 }
481492 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 );
483494 }
484495 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 );
486497 }
487498 }
488499 }
@@ -492,8 +503,9 @@ else if (routerOperation.getOperationModel() != null && StringUtils.isNotBlank(r
492503 * Calculate path.
493504 *
494505 * @param routerOperation the router operation
506+ * @param locale the locale
495507 */
496- protected void calculatePath (RouterOperation routerOperation ) {
508+ protected void calculatePath (RouterOperation routerOperation , Locale locale ) {
497509 String operationPath = routerOperation .getPath ();
498510 io .swagger .v3 .oas .annotations .Operation apiOperation = routerOperation .getOperation ();
499511 String [] methodConsumes = routerOperation .getConsumes ();
@@ -510,7 +522,7 @@ protected void calculatePath(RouterOperation routerOperation) {
510522 }
511523 for (RequestMethod requestMethod : routerOperation .getMethods ()) {
512524 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 );
514526 methodAttributes .setMethodOverloaded (existingOperation != null );
515527 Operation operation = getOperation (routerOperation , existingOperation );
516528 if (apiOperation != null )
@@ -541,24 +553,26 @@ protected void calculatePath(RouterOperation routerOperation) {
541553 * @param handlerMethod the handler method
542554 * @param operationPath the operation path
543555 * @param requestMethods the request methods
556+ * @param locale the locale
544557 */
545558 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 );
548561 }
549562
550563 /**
551564 * Gets router function paths.
552565 *
553566 * @param beanName the bean name
554567 * @param routerFunctionVisitor the router function visitor
568+ * @param locale the locale
555569 */
556- protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor ) {
570+ protected void getRouterFunctionPaths (String beanName , AbstractRouterFunctionVisitor routerFunctionVisitor , Locale locale ) {
557571 boolean withRouterOperation = routerFunctionVisitor .getRouterFunctionDatas ().stream ()
558572 .anyMatch (routerFunctionData -> routerFunctionData .getAttributes ().containsKey (OPERATION_ATTRIBUTE ));
559573 if (withRouterOperation ) {
560574 List <RouterOperation > operationList = routerFunctionVisitor .getRouterFunctionDatas ().stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
561- calculatePath (operationList );
575+ calculatePath (operationList , locale );
562576 }
563577 else {
564578 List <org .springdoc .core .annotations .RouterOperation > routerOperationList = new ArrayList <>();
@@ -572,11 +586,11 @@ protected void getRouterFunctionPaths(String beanName, AbstractRouterFunctionVis
572586 else
573587 routerOperationList .addAll (Arrays .asList (routerOperations .value ()));
574588 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 );
576590 else {
577591 List <RouterOperation > operationList = routerOperationList .stream ().map (RouterOperation ::new ).collect (Collectors .toList ());
578592 mergeRouters (routerFunctionVisitor .getRouterFunctionDatas (), operationList );
579- calculatePath (operationList );
593+ calculatePath (operationList , locale );
580594 }
581595 }
582596 }
0 commit comments