40
40
import javax .validation .constraints .DecimalMin ;
41
41
import javax .validation .constraints .Max ;
42
42
import javax .validation .constraints .Min ;
43
- import javax .validation .constraints .NotNull ;
44
43
import javax .validation .constraints .Pattern ;
45
44
import javax .validation .constraints .Size ;
46
45
@@ -96,17 +95,17 @@ public abstract class AbstractRequestService {
96
95
* The constant ANNOTATIONS_FOR_REQUIRED.
97
96
*/
98
97
// using string litterals to support both validation-api v1 and v2
99
- private static final String [] ANNOTATIONS_FOR_REQUIRED = { NotNull . class . getName () , "javax.validation.constraints. NotBlank" , "javax.validation.constraints. NotEmpty" };
98
+ private static final String [] ANNOTATIONS_FOR_REQUIRED = {" NotNull" , "NonNull" , " NotBlank" , "NotEmpty" };
100
99
101
100
/**
102
101
* The constant POSITIVE_OR_ZERO.
103
102
*/
104
- private static final String POSITIVE_OR_ZERO = "javax.validation.constraints. PositiveOrZero" ;
103
+ private static final String POSITIVE_OR_ZERO = "PositiveOrZero" ;
105
104
106
105
/**
107
106
* The constant NEGATIVE_OR_ZERO.
108
107
*/
109
- private static final String NEGATIVE_OR_ZERO = "javax.validation.constraints. NegativeOrZero" ;
108
+ private static final String NEGATIVE_OR_ZERO = "NegativeOrZero" ;
110
109
111
110
static {
112
111
PARAM_TYPES_TO_IGNORE .add (WebRequest .class );
@@ -171,8 +170,7 @@ protected AbstractRequestService(GenericParameterService parameterBuilder, Reque
171
170
this .parameterBuilder = parameterBuilder ;
172
171
this .requestBodyService = requestBodyService ;
173
172
this .operationService = operationService ;
174
- if (parameterCustomizers .isPresent ())
175
- parameterCustomizers .get ().removeIf (Objects ::isNull );
173
+ parameterCustomizers .ifPresent (customizers -> customizers .removeIf (Objects ::isNull ));
176
174
this .parameterCustomizers = parameterCustomizers ;
177
175
this .localSpringDocParameterNameDiscoverer = localSpringDocParameterNameDiscoverer ;
178
176
}
@@ -478,7 +476,7 @@ private Parameter buildParam(ParameterInfo parameterInfo, Components components,
478
476
public void applyBeanValidatorAnnotations (final Parameter parameter , final List <Annotation > annotations ) {
479
477
Map <String , Annotation > annos = new HashMap <>();
480
478
if (annotations != null )
481
- annotations .forEach (annotation -> annos .put (annotation .annotationType ().getName (), annotation ));
479
+ annotations .forEach (annotation -> annos .put (annotation .annotationType ().getSimpleName (), annotation ));
482
480
boolean annotationExists = Arrays .stream (ANNOTATIONS_FOR_REQUIRED ).anyMatch (annos ::containsKey );
483
481
if (annotationExists )
484
482
parameter .setRequired (true );
@@ -497,7 +495,7 @@ public void applyBeanValidatorAnnotations(final RequestBody requestBody, final L
497
495
Map <String , Annotation > annos = new HashMap <>();
498
496
boolean requestBodyRequired = false ;
499
497
if (!CollectionUtils .isEmpty (annotations )) {
500
- annotations .forEach (annotation -> annos .put (annotation .annotationType ().getName (), annotation ));
498
+ annotations .forEach (annotation -> annos .put (annotation .annotationType ().getSimpleName (), annotation ));
501
499
requestBodyRequired = annotations .stream ()
502
500
.filter (annotation -> org .springframework .web .bind .annotation .RequestBody .class .equals (annotation .annotationType ()))
503
501
.anyMatch (annotation -> ((org .springframework .web .bind .annotation .RequestBody ) annotation ).required ());
@@ -520,8 +518,8 @@ public void applyBeanValidatorAnnotations(final RequestBody requestBody, final L
520
518
* @param schema the schema
521
519
*/
522
520
private void calculateSize (Map <String , Annotation > annos , Schema <?> schema ) {
523
- if (annos .containsKey (Size .class .getName ())) {
524
- Size size = (Size ) annos .get (Size .class .getName ());
521
+ if (annos .containsKey (Size .class .getSimpleName ())) {
522
+ Size size = (Size ) annos .get (Size .class .getSimpleName ());
525
523
if (OPENAPI_ARRAY_TYPE .equals (schema .getType ())) {
526
524
schema .setMinItems (size .min ());
527
525
schema .setMaxItems (size .max ());
@@ -588,35 +586,35 @@ private Map<String, io.swagger.v3.oas.annotations.Parameter> getApiParameters(Me
588
586
* @param schema the schema
589
587
*/
590
588
private void applyValidationsToSchema (Map <String , Annotation > annos , Schema <?> schema ) {
591
- if (annos .containsKey (Min .class .getName ())) {
592
- Min min = (Min ) annos .get (Min .class .getName ());
589
+ if (annos .containsKey (Min .class .getSimpleName ())) {
590
+ Min min = (Min ) annos .get (Min .class .getSimpleName ());
593
591
schema .setMinimum (BigDecimal .valueOf (min .value ()));
594
592
}
595
- if (annos .containsKey (Max .class .getName ())) {
596
- Max max = (Max ) annos .get (Max .class .getName ());
593
+ if (annos .containsKey (Max .class .getSimpleName ())) {
594
+ Max max = (Max ) annos .get (Max .class .getSimpleName ());
597
595
schema .setMaximum (BigDecimal .valueOf (max .value ()));
598
596
}
599
597
calculateSize (annos , schema );
600
- if (annos .containsKey (DecimalMin .class .getName ())) {
601
- DecimalMin min = (DecimalMin ) annos .get (DecimalMin .class .getName ());
598
+ if (annos .containsKey (DecimalMin .class .getSimpleName ())) {
599
+ DecimalMin min = (DecimalMin ) annos .get (DecimalMin .class .getSimpleName ());
602
600
if (min .inclusive ())
603
601
schema .setMinimum (BigDecimal .valueOf (Double .parseDouble (min .value ())));
604
602
else
605
- schema .setExclusiveMinimum (! min . inclusive () );
603
+ schema .setExclusiveMinimum (true );
606
604
}
607
- if (annos .containsKey (DecimalMax .class .getName ())) {
608
- DecimalMax max = (DecimalMax ) annos .get (DecimalMax .class .getName ());
605
+ if (annos .containsKey (DecimalMax .class .getSimpleName ())) {
606
+ DecimalMax max = (DecimalMax ) annos .get (DecimalMax .class .getSimpleName ());
609
607
if (max .inclusive ())
610
608
schema .setMaximum (BigDecimal .valueOf (Double .parseDouble (max .value ())));
611
609
else
612
- schema .setExclusiveMaximum (! max . inclusive () );
610
+ schema .setExclusiveMaximum (true );
613
611
}
614
612
if (annos .containsKey (POSITIVE_OR_ZERO ))
615
613
schema .setMinimum (BigDecimal .ZERO );
616
614
if (annos .containsKey (NEGATIVE_OR_ZERO ))
617
615
schema .setMaximum (BigDecimal .ZERO );
618
- if (annos .containsKey (Pattern .class .getName ())) {
619
- Pattern pattern = (Pattern ) annos .get (Pattern .class .getName ());
616
+ if (annos .containsKey (Pattern .class .getSimpleName ())) {
617
+ Pattern pattern = (Pattern ) annos .get (Pattern .class .getSimpleName ());
620
618
schema .setPattern (pattern .regexp ());
621
619
}
622
620
}
0 commit comments