5656
5757import com .fasterxml .jackson .annotation .JsonView ;
5858import io .swagger .v3 .core .converter .AnnotatedType ;
59- import io .swagger .v3 .core .util .PrimitiveType ;
6059import io .swagger .v3 .oas .annotations .Parameters ;
6160import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
6261import io .swagger .v3 .oas .models .Components ;
@@ -435,8 +434,12 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
435434 * @param parametersDocMap the parameters doc map
436435 * @return the parameter linked hash map
437436 */
438- private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
439- LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ().collect (Collectors .toMap (ParameterId ::new , parameter -> parameter , (u , v ) -> {
437+ private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components ,
438+ MethodAttributes methodAttributes ,
439+ List <Parameter > operationParameters ,
440+ Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
441+ LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ()
442+ .collect (Collectors .toMap (ParameterId ::new , parameter -> parameter , (u , v ) -> {
440443 LOGGER .warn (
441444 "Duplicate OpenAPI parameter detected: name='{}', in='{}'. Keeping the first found and ignoring the rest. " +
442445 "Declare the parameter only once." ,
@@ -458,7 +461,8 @@ private LinkedHashMap<ParameterId, Parameter> getParameterLinkedHashMap(Componen
458461 long mumParamsWithName = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
459462 long mumParamsDocWithName = parametersDocMap .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
460463 if (mumParamsWithName == 1 && mumParamsDocWithName == 1 ) {
461- Optional <ParameterId > parameterIdWithSameNameOptional = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).findAny ();
464+ Optional <ParameterId > parameterIdWithSameNameOptional = map .keySet ().stream ()
465+ .filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).findAny ();
462466 parameterIdWithSameNameOptional .ifPresent (parameterIdWithSameName -> {
463467 GenericParameterService .mergeParameter (map .get (parameterIdWithSameName ), parameter );
464468 map .put (parameterIdWithSameName , parameter );
@@ -595,7 +599,8 @@ private void setParams(Operation operation, List<Parameter> operationParameters,
595599 * @return the boolean
596600 */
597601 public boolean isValidParameter (Parameter parameter , MethodAttributes methodAttributes ) {
598- return parameter != null && (parameter .getName () != null || parameter .get$ref () != null ) && !(List .of (methodAttributes .getMethodConsumes ()).contains (APPLICATION_FORM_URLENCODED_VALUE ) && ParameterIn .QUERY .toString ().equals (parameter .getIn ()));
602+ return parameter != null && (parameter .getName () != null || parameter .get$ref () != null ) &&
603+ !(List .of (methodAttributes .getMethodConsumes ()).contains (APPLICATION_FORM_URLENCODED_VALUE ) && ParameterIn .QUERY .toString ().equals (parameter .getIn ()));
599604 }
600605
601606 /**
@@ -660,14 +665,7 @@ public Parameter buildParam(ParameterInfo parameterInfo, Components components,
660665 Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , null ,
661666 jsonView );
662667 if (parameterInfo .getDefaultValue () != null && schema != null ) {
663- Object defaultValue = parameterInfo .getDefaultValue ();
664- // Cast default value
665- PrimitiveType primitiveType = PrimitiveType .fromTypeAndFormat (schema .getType (), schema .getFormat ());
666- if (primitiveType != null ) {
667- Schema <?> primitiveSchema = primitiveType .createProperty ();
668- primitiveSchema .setDefault (parameterInfo .getDefaultValue ());
669- defaultValue = primitiveSchema .getDefault ();
670- }
668+ Object defaultValue = SpringDocAnnotationsUtils .castDefaultValue (schema , parameterInfo .getDefaultValue ());
671669 schema .setDefault (defaultValue );
672670 }
673671 parameter .setSchema (schema );
@@ -784,18 +782,22 @@ private Map<ParameterId, io.swagger.v3.oas.annotations.Parameter> getApiParamete
784782 Class <?> declaringClass = method .getDeclaringClass ();
785783
786784 Set <Parameters > apiParametersDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , Parameters .class );
787- 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 ));
785+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersMap = apiParametersDoc .stream ()
786+ .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
788787
789788 Set <Parameters > apiParametersDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , Parameters .class );
790- 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 ));
789+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass .stream ()
790+ .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
791791 apiParametersMap .putAll (apiParametersDocDeclaringClassMap );
792792
793793 Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameter .class );
794- LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
794+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ()
795+ .collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
795796 apiParametersMap .putAll (apiParameterDocMap );
796797
797798 Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameter .class );
798- LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
799+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ()
800+ .collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
799801 apiParametersMap .putAll (apiParameterDocDeclaringClassMap );
800802
801803 return apiParametersMap ;
0 commit comments