Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit f34466c

Browse files
authored
Merge pull request #823 from linwumingshi/fix/jsr303-required-field-bug
Fix/jsr303 required field bug
2 parents f759d66 + 49564f0 commit f34466c

11 files changed

Lines changed: 279 additions & 72 deletions
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.ly.doc.constants;
2+
3+
import java.util.Set;
4+
import java.util.stream.Collectors;
5+
import java.util.stream.Stream;
6+
7+
/**
8+
* default class constants
9+
*
10+
* @author linwumingshi
11+
* @since 3.0.6
12+
*/
13+
public interface DefaultClassConstants {
14+
15+
/**
16+
* jakarta.validation.groups.Default
17+
*/
18+
String JAKARTA_VALIDATION_GROUPS_DEFAULT = "jakarta.validation.groups.Default";
19+
20+
/**
21+
* javax.validation.groups.Default
22+
*/
23+
String JAVAX_VALIDATION_GROUPS_DEFAULT = "javax.validation.groups.Default";
24+
25+
26+
/**
27+
* default class set
28+
*/
29+
Set<String> DEFAULT_CLASSES = Stream.of(
30+
JAKARTA_VALIDATION_GROUPS_DEFAULT,
31+
JAVAX_VALIDATION_GROUPS_DEFAULT
32+
).collect(Collectors.toSet());
33+
}

src/main/java/com/ly/doc/constants/DocValidatorAnnotationEnum.java

Lines changed: 49 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,97 +33,127 @@ public enum DocValidatorAnnotationEnum {
3333
/**
3434
* Spring validator annotations `@NotEmpty`
3535
*/
36-
NOT_EMPTY("NotEmpty"),
36+
NOT_EMPTY(JSRAnnotationConstants.NOT_EMPTY),
3737

3838
/**
3939
* Spring validator annotations `@NotBlank`
4040
*/
41-
NOT_BLANK("NotBlank"),
41+
NOT_BLANK(JSRAnnotationConstants.NOT_BLANK),
4242

4343
/**
4444
* Spring validator annotations `@NotNull`
4545
*/
46-
NOT_NULL("NotNull"),
46+
NOT_NULL(JSRAnnotationConstants.NOT_NULL),
4747

4848
/**
4949
* Spring validator annotations `@Null`
5050
*/
51-
NULL("Null"),
51+
NULL(JSRAnnotationConstants.NULL),
5252

5353
/**
5454
* Spring validator annotations `@AssertTrue`
5555
*/
56-
ASSERT_TRUE("AssertTrue"),
56+
ASSERT_TRUE(JSRAnnotationConstants.ASSERT_TRUE),
5757

5858
/**
5959
* Spring validator annotations `@AssertFalse`
6060
*/
61-
ASSERT_FALSE("AssertFalse"),
61+
ASSERT_FALSE(JSRAnnotationConstants.ASSERT_FALSE),
6262

6363
/**
6464
* Spring validator annotations `@Min`
6565
*/
66-
MIN("Min"),
66+
MIN(JSRAnnotationConstants.MIN),
6767

6868
/**
6969
* Spring validator annotations `@Max`
7070
*/
71-
MAX("Max"),
71+
MAX(JSRAnnotationConstants.MAX),
7272

7373
/**
7474
* Spring validator annotations `@DecimalMin`
7575
*/
76-
DECIMAL_MIN("DecimalMin"),
76+
DECIMAL_MIN(JSRAnnotationConstants.DECIMAL_MIN),
7777

7878
/**
7979
* Spring validator annotations `@DecimalMax`
8080
*/
81-
DECIMAL_MAX("DecimalMax"),
81+
DECIMAL_MAX(JSRAnnotationConstants.DECIMAL_MAX),
8282

8383
/**
8484
* Spring validator annotations `@Size`
8585
*/
86-
SIZE("Size"),
86+
SIZE(JSRAnnotationConstants.SIZE),
8787

8888
/**
8989
* Spring validator annotations `@Digits`
9090
*/
91-
DIGITS("Digits"),
91+
DIGITS(JSRAnnotationConstants.DIGITS),
9292

9393
/**
9494
* Spring validator annotations `@Past`
9595
*/
96-
PAST("Past"),
96+
PAST(JSRAnnotationConstants.PAST),
97+
98+
/**
99+
* Spring validator annotations `@PastOrPresent`
100+
*/
101+
PAST_OR_PRESENT(JSRAnnotationConstants.PAST_OR_PRESENT),
97102

98103
/**
99104
* Spring validator annotations `@Future`
100105
*/
101-
FUTURE("Future"),
106+
FUTURE(JSRAnnotationConstants.FUTURE),
107+
108+
/**
109+
* Spring validator annotations `@FutureOrPresent`
110+
*/
111+
FUTURE_OR_PRESENT(JSRAnnotationConstants.FUTURE_OR_PRESENT),
102112

103113
/**
104114
* Spring validator annotations `@Pattern`
105115
*/
106-
PATTERN("Pattern"),
116+
PATTERN(JSRAnnotationConstants.PATTERN),
117+
118+
/**
119+
* Spring validator annotations `@Positive`
120+
*/
121+
POSITIVE(JSRAnnotationConstants.POSITIVE),
122+
123+
/**
124+
* Spring validator annotations `@PositiveOrZero`
125+
*/
126+
POSITIVE_OR_ZERO(JSRAnnotationConstants.POSITIVE_OR_ZERO),
127+
128+
/**
129+
* Spring validator annotations `@Negative`
130+
*/
131+
NEGATIVE(JSRAnnotationConstants.NEGATIVE),
132+
133+
/**
134+
* Spring validator annotations `@NegativeOrZero`
135+
*/
136+
NEGATIVE_OR_ZERO(JSRAnnotationConstants.NEGATIVE_OR_ZERO),
107137

108138
/**
109139
* Spring validator annotations `@Email`
110140
*/
111-
EMAIL("Email"),
141+
EMAIL(JSRAnnotationConstants.EMAIL),
112142

113143
/**
114144
* Spring validator annotations `@Length`
115145
*/
116-
LENGTH("Length"),
146+
LENGTH(JSRAnnotationConstants.LENGTH),
117147

118148
/**
119149
* Spring validator annotations `@Range`
120150
*/
121-
RANGE("Range"),
151+
RANGE(JSRAnnotationConstants.RANGE),
122152

123153
/**
124154
* Spring validator annotations `@Validated`
125155
*/
126-
VALIDATED("Validated");
156+
VALIDATED(JSRAnnotationConstants.VALIDATED);
127157

128158
/**
129159
* annotation value

src/main/java/com/ly/doc/constants/JSRAnnotationConstants.java

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,142 @@
2424
* @author yu 2024/6/7
2525
*/
2626
public interface JSRAnnotationConstants {
27+
28+
// begin from javax.validation:validation-api
29+
/**
30+
* Spring validator annotations `@AssertFalse`
31+
*/
32+
String ASSERT_FALSE = "AssertFalse";
33+
34+
/**
35+
* Spring validator annotations `@AssertTrue`
36+
*/
37+
String ASSERT_TRUE = "AssertTrue";
38+
39+
/**
40+
* Spring validator annotations `@DecimalMax`
41+
*/
42+
String DECIMAL_MAX = "DecimalMax";
43+
44+
/**
45+
* Spring validator annotations `@DecimalMin`
46+
*/
47+
String DECIMAL_MIN = "DecimalMin";
48+
49+
/**
50+
* Spring validator annotations `@Digits`
51+
*/
52+
String DIGITS = "Digits";
53+
54+
/**
55+
* Spring validator annotations `@Email`
56+
*/
57+
String EMAIL = "Email";
58+
59+
/**
60+
* Spring validator annotations `@Future`
61+
*/
62+
String FUTURE = "Future";
63+
64+
/**
65+
* Spring validator annotations `@FutureOrPresent`
66+
*/
67+
String FUTURE_OR_PRESENT = "FutureOrPresent";
68+
69+
/**
70+
* Spring validator annotations `@Max`
71+
*/
2772
String MAX = "Max";
2873

74+
/**
75+
* Spring validator annotations `@Min`
76+
*/
2977
String MIN = "Min";
3078

79+
/**
80+
* Spring validator annotations `@Negative`
81+
*/
82+
String NEGATIVE = "Negative";
83+
84+
/**
85+
* Spring validator annotations `@NegativeOrZero`
86+
*/
87+
String NEGATIVE_OR_ZERO = "NegativeOrZero";
88+
89+
/**
90+
* Spring validator annotations `@NotBlank`
91+
*/
92+
String NOT_BLANK = "NotBlank";
93+
94+
/**
95+
* Spring validator annotations `@NotEmpty`
96+
*/
97+
String NOT_EMPTY = "NotEmpty";
98+
99+
/**
100+
* Spring validator annotations `@NotNull`
101+
*/
102+
String NOT_NULL = "NotNull";
103+
104+
/**
105+
* Spring validator annotations `@Null`
106+
*/
107+
String NULL = "Null";
108+
109+
/**
110+
* Spring validator annotations `@Past`
111+
*/
112+
String PAST = "Past";
113+
114+
/**
115+
* Spring validator annotations `@PastOrPresent`
116+
*/
117+
String PAST_OR_PRESENT = "PastOrPresent";
118+
119+
/**
120+
* Spring validator annotations `@Pattern`
121+
*/
122+
String PATTERN = "Pattern";
123+
124+
/**
125+
* Spring validator annotations `@Positive`
126+
*/
127+
String POSITIVE = "Positive";
128+
129+
/**
130+
* Spring validator annotations `@PositiveOrZero`
131+
*/
132+
String POSITIVE_OR_ZERO = "PositiveOrZero";
133+
134+
/**
135+
* Spring validator annotations `@Size`
136+
*/
31137
String SIZE = "Size";
32138

139+
// end from javax.validation:validation-api
140+
141+
// begin from org.hibernate.validator:hibernate-validator
142+
/**
143+
* Spring validator annotations `@Length`
144+
*/
33145
String LENGTH = "Length";
146+
147+
/**
148+
* Spring validator annotations `@Range`
149+
*/
150+
String RANGE = "Range";
151+
152+
// end from org.hibernate.validator:hibernate-validator
153+
154+
/**
155+
* java annotations `@Valid`
156+
* jakarta.validation.Valid
157+
* javax.validation.Valid
158+
*/
159+
String VALID = "Valid";
160+
161+
/**
162+
* Spring validator annotations `@Validated`
163+
*/
164+
String VALIDATED = "Validated";
34165
}

src/main/java/com/ly/doc/constants/ValidatorAnnotations.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,41 @@
2222

2323
/**
2424
* @author yu 2019/12/22.
25+
*
26+
* @see JSRAnnotationConstants
2527
*/
28+
@Deprecated
2629
public interface ValidatorAnnotations {
2730

28-
String VALID = "Valid";
31+
/**
32+
* java annotations `@Valid`
33+
* jakarta.validation.Valid
34+
* javax.validation.Valid
35+
*/
36+
String VALID = JSRAnnotationConstants.VALID;
2937

3038
/**
3139
* Spring validator annotations `@NotEmpty`
3240
*/
33-
String NOT_EMPTY = "NotEmpty";
41+
String NOT_EMPTY = JSRAnnotationConstants.NOT_EMPTY;
3442

3543
/**
3644
* Spring validator annotations `@NotBlank`
3745
*/
38-
String NOT_BLANK = "NotBlank";
46+
String NOT_BLANK = JSRAnnotationConstants.NOT_BLANK;
3947

4048
/**
4149
* Spring validator annotations `@NotNull`
4250
*/
43-
String NOT_NULL = "NotNull";
51+
String NOT_NULL = JSRAnnotationConstants.NOT_NULL;
4452

4553
/**
4654
* Spring validator annotations `@Null`
4755
*/
48-
String NULL= "Null";
56+
String NULL = JSRAnnotationConstants.NULL;
4957

50-
String VALIDATED = "Validated";
58+
/**
59+
* Spring validator annotations `@Validated`
60+
*/
61+
String VALIDATED = JSRAnnotationConstants.VALIDATED;
5162
}

src/main/java/com/ly/doc/helper/FormDataBuildHelper.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
import java.util.*;
2424

25-
import com.ly.doc.constants.DocGlobalConstants;
26-
import com.ly.doc.constants.ParamTypeConstants;
27-
import com.ly.doc.constants.ValidatorAnnotations;
25+
import com.ly.doc.constants.*;
2826
import com.ly.doc.model.ApiConfig;
2927
import com.ly.doc.model.CustomField;
3028
import com.ly.doc.model.DocJavaField;
@@ -34,7 +32,6 @@
3432
import com.power.common.util.RandomUtil;
3533
import com.power.common.util.StringUtil;
3634
import com.ly.doc.builder.ProjectDocConfigBuilder;
37-
import com.ly.doc.constants.DocTags;
3835
import com.thoughtworks.qdox.model.JavaAnnotation;
3936
import com.thoughtworks.qdox.model.JavaClass;
4037
import com.thoughtworks.qdox.model.JavaField;
@@ -119,7 +116,7 @@ public static List<FormData> getFormData(String className, Map<String, String> r
119116
List<JavaAnnotation> javaAnnotations = docField.getAnnotations();
120117
for (JavaAnnotation annotation : javaAnnotations) {
121118
String simpleAnnotationName = annotation.getType().getValue();
122-
if (ValidatorAnnotations.NULL.equals(simpleAnnotationName)) {
119+
if (JSRAnnotationConstants.NULL.equals(simpleAnnotationName)) {
123120
if (CollectionUtil.isEmpty(groupClasses)) {
124121
continue out;
125122
}

0 commit comments

Comments
 (0)