@@ -156,20 +156,34 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
156156 return result .toString ();
157157 }
158158
159+ var patternMsg = (String ) prop .vendorExtensions .get ("x-pattern-message" );
160+ var sizeMsg = (String ) prop .vendorExtensions .get ("x-size-message" );
161+ var notNullMsg = (String ) prop .vendorExtensions .get ("x-not-null-message" );
162+ var minMsg = (String ) prop .vendorExtensions .get ("x-min-message" );
163+ var maxMsg = (String ) prop .vendorExtensions .get ("x-max-message" );
164+
159165 if (StringUtils .isNotEmpty (prop .pattern ) && !prop .isDate && !prop .isDateTime ) {
160- if ("email" .equals (type )) {
166+ if ("email" .equals (type ) || "email" . equalsIgnoreCase ( prop . dataFormat ) || prop . isEmail ) {
161167 result .append ("@Email(regexp = \" " );
162168 } else {
163169 result .append ("@Pattern(regexp = \" " );
164170 }
165- result .append (prop .pattern ).append ("\" ) " );
171+ result .append (prop .pattern ).append ("\" " );
172+ if (patternMsg != null ) {
173+ result .append (", message = \" " ).append (patternMsg ).append ("\" " );
174+ }
175+ result .append (") " );
166176 }
167177
168178 var containsNotEmpty = false ;
169179
170180 if (prop .minLength != null || prop .maxLength != null ) {
171181 if (prop .minLength != null && prop .minLength == 1 && prop .maxLength == null && !prop .isNullable ) {
172- result .append ("@NotEmpty " );
182+ result .append ("@NotEmpty" );
183+ if (sizeMsg != null ) {
184+ result .append ("(message = \" " ).append (sizeMsg ).append ("\" )" );
185+ }
186+ result .append (' ' );
173187 containsNotEmpty = true ;
174188 } else {
175189 result .append ("@Size(" );
@@ -182,6 +196,9 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
182196 }
183197 result .append ("max = " ).append (prop .maxLength );
184198 }
199+ if (sizeMsg != null ) {
200+ result .append (", message = \" " ).append (sizeMsg ).append ('"' );
201+ }
185202 result .append (") " );
186203 }
187204 }
@@ -201,6 +218,9 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
201218 }
202219 result .append ("max = " ).append (prop .maxItems );
203220 }
221+ if (sizeMsg != null ) {
222+ result .append (", message = \" " ).append (sizeMsg ).append ('"' );
223+ }
204224 result .append (") " );
205225 }
206226 }
@@ -211,7 +231,11 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
211231 result .append ("@Nullable " );
212232 }
213233 } else if (!containsNotEmpty ) {
214- result .append ("@NotNull " );
234+ result .append ("@NotNull" );
235+ if (notNullMsg != null ) {
236+ result .append ("(message = \" " ).append (notNullMsg ).append ("\" )" );
237+ }
238+ result .append (" " );
215239 }
216240 if (StringUtils .isNotEmpty (prop .minimum )) {
217241 try {
@@ -220,21 +244,43 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
220244 longNumber ++;
221245 }
222246 if (longNumber == 0 && StringUtils .isEmpty (prop .maximum )) {
223- result .append ("@PositiveOrZero " );
247+ result .append ("@PositiveOrZero" );
248+ if (minMsg != null ) {
249+ result .append ("(message = \" " ).append (minMsg ).append ("\" )" );
250+ }
251+ result .append (" " );
224252 } else if (longNumber == 1 && StringUtils .isEmpty (prop .maximum )) {
225- result .append ("@Positive " );
253+ result .append ("@Positive" );
254+ if (minMsg != null ) {
255+ result .append ("(message = \" " ).append (minMsg ).append ("\" )" );
256+ }
257+ result .append (" " );
226258 } else {
227- result .append ("@Min(" ).append (longNumber ).append (") " );
259+ result .append ("@Min(" );
260+ if (minMsg != null ) {
261+ result .append ("value = " );
262+ }
263+ result .append (longNumber );
264+ if (prop .isLong ) {
265+ result .append ("L" );
266+ }
267+ if (minMsg != null ) {
268+ result .append (", message = \" " ).append (minMsg ).append ("\" " );
269+ }
270+ result .append (") " );
228271 }
229272 } catch (Exception e ) {
230273 result .append ("@DecimalMin(" );
231- if (prop .exclusiveMinimum ) {
274+ if (prop .exclusiveMinimum || minMsg != null ) {
232275 result .append ("value = " );
233276 }
234277 result .append ('"' ).append (prop .minimum ).append ('"' );
235278 if (prop .exclusiveMinimum ) {
236279 result .append (", inclusive = false" );
237280 }
281+ if (minMsg != null ) {
282+ result .append (", message = \" " ).append (minMsg ).append ("\" " );
283+ }
238284 result .append (") " );
239285 }
240286 }
@@ -245,21 +291,44 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
245291 longNumber --;
246292 }
247293 if (longNumber == 0 && StringUtils .isEmpty (prop .minimum )) {
248- result .append ("@NegativeOrZero " );
294+ result .append ("@NegativeOrZero" );
295+ if (maxMsg != null ) {
296+ result .append ("(message = \" " ).append (maxMsg ).append ("\" )" );
297+ }
298+ result .append (" " );
249299 } else if (longNumber == -1 && StringUtils .isEmpty (prop .minimum )) {
250- result .append ("@Negative " );
300+ result .append ("@Negative" );
301+ if (maxMsg != null ) {
302+ result .append ("(message = \" " ).append (maxMsg ).append ("\" )" );
303+ }
304+ result .append (" " );
251305 } else {
252- result .append ("@Max(" ).append (longNumber ).append (") " );
306+ result .append ("@Max(" );
307+ if (maxMsg != null ) {
308+ result .append ("value = " );
309+ }
310+ result .append (longNumber );
311+ if (prop .isLong ) {
312+ result .append ("L" );
313+ }
314+ if (maxMsg != null ) {
315+ result .append (", message = \" " ).append (maxMsg ).append ("\" " );
316+ }
317+ result .append (") " );
318+
253319 }
254320 } catch (Exception e ) {
255321 result .append ("@DecimalMax(" );
256- if (prop .exclusiveMaximum ) {
322+ if (prop .exclusiveMaximum || maxMsg != null ) {
257323 result .append ("value = " );
258324 }
259325 result .append ('"' ).append (prop .maximum ).append ('"' );
260326 if (prop .exclusiveMaximum ) {
261327 result .append (", inclusive = false" );
262328 }
329+ if (maxMsg != null ) {
330+ result .append (", message = \" " ).append (maxMsg ).append ("\" " );
331+ }
263332 result .append (") " );
264333 }
265334 }
0 commit comments