11package org .springdoc .core .utils ;
22
3+ import java .lang .annotation .Annotation ;
4+ import java .lang .reflect .Field ;
5+ import java .math .BigDecimal ;
6+ import java .util .Arrays ;
7+ import java .util .Collection ;
8+ import java .util .HashSet ;
9+ import java .util .List ;
10+ import java .util .Optional ;
11+ import java .util .OptionalDouble ;
12+ import java .util .OptionalInt ;
13+ import java .util .OptionalLong ;
14+ import java .util .Set ;
15+ import java .util .stream .Collectors ;
16+
317import io .swagger .v3 .oas .annotations .Parameter ;
18+ import io .swagger .v3 .oas .annotations .media .Schema .RequiredMode ;
419import io .swagger .v3 .oas .models .media .Schema ;
5- import jakarta .validation .constraints .*;
20+ import jakarta .validation .constraints .DecimalMax ;
21+ import jakarta .validation .constraints .DecimalMin ;
22+ import jakarta .validation .constraints .Max ;
23+ import jakarta .validation .constraints .Min ;
24+ import jakarta .validation .constraints .NegativeOrZero ;
25+ import jakarta .validation .constraints .Pattern ;
26+ import jakarta .validation .constraints .PositiveOrZero ;
27+ import jakarta .validation .constraints .Size ;
628import kotlin .reflect .KProperty ;
729import kotlin .reflect .jvm .ReflectJvmMapping ;
30+
831import org .springframework .core .KotlinDetector ;
932import org .springframework .lang .Nullable ;
1033
11- import java .lang .annotation .Annotation ;
12- import java .lang .reflect .Field ;
13- import java .math .BigDecimal ;
14- import java .util .*;
15- import java .util .stream .Collectors ;
16-
1734import static org .springdoc .core .utils .Constants .OPENAPI_ARRAY_TYPE ;
1835import static org .springdoc .core .utils .Constants .OPENAPI_STRING_TYPE ;
1936
@@ -77,7 +94,7 @@ public static boolean swaggerVisible(@Nullable io.swagger.v3.oas.annotations.med
7794 * @param schema the schema
7895 * @param parameter the parameter
7996 * @return the boolean or {@code null}
80- * @see io.swagger.v3.oas.annotations. Parameter#required()
97+ * @see Parameter#required()
8198 * @see io.swagger.v3.oas.annotations.media.Schema#required()
8299 * @see io.swagger.v3.oas.annotations.media.Schema#requiredMode()
83100 */
@@ -89,10 +106,10 @@ public static Boolean swaggerRequired(@Nullable io.swagger.v3.oas.annotations.me
89106 }
90107 if (schema != null ) {
91108 if (schema .required ()
92- || schema .requiredMode () == io . swagger . v3 . oas . annotations . media . Schema . RequiredMode .REQUIRED ) {
109+ || schema .requiredMode () == RequiredMode .REQUIRED ) {
93110 return true ;
94111 }
95- if (schema .requiredMode () == io . swagger . v3 . oas . annotations . media . Schema . RequiredMode .NOT_REQUIRED ) {
112+ if (schema .requiredMode () == RequiredMode .NOT_REQUIRED ) {
96113 return false ;
97114 }
98115 }
@@ -146,7 +163,7 @@ public static boolean fieldNullable(Field field) {
146163 * @param schema the schema
147164 * @param parameter the parameter
148165 * @return the boolean
149- * @see io.swagger.v3.oas.annotations. Parameter#required()
166+ * @see Parameter#required()
150167 * @see io.swagger.v3.oas.annotations.media.Schema#required()
151168 * @see io.swagger.v3.oas.annotations.media.Schema#requiredMode()
152169 */
@@ -203,11 +220,14 @@ public static void applyValidationsToSchema(Schema<?> schema, List<Annotation> a
203220 }
204221 }
205222 if (annotationName .equals (Size .class .getSimpleName ())) {
206- if (OPENAPI_ARRAY_TYPE .equals (schema .getType ())) {
223+ String type = schema .getType ();
224+ if (type == null && schema .getTypes () != null && schema .getTypes ().size () == 1 )
225+ type = schema .getTypes ().iterator ().next ();
226+ if (OPENAPI_ARRAY_TYPE .equals (type )) {
207227 schema .setMinItems (((Size ) anno ).min ());
208228 schema .setMaxItems (((Size ) anno ).max ());
209229 }
210- else if (OPENAPI_STRING_TYPE .equals (schema . getType () )) {
230+ else if (OPENAPI_STRING_TYPE .equals (type )) {
211231 schema .setMinLength (((Size ) anno ).min ());
212232 schema .setMaxLength (((Size ) anno ).max ());
213233 }
0 commit comments