3636import java .lang .reflect .Method ;
3737import java .security .Principal ;
3838import java .time .ZoneId ;
39- import java .util .ArrayList ;
40- import java .util .Arrays ;
41- import java .util .Collection ;
42- import java .util .Collections ;
43- import java .util .HashMap ;
44- import java .util .Iterator ;
45- import java .util .LinkedHashMap ;
46- import java .util .List ;
47- import java .util .Locale ;
48- import java .util .Map ;
39+ import java .util .*;
4940import java .util .Map .Entry ;
50- import java .util .Objects ;
51- import java .util .Optional ;
52- import java .util .Set ;
53- import java .util .TimeZone ;
5441import java .util .stream .Collectors ;
5542import java .util .stream .Stream ;
5643
5744import com .fasterxml .jackson .annotation .JsonView ;
5845import io .swagger .v3 .core .converter .AnnotatedType ;
59- import io .swagger .v3 .core .util .PrimitiveType ;
6046import io .swagger .v3 .oas .annotations .Parameters ;
6147import io .swagger .v3 .oas .annotations .enums .ParameterIn ;
6248import io .swagger .v3 .oas .models .Components ;
@@ -416,8 +402,12 @@ else if (!RequestMethod.GET.equals(requestMethod) || OpenApiVersion.OPENAPI_3_1.
416402 * @param parametersDocMap the parameters doc map
417403 * @return the parameter linked hash map
418404 */
419- private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components , MethodAttributes methodAttributes , List <Parameter > operationParameters , Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
420- LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ().collect (Collectors .toMap (ParameterId ::new , parameter -> parameter , (u , v ) -> {
405+ private LinkedHashMap <ParameterId , Parameter > getParameterLinkedHashMap (Components components ,
406+ MethodAttributes methodAttributes ,
407+ List <Parameter > operationParameters ,
408+ Map <ParameterId , io .swagger .v3 .oas .annotations .Parameter > parametersDocMap ) {
409+ LinkedHashMap <ParameterId , Parameter > map = operationParameters .stream ()
410+ .collect (Collectors .toMap (ParameterId ::new , parameter -> parameter , (u , v ) -> {
421411 LOGGER .warn (
422412 "Duplicate OpenAPI parameter detected: name='{}', in='{}'. Keeping the first found and ignoring the rest. " +
423413 "Declare the parameter only once." ,
@@ -439,7 +429,8 @@ private LinkedHashMap<ParameterId, Parameter> getParameterLinkedHashMap(Componen
439429 long mumParamsWithName = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
440430 long mumParamsDocWithName = parametersDocMap .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).count ();
441431 if (mumParamsWithName == 1 && mumParamsDocWithName == 1 ) {
442- Optional <ParameterId > parameterIdWithSameNameOptional = map .keySet ().stream ().filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).findAny ();
432+ Optional <ParameterId > parameterIdWithSameNameOptional = map .keySet ().stream ()
433+ .filter (parameterId1 -> parameterId .getpName ().equals (parameterId1 .getpName ())).findAny ();
443434 parameterIdWithSameNameOptional .ifPresent (parameterIdWithSameName -> {
444435 GenericParameterService .mergeParameter (map .get (parameterIdWithSameName ), parameter );
445436 map .put (parameterIdWithSameName , parameter );
@@ -574,7 +565,8 @@ private void setParams(Operation operation, List<Parameter> operationParameters,
574565 * @return the boolean
575566 */
576567 public boolean isValidParameter (Parameter parameter , MethodAttributes methodAttributes ) {
577- return parameter != null && (parameter .getName () != null || parameter .get$ref () != null ) && !(ArrayUtils .contains (methodAttributes .getMethodConsumes (), APPLICATION_FORM_URLENCODED_VALUE ) && ParameterIn .QUERY .toString ().equals (parameter .getIn ()));
568+ return parameter != null && (parameter .getName () != null || parameter .get$ref () != null ) &&
569+ !(ArrayUtils .contains (methodAttributes .getMethodConsumes (), APPLICATION_FORM_URLENCODED_VALUE ) && ParameterIn .QUERY .toString ().equals (parameter .getIn ()));
578570 }
579571
580572 /**
@@ -639,14 +631,7 @@ public Parameter buildParam(ParameterInfo parameterInfo, Components components,
639631 Schema <?> schema = parameterBuilder .calculateSchema (components , parameterInfo , null ,
640632 jsonView );
641633 if (parameterInfo .getDefaultValue () != null && schema != null ) {
642- Object defaultValue = parameterInfo .getDefaultValue ();
643- // Cast default value
644- PrimitiveType primitiveType = PrimitiveType .fromTypeAndFormat (schema .getType (), schema .getFormat ());
645- if (primitiveType != null ) {
646- Schema <?> primitiveSchema = primitiveType .createProperty ();
647- primitiveSchema .setDefault (parameterInfo .getDefaultValue ());
648- defaultValue = primitiveSchema .getDefault ();
649- }
634+ Object defaultValue = SpringDocAnnotationsUtils .castDefaultValue (schema , parameterInfo .getDefaultValue ());
650635 schema .setDefault (defaultValue );
651636 }
652637 parameter .setSchema (schema );
@@ -759,18 +744,22 @@ private Map<ParameterId, io.swagger.v3.oas.annotations.Parameter> getApiParamete
759744 Class <?> declaringClass = method .getDeclaringClass ();
760745
761746 Set <Parameters > apiParametersDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , Parameters .class );
762- 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 ));
747+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersMap = apiParametersDoc .stream ()
748+ .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
763749
764750 Set <Parameters > apiParametersDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , Parameters .class );
765- 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 ));
751+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParametersDocDeclaringClassMap = apiParametersDocDeclaringClass .stream ()
752+ .flatMap (x -> Stream .of (x .value ())).collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
766753 apiParametersMap .putAll (apiParametersDocDeclaringClassMap );
767754
768755 Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDoc = AnnotatedElementUtils .findAllMergedAnnotations (method , io .swagger .v3 .oas .annotations .Parameter .class );
769- LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
756+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocMap = apiParameterDoc .stream ()
757+ .collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
770758 apiParametersMap .putAll (apiParameterDocMap );
771759
772760 Set <io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClass = AnnotatedElementUtils .findAllMergedAnnotations (declaringClass , io .swagger .v3 .oas .annotations .Parameter .class );
773- LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ().collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
761+ LinkedHashMap <ParameterId , io .swagger .v3 .oas .annotations .Parameter > apiParameterDocDeclaringClassMap = apiParameterDocDeclaringClass .stream ()
762+ .collect (Collectors .toMap (ParameterId ::new , x -> x , (e1 , e2 ) -> e2 , LinkedHashMap ::new ));
774763 apiParametersMap .putAll (apiParameterDocDeclaringClassMap );
775764
776765 return apiParametersMap ;
0 commit comments