@@ -261,7 +261,7 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
261261 parameters = DelegatingMethodParameter .customize (pNames , parameters , parameterBuilder .getDelegatingMethodParameterCustomizer (), this .defaultFlatParamObject );
262262 RequestBodyInfo requestBodyInfo = new RequestBodyInfo ();
263263 List <Parameter > operationParameters = (operation .getParameters () != null ) ? operation .getParameters () : new ArrayList <>();
264- Map <String , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap = getApiParameters (handlerMethod .getMethod ());
264+ Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap = getApiParameters (handlerMethod .getMethod ());
265265 Components components = openAPI .getComponents ();
266266
267267 JavadocProvider javadocProvider = operationService .getJavadocProvider ();
@@ -274,10 +274,10 @@ public Operation build(HandlerMethod handlerMethod, RequestMethod requestMethod,
274274 io .swagger .v3 .oas .annotations .Parameter .class );
275275
276276 final String pName = methodParameter .getParameterName ();
277- ParameterInfo parameterInfo = new ParameterInfo (pName , methodParameter , parameterBuilder );
277+ ParameterInfo parameterInfo = new ParameterInfo (pName , methodParameter , parameterBuilder , parameterDoc );
278278
279279 if (parameterDoc == null )
280- parameterDoc = parametersDocMap .get (parameterInfo .getpName ());
280+ parameterDoc = parametersDocMap .get (parameterInfo .getParameterId ());
281281
282282 if (parameterDoc == null ) {
283283 io .swagger .v3 .oas .annotations .media .Schema schema = AnnotatedElementUtils .findMergedAnnotation (
@@ -364,35 +364,43 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
364364 * @param parametersDocMap the parameters doc map
365365 * @return the parameter linked hash map
366366 */
367- private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <String , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
368- LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ()
369- .collect (Collectors .toMap (
370- ParameterId ::new ,
371- parameter -> parameter ,
372- (u , v ) -> {
373- throw new IllegalStateException (String .format ("Duplicate key %s" , u ));
374- },
375- LinkedHashMap ::new
376- ));
377-
378- for (Map .Entry <String , io .swagger .v3 .oas .annotations .Parameter > entry : parametersDocMap .entrySet ()) {
379- ParameterId parameterId = new ParameterId (entry .getValue ());
380- if (entry .getKey () != null && !map .containsKey (parameterId ) && !entry .getValue ().hidden ()) {
381- //Convert
382- Parameter parameter = parameterBuilder .buildParameterFromDoc (entry .getValue (), components ,
383- methodAttributes .getJsonViewAnnotation (), methodAttributes .getLocale ());
384- map .put (parameterId , parameter );
367+ private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
368+ LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ().collect (Collectors .toMap (ParameterId ::new , parameter -> parameter , (u , v ) -> {
369+ throw new IllegalStateException (String .format ("Duplicate key %s" , u ));
370+ }, LinkedHashMap ::new ));
371+
372+ for (Map .Entry <ParameterId , io .swagger .v3 .oas .annotations .Parameter > entry : parametersDocMap .entrySet ()) {
373+ ParameterId parameterId = entry .getKey ();
374+ if (parameterId != null && !map .containsKey (parameterId ) && !entry .getValue ().hidden ()) {
375+ Parameter parameter = parameterBuilder .buildParameterFromDoc (entry .getValue (), components , methodAttributes .getJsonViewAnnotation (), methodAttributes .getLocale ());
376+ //proceed with the merge if possible
377+ if (map .containsKey (parameterId )) {
378+ GenericParameterService .mergeParameter (map .get (parameterId ), parameter );
379+ map .put (parameterId , parameter );
380+ }
381+ else {
382+ long mumParamsWithName = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
383+ long mumParamsDocWithName = parametersDocMap .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
384+ if (mumParamsWithName == 1 && mumParamsDocWithName == 1 ) {
385+ Optional <ParameterId > parameterIdWithSameNameOptional = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).findAny ();
386+ parameterIdWithSameNameOptional .ifPresent (parameterIdWithSameName -> {
387+ GenericParameterService .mergeParameter (map .get (parameterIdWithSameName ), parameter );
388+ map .put (parameterIdWithSameName , parameter );
389+ });
390+ }
391+ else
392+ map .put (parameterId , parameter );
393+ }
385394 }
386395 }
387396
388- getHeaders (methodAttributes , map );
389- map .forEach ((parameterId , parameter ) -> {
390- if (StringUtils .isBlank (parameter .getIn ()) && StringUtils .isBlank (parameter .get$ref ()))
397+ getHeaders (methodAttributes , map ); map .forEach ((parameterId , parameter ) -> {
398+ if (StringUtils .isBlank (parameter .getIn ()) && StringUtils .isBlank (parameter .get$ref ()))
391399 parameter .setIn (ParameterIn .QUERY .toString ());
392- });
393- return map ;
400+ }); return map ;
394401 }
395402
403+
396404 /**
397405 * Gets headers.
398406 *
@@ -650,34 +658,22 @@ public RequestBodyService getRequestBodyBuilder() {
650658 * @param method the method
651659 * @return the api parameters
652660 */
653- private Map <String , io .swagger .v3 .oas .annotations .Parameter > getApiParameters (Method method ) {
661+ private Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > getApiParameters (Method method ) {
654662 Class <?> declaringClass = method .getDeclaringClass ();
655663
656- Set <io .swagger .v3 .oas .annotations .Parameters > apiParametersDoc = AnnotatedElementUtils
657- .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameters .class );
658- LinkedHashMap <String , io .swagger .v3 .oas .annotations .Parameter > apiParametersMap = apiParametersDoc .stream ()
659- .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (io .swagger .v3 .oas .annotations .Parameter ::name , x -> x , (e1 , e2 ) -> e2 ,
660- LinkedHashMap ::new ));
661-
662- Set <io .swagger .v3 .oas .annotations .Parameters > apiParametersDocDeclaringClass = AnnotatedElementUtils
663- .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameters .class );
664- LinkedHashMap <String , io .swagger .v3 .oas .annotations .Parameter > apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass .stream ()
665- .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (io .swagger .v3 .oas .annotations .Parameter ::name , x -> x , (e1 , e2 ) -> e2 ,
666- LinkedHashMap ::new ));
664+ Set <io .swagger .v3 .oas .annotations .Parameters > apiParametersDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameters .class );
665+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersMap = apiParametersDoc .stream ().flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
666+
667+ Set <io .swagger .v3 .oas .annotations .Parameters > apiParametersDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameters .class );
668+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass .stream ().flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
667669 apiParametersMap .putAll (apiParametersDocDeclaringClassMap );
668670
669- Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDoc = AnnotatedElementUtils
670- .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameter .class );
671- LinkedHashMap <String , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ()
672- .collect (Collectors .toMap (io .swagger .v3 .oas .annotations .Parameter ::name , x -> x , (e1 , e2 ) -> e2 ,
673- LinkedHashMap ::new ));
671+ Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameter .class );
672+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
674673 apiParametersMap .putAll (apiParameterDocMap );
675674
676- Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClass = AnnotatedElementUtils
677- .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameter .class );
678- LinkedHashMap <String , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ()
679- .collect (Collectors .toMap (io .swagger .v3 .oas .annotations .Parameter ::name , x -> x , (e1 , e2 ) -> e2 ,
680- LinkedHashMap ::new ));
675+ Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameter .class );
676+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
681677 apiParametersMap .putAll (apiParameterDocDeclaringClassMap );
682678
683679 return apiParametersMap ;
0 commit comments