4343import java .util .LinkedHashMap ;
4444import java .util .List ;
4545import java .util .Locale ;
46+ import java .util .Locale .LanguageRange ;
4647import java .util .Map ;
48+ import java .util .Map .Entry ;
4749import java .util .Objects ;
4850import java .util .Optional ;
4951import java .util .Set ;
111113import org .springdoc .core .utils .PropertyResolverUtils ;
112114import org .springdoc .core .utils .SpringDocAnnotationsUtils ;
113115import org .springdoc .core .utils .SpringDocUtils ;
116+ import org .springdoc .core .versions .SpringDocVersionStrategy ;
114117
115118import org .springframework .aop .support .AopUtils ;
116119import org .springframework .beans .factory .ObjectFactory ;
@@ -369,7 +372,7 @@ protected OpenAPI getOpenApi(String serverBaseUrl, Locale locale) {
369372 .filter (controller -> (AnnotationUtils .findAnnotation (controller .getValue ().getClass (),
370373 Hidden .class ) == null ))
371374 .filter (controller -> !isHiddenRestControllers (controller .getValue ().getClass ()))
372- .collect (Collectors .toMap (Map . Entry ::getKey , Map . Entry ::getValue , (a1 , a2 ) -> a1 ));
375+ .collect (Collectors .toMap (Entry ::getKey , Entry ::getValue , (a1 , a2 ) -> a1 ));
373376
374377 Map <String , Object > findControllerAdvice = openAPIService .getControllerAdviceMap ();
375378 if (OpenApiVersion .OPENAPI_3_1 == springDocConfigProperties .getApiDocs ().getVersion ()) {
@@ -434,7 +437,7 @@ private Locale selectLocale(Locale inputLocale) {
434437 List <String > allowedLocales = springDocConfigProperties .getAllowedLocales ();
435438 if (!CollectionUtils .isEmpty (allowedLocales )) {
436439 Locale bestMatchingAllowedLocale = Locale .lookup (
437- Locale . LanguageRange .parse (inputLocale .toLanguageTag ()),
440+ LanguageRange .parse (inputLocale .toLanguageTag ()),
438441 allowedLocales .stream ().map (Locale ::forLanguageTag ).toList ()
439442 );
440443
@@ -568,7 +571,9 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
568571 String [] methodProduces = routerOperation .getProduces ();
569572 String [] headers = routerOperation .getHeaders ();
570573 Map <String , String > queryParams = routerOperation .getQueryParams ();
571-
574+ SpringDocVersionStrategy springDocVersionStrategy = routerOperation .getSpringDocVersionStrategy ();
575+ if (springDocVersionStrategy != null )
576+ queryParams = springDocVersionStrategy .updateQueryParams (queryParams );
572577 Components components = openAPI .getComponents ();
573578 Paths paths = openAPI .getPaths ();
574579
@@ -590,7 +595,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
590595 RequestMapping reqMappingClass = AnnotatedElementUtils .findMergedAnnotation (handlerMethod .getBeanType (),
591596 RequestMapping .class );
592597
593- MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , locale );
598+ MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , springDocVersionStrategy , locale );
594599 methodAttributes .setMethodOverloaded (existingOperation != null );
595600 //Use the javadoc return if present
596601 if (javadocProvider != null ) {
@@ -655,7 +660,7 @@ protected void calculatePath(HandlerMethod handlerMethod, RouterOperation router
655660 }
656661 }
657662
658- Set <io . swagger . v3 . oas . annotations . callbacks . Callback > apiCallbacks = AnnotatedElementUtils .findMergedRepeatableAnnotations (method , io . swagger . v3 . oas . annotations . callbacks . Callback .class );
663+ Set <Callback > apiCallbacks = AnnotatedElementUtils .findMergedRepeatableAnnotations (method , Callback .class );
659664
660665 // callbacks
661666 buildCallbacks (openAPI , methodAttributes , operation , apiCallbacks );
@@ -757,7 +762,9 @@ protected void calculatePath(RouterOperation routerOperation, Locale locale, Ope
757762 String [] methodProduces = routerOperation .getProduces ();
758763 String [] headers = routerOperation .getHeaders ();
759764 Map <String , String > queryParams = routerOperation .getQueryParams ();
760-
765+ SpringDocVersionStrategy springDocVersionStrategy = routerOperation .getSpringDocVersionStrategy ();
766+ if (springDocVersionStrategy != null )
767+ queryParams = springDocVersionStrategy .updateQueryParams (queryParams );
761768 Paths paths = openAPI .getPaths ();
762769 Map <HttpMethod , Operation > operationMap = null ;
763770 if (paths .containsKey (operationPath )) {
@@ -766,7 +773,7 @@ protected void calculatePath(RouterOperation routerOperation, Locale locale, Ope
766773 }
767774 for (RequestMethod requestMethod : routerOperation .getMethods ()) {
768775 Operation existingOperation = getExistingOperation (operationMap , requestMethod );
769- MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , locale );
776+ MethodAttributes methodAttributes = new MethodAttributes (springDocConfigProperties .getDefaultConsumesMediaType (), springDocConfigProperties .getDefaultProducesMediaType (), methodConsumes , methodProduces , headers , springDocVersionStrategy , locale );
770777 methodAttributes .setMethodOverloaded (existingOperation != null );
771778 Operation operation = getOperation (routerOperation , existingOperation );
772779 if (apiOperation != null )
@@ -812,19 +819,20 @@ private RouterOperation customizeDataRestRouterOperation(RouterOperation routerO
812819 /**
813820 * Calculate path.
814821 *
815- * @param handlerMethod the handler method
816- * @param operationPath the operation path
817- * @param requestMethods the request methods
818- * @param consumes the consumes
819- * @param produces the produces
820- * @param headers the headers
821- * @param params the params
822- * @param locale the locale
823- * @param openAPI the open api
822+ * @param handlerMethod the handler method
823+ * @param operationPath the operation path
824+ * @param requestMethods the request methods
825+ * @param consumes the consumes
826+ * @param produces the produces
827+ * @param headers the headers
828+ * @param params the params
829+ * @param versionStrategy the version strategy
830+ * @param locale the locale
831+ * @param openAPI the open api
824832 */
825833 protected void calculatePath (HandlerMethod handlerMethod , String operationPath ,
826- Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , String [] params , Locale locale , OpenAPI openAPI ) {
827- this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers , params ), locale , openAPI );
834+ Set <RequestMethod > requestMethods , String [] consumes , String [] produces , String [] headers , String [] params , SpringDocVersionStrategy versionStrategy , Locale locale , OpenAPI openAPI ) {
835+ this .calculatePath (handlerMethod , new RouterOperation (operationPath , requestMethods .toArray (new RequestMethod [requestMethods .size ()]), consumes , produces , headers , params , versionStrategy ), locale , openAPI );
828836 }
829837
830838 /**
@@ -1227,10 +1235,16 @@ private void fillParametersList(Operation operation, Map<String, String> queryPa
12271235 }
12281236 });
12291237 if (!CollectionUtils .isEmpty (queryParams )) {
1230- for (Map .Entry <String , String > entry : queryParams .entrySet ()) {
1231- io .swagger .v3 .oas .models .parameters .Parameter parameter = new io .swagger .v3 .oas .models .parameters .Parameter ();
1232- parameter .setName (entry .getKey ());
1233- parameter .setSchema (new StringSchema ()._default (entry .getValue ()));
1238+ Map <String , String > versionDefaultMap = null ;
1239+ if (methodAttributes .getSpringDocVersionStrategy () != null )
1240+ versionDefaultMap = methodAttributes .getSpringDocVersionStrategy ().getVersionDefaultMap ();
1241+ for (Entry <String , String > entry : queryParams .entrySet ()) {
1242+ Parameter parameter = new Parameter ();
1243+ String name = entry .getKey ();
1244+ String value = entry .getValue ();
1245+ String defaultValue = (versionDefaultMap != null ) ? versionDefaultMap .get (name ) : value ;
1246+ parameter .setName (name );
1247+ parameter .setSchema (new StringSchema ()._default (defaultValue )._enum (Collections .singletonList (value )));
12341248 parameter .setRequired (true );
12351249 parameter .setIn (ParameterIn .QUERY .toString ());
12361250 GenericParameterService .mergeParameter (parametersList , parameter );
0 commit comments