@@ -1495,59 +1495,54 @@ protected void applyBeanValidatorAnnotations(Schema property, Annotation[] annot
1495
1495
}
1496
1496
}
1497
1497
if (annos .containsKey ("javax.validation.constraints.Min" )) {
1498
- if ("integer" . equals (property . getType ()) || "number" . equals ( property . getType () )) {
1498
+ if (isNumberSchema (property )) {
1499
1499
Min min = (Min ) annos .get ("javax.validation.constraints.Min" );
1500
1500
property .setMinimum (new BigDecimal (min .value ()));
1501
1501
}
1502
1502
}
1503
1503
if (annos .containsKey ("javax.validation.constraints.Max" )) {
1504
- if ("integer" . equals (property . getType ()) || "number" . equals ( property . getType () )) {
1504
+ if (isNumberSchema (property )) {
1505
1505
Max max = (Max ) annos .get ("javax.validation.constraints.Max" );
1506
1506
property .setMaximum (new BigDecimal (max .value ()));
1507
1507
}
1508
1508
}
1509
1509
if (annos .containsKey ("javax.validation.constraints.Size" )) {
1510
1510
Size size = (Size ) annos .get ("javax.validation.constraints.Size" );
1511
- if ("integer" . equals (property . getType ()) || "number" . equals ( property . getType () )) {
1511
+ if (isNumberSchema (property )) {
1512
1512
property .setMinimum (new BigDecimal (size .min ()));
1513
1513
property .setMaximum (new BigDecimal (size .max ()));
1514
- } else if ( property instanceof StringSchema ) {
1515
- StringSchema sp = ( StringSchema ) property ;
1516
- sp . minLength (Integer .valueOf (size .min ()));
1517
- sp . maxLength (Integer .valueOf (size .max ()));
1518
- } else if ( property instanceof ArraySchema ) {
1519
- ArraySchema sp = ( ArraySchema ) property ;
1520
- sp .setMinItems (size .min ());
1521
- sp .setMaxItems (size .max ());
1514
+ }
1515
+ if ( isStringSchema ( property )) {
1516
+ property . setMinLength (Integer .valueOf (size .min ()));
1517
+ property . setMaxLength (Integer .valueOf (size .max ()));
1518
+ }
1519
+ if ( isArraySchema ( property )) {
1520
+ property .setMinItems (size .min ());
1521
+ property .setMaxItems (size .max ());
1522
1522
}
1523
1523
}
1524
1524
if (annos .containsKey ("javax.validation.constraints.DecimalMin" )) {
1525
1525
DecimalMin min = (DecimalMin ) annos .get ("javax.validation.constraints.DecimalMin" );
1526
- if (property instanceof NumberSchema ) {
1527
- NumberSchema ap = (NumberSchema ) property ;
1528
- ap .setMinimum (new BigDecimal (min .value ()));
1529
- ap .setExclusiveMinimum (!min .inclusive ());
1526
+ if (isNumberSchema (property )) {
1527
+ property .setMinimum (new BigDecimal (min .value ()));
1528
+ property .setExclusiveMinimum (!min .inclusive ());
1530
1529
}
1531
1530
}
1532
1531
if (annos .containsKey ("javax.validation.constraints.DecimalMax" )) {
1533
1532
DecimalMax max = (DecimalMax ) annos .get ("javax.validation.constraints.DecimalMax" );
1534
- if (property instanceof NumberSchema ) {
1535
- NumberSchema ap = (NumberSchema ) property ;
1536
- ap .setMaximum (new BigDecimal (max .value ()));
1537
- ap .setExclusiveMaximum (!max .inclusive ());
1533
+ if (isNumberSchema (property )) {
1534
+ property .setMaximum (new BigDecimal (max .value ()));
1535
+ property .setExclusiveMaximum (!max .inclusive ());
1538
1536
}
1539
1537
}
1540
1538
if (annos .containsKey ("javax.validation.constraints.Pattern" )) {
1541
1539
Pattern pattern = (Pattern ) annos .get ("javax.validation.constraints.Pattern" );
1542
-
1543
- if (property instanceof StringSchema ) {
1540
+ if (isStringSchema (property )) {
1544
1541
property .setPattern (pattern .regexp ());
1545
1542
}
1546
-
1547
- if (property .getItems () != null && property .getItems () instanceof StringSchema ) {
1543
+ if (property .getItems () != null && isStringSchema (property .getItems ())) {
1548
1544
property .getItems ().setPattern (pattern .regexp ());
1549
1545
}
1550
-
1551
1546
}
1552
1547
}
1553
1548
@@ -3009,6 +3004,18 @@ protected boolean isObjectSchema(Schema schema) {
3009
3004
return (schema .getTypes () != null && schema .getTypes ().contains ("object" )) || "object" .equals (schema .getType ()) || (schema .getType () == null && schema .getProperties () != null && !schema .getProperties ().isEmpty ());
3010
3005
}
3011
3006
3007
+ protected boolean isArraySchema (Schema schema ){
3008
+ return "array" .equals (schema .getType ()) || (schema .getTypes () != null && schema .getTypes ().contains ("array" ));
3009
+ }
3010
+
3011
+ protected boolean isStringSchema (Schema schema ){
3012
+ return "string" .equals (schema .getType ()) || (schema .getTypes () != null && schema .getTypes ().contains ("string" ));
3013
+ }
3014
+
3015
+ protected boolean isNumberSchema (Schema schema ){
3016
+ return "number" .equals (schema .getType ()) || (schema .getTypes () != null && schema .getTypes ().contains ("number" )) || "integer" .equals (schema .getType ()) || (schema .getTypes () != null && schema .getTypes ().contains ("integer" ));
3017
+ }
3018
+
3012
3019
protected Schema buildRefSchemaIfObject (Schema schema , ModelConverterContext context ) {
3013
3020
if (schema == null ) {
3014
3021
return null ;
0 commit comments