Skip to content

Commit 5e6530a

Browse files
committed
Raise minimum versions of validation dependencies
Closes gh-956
1 parent 4fb5b87 commit 5e6530a

File tree

6 files changed

+39
-38
lines changed

6 files changed

+39
-38
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ nohttp {
3535
ext {
3636
javadocLinks = [
3737
"https://docs.spring.io/spring-framework/docs/$springFrameworkVersion/javadoc-api/",
38-
"https://docs.jboss.org/hibernate/validator/7.0/api/",
39-
"https://jakarta.ee/specifications/bean-validation/3.0/apidocs/"
38+
"https://docs.jboss.org/hibernate/validator/9.0/api/",
39+
"https://jakarta.ee/specifications/bean-validation/3.1/apidocs/"
4040
] as String[]
4141
}
4242

docs/src/docs/asciidoc/documenting-your-api.adoc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ To take complete control of constraint resolution, you can use your own implemen
11461146
[[documenting-your-api-constraints-describing]]
11471147
==== Describing Constraints
11481148

1149-
Default descriptions are provided for all of Bean Validation 3.0's constraints:
1149+
Default descriptions are provided for all of Bean Validation 3.1's constraints:
11501150

11511151
* `AssertFalse`
11521152
* `AssertTrue`

spring-restdocs-core/src/main/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolver.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -64,7 +64,7 @@
6464
* {@code jakarta.validation.constraints.NotNull} is
6565
* {@code jakarta.validation.constraints.NotNull.description}.
6666
* <p>
67-
* Default descriptions are provided for Bean Validation 2.0's constraints:
67+
* Default descriptions are provided for all of Bean Validation 3.1's constraints:
6868
*
6969
* <ul>
7070
* <li>{@link AssertFalse}
@@ -92,20 +92,18 @@
9292
* </ul>
9393
*
9494
* <p>
95-
* Default descriptions are also provided for Hibernate Validator's constraints:
95+
* Default descriptions are also provided for the following Hibernate Validator
96+
* constraints:
9697
*
9798
* <ul>
9899
* <li>{@link CodePointLength}
99100
* <li>{@link CreditCardNumber}
100101
* <li>{@link Currency}
101102
* <li>{@link EAN}
102-
* <li>{@link org.hibernate.validator.constraints.Email}
103103
* <li>{@link Length}
104104
* <li>{@link LuhnCheck}
105105
* <li>{@link Mod10Check}
106106
* <li>{@link Mod11Check}
107-
* <li>{@link org.hibernate.validator.constraints.NotBlank}
108-
* <li>{@link org.hibernate.validator.constraints.NotEmpty}
109107
* <li>{@link Range}
110108
* <li>{@link URL}
111109
* </ul>

spring-restdocs-core/src/main/resources/org/springframework/restdocs/constraints/DefaultConstraintDescriptions.properties

-3
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@ org.hibernate.validator.constraints.CodePointLength.description=Code point lengt
2424
org.hibernate.validator.constraints.CreditCardNumber.description=Must be a well-formed credit card number
2525
org.hibernate.validator.constraints.Currency.description=Must be in an accepted currency unit (${value})
2626
org.hibernate.validator.constraints.EAN.description=Must be a well-formed ${type} number
27-
org.hibernate.validator.constraints.Email.description=Must be a well-formed email address
2827
org.hibernate.validator.constraints.Length.description=Length must be between ${min} and ${max} inclusive
2928
org.hibernate.validator.constraints.LuhnCheck.description=Must pass the Luhn Modulo 10 checksum algorithm
3029
org.hibernate.validator.constraints.Mod10Check.description=Must pass the Mod10 checksum algorithm
3130
org.hibernate.validator.constraints.Mod11Check.description=Must pass the Mod11 checksum algorithm
32-
org.hibernate.validator.constraints.NotBlank.description=Must not be blank
33-
org.hibernate.validator.constraints.NotEmpty.description=Must not be empty
3431
org.hibernate.validator.constraints.Range.description=Must be at least ${min} and at most ${max}
3532
org.hibernate.validator.constraints.URL.description=Must be a well-formed URL

spring-restdocs-core/src/test/java/org/springframework/restdocs/constraints/ResourceBundleConstraintDescriptionResolverTests.java

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2024 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,9 +21,11 @@
2121
import java.net.URL;
2222
import java.util.Collections;
2323
import java.util.Date;
24+
import java.util.HashSet;
2425
import java.util.List;
2526
import java.util.ListResourceBundle;
2627
import java.util.ResourceBundle;
28+
import java.util.Set;
2729

2830
import javax.money.MonetaryAmount;
2931

@@ -61,7 +63,11 @@
6163
import org.junit.Test;
6264

6365
import org.springframework.core.annotation.AnnotationUtils;
66+
import org.springframework.core.io.ClassPathResource;
67+
import org.springframework.core.io.Resource;
68+
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
6469
import org.springframework.util.Assert;
70+
import org.springframework.util.ClassUtils;
6571
import org.springframework.util.ReflectionUtils;
6672

6773
import static org.assertj.core.api.Assertions.assertThat;
@@ -180,12 +186,6 @@ public void defaultMessageEmail() {
180186
assertThat(constraintDescriptionForField("email")).isEqualTo("Must be a well-formed email address");
181187
}
182188

183-
@Test
184-
public void defaultMessageEmailHibernateValidator() {
185-
assertThat(constraintDescriptionForField("emailHibernateValidator"))
186-
.isEqualTo("Must be a well-formed email address");
187-
}
188-
189189
@Test
190190
public void defaultMessageLength() {
191191
assertThat(constraintDescriptionForField("length")).isEqualTo("Length must be between 2 and 10 inclusive");
@@ -222,11 +222,6 @@ public void defaultMessageNotBlank() {
222222
assertThat(constraintDescriptionForField("notBlank")).isEqualTo("Must not be blank");
223223
}
224224

225-
@Test
226-
public void defaultMessageNotBlankHibernateValidator() {
227-
assertThat(constraintDescriptionForField("notBlankHibernateValidator")).isEqualTo("Must not be blank");
228-
}
229-
230225
@Test
231226
public void defaultMessageNotEmpty() {
232227
assertThat(constraintDescriptionForField("notEmpty")).isEqualTo("Must not be empty");
@@ -298,6 +293,29 @@ protected Object[][] getContents() {
298293
assertThat(description).isEqualTo("Not null");
299294
}
300295

296+
@Test
297+
public void allBeanValidationConstraintsAreTested() throws Exception {
298+
PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
299+
Resource[] resources = resolver.getResources("jakarta/validation/constraints/*.class");
300+
Set<Class<?>> beanValidationConstraints = new HashSet<>();
301+
for (Resource resource : resources) {
302+
String className = ClassUtils.convertResourcePathToClassName(((ClassPathResource) resource).getPath());
303+
if (className.endsWith(".class")) {
304+
className = className.substring(0, className.length() - 6);
305+
}
306+
Class<?> type = Class.forName(className);
307+
if (type.isAnnotation() && type.isAnnotationPresent(jakarta.validation.Constraint.class)) {
308+
beanValidationConstraints.add(type);
309+
}
310+
}
311+
ReflectionUtils.doWithFields(Constrained.class, (field) -> {
312+
for (Annotation annotation : field.getAnnotations()) {
313+
beanValidationConstraints.remove(annotation.annotationType());
314+
}
315+
});
316+
assertThat(beanValidationConstraints).isEmpty();
317+
}
318+
301319
private String constraintDescriptionForField(String name) {
302320
return this.resolver.resolveDescription(getConstraintFromField(name));
303321
}
@@ -372,10 +390,6 @@ private static final class Constrained {
372390
@Email
373391
private String email;
374392

375-
@SuppressWarnings("deprecation")
376-
@org.hibernate.validator.constraints.Email
377-
private String emailHibernateValidator;
378-
379393
@Length(min = 2, max = 10)
380394
private String length;
381395

@@ -397,17 +411,9 @@ private static final class Constrained {
397411
@NotBlank
398412
private String notBlank;
399413

400-
@SuppressWarnings("deprecation")
401-
@org.hibernate.validator.constraints.NotBlank
402-
private String notBlankHibernateValidator;
403-
404414
@NotEmpty
405415
private String notEmpty;
406416

407-
@SuppressWarnings("deprecation")
408-
@org.hibernate.validator.constraints.NotEmpty
409-
private String notEmptyHibernateValidator;
410-
411417
@Positive
412418
private int positive;
413419

spring-restdocs-platform/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ dependencies {
1010
constraints {
1111
api("com.samskivert:jmustache:$jmustacheVersion")
1212
api("jakarta.servlet:jakarta.servlet-api:6.0.0")
13-
api("jakarta.validation:jakarta.validation-api:3.0.0")
13+
api("jakarta.validation:jakarta.validation-api:3.1.0")
1414
api("junit:junit:4.13.1")
1515
api("org.apache.pdfbox:pdfbox:2.0.27")
1616
api("org.apache.tomcat.embed:tomcat-embed-core:10.1.1")
@@ -20,7 +20,7 @@ dependencies {
2020
api("org.assertj:assertj-core:3.23.1")
2121
api("org.hamcrest:hamcrest-core:1.3")
2222
api("org.hamcrest:hamcrest-library:1.3")
23-
api("org.hibernate.validator:hibernate-validator:8.0.0.Final")
23+
api("org.hibernate.validator:hibernate-validator:9.0.0.CR1")
2424
api("org.javamoney:moneta:1.4.2")
2525
api("org.junit.jupiter:junit-jupiter-api:5.0.0")
2626
}

0 commit comments

Comments
 (0)