@@ -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 (prop .isEmail ) {
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 }
@@ -212,7 +232,11 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
212232 result .append ("@Nullable " );
213233 }
214234 } else if (!containsNotEmpty ) {
215- result .append ("@NotNull " );
235+ result .append ("@NotNull" );
236+ if (notNullMsg != null ) {
237+ result .append ("(message = \" " ).append (notNullMsg ).append ("\" )" );
238+ }
239+ result .append (" " );
216240 }
217241 }
218242 if (StringUtils .isNotEmpty (prop .minimum )) {
@@ -222,21 +246,43 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
222246 longNumber ++;
223247 }
224248 if (longNumber == 0 && StringUtils .isEmpty (prop .maximum )) {
225- result .append ("@PositiveOrZero " );
249+ result .append ("@PositiveOrZero" );
250+ if (minMsg != null ) {
251+ result .append ("(message = \" " ).append (minMsg ).append ("\" )" );
252+ }
253+ result .append (" " );
226254 } else if (longNumber == 1 && StringUtils .isEmpty (prop .maximum )) {
227- result .append ("@Positive " );
255+ result .append ("@Positive" );
256+ if (minMsg != null ) {
257+ result .append ("(message = \" " ).append (minMsg ).append ("\" )" );
258+ }
259+ result .append (" " );
228260 } else {
229- result .append ("@Min(" ).append (longNumber ).append (") " );
261+ result .append ("@Min(" );
262+ if (minMsg != null ) {
263+ result .append ("value = " );
264+ }
265+ result .append (longNumber );
266+ if (prop .isLong ) {
267+ result .append ("L" );
268+ }
269+ if (minMsg != null ) {
270+ result .append (", message = \" " ).append (minMsg ).append ("\" " );
271+ }
272+ result .append (") " );
230273 }
231274 } catch (Exception e ) {
232275 result .append ("@DecimalMin(" );
233- if (prop .exclusiveMinimum ) {
276+ if (prop .exclusiveMinimum || minMsg != null ) {
234277 result .append ("value = " );
235278 }
236279 result .append ('"' ).append (prop .minimum ).append ('"' );
237280 if (prop .exclusiveMinimum ) {
238281 result .append (", inclusive = false" );
239282 }
283+ if (minMsg != null ) {
284+ result .append (", message = \" " ).append (minMsg ).append ("\" " );
285+ }
240286 result .append (") " );
241287 }
242288 }
@@ -247,21 +293,44 @@ private static String genericAnnotations(CodegenProperty prop, boolean isGenerat
247293 longNumber --;
248294 }
249295 if (longNumber == 0 && StringUtils .isEmpty (prop .minimum )) {
250- result .append ("@NegativeOrZero " );
296+ result .append ("@NegativeOrZero" );
297+ if (maxMsg != null ) {
298+ result .append ("(message = \" " ).append (maxMsg ).append ("\" )" );
299+ }
300+ result .append (" " );
251301 } else if (longNumber == -1 && StringUtils .isEmpty (prop .minimum )) {
252- result .append ("@Negative " );
302+ result .append ("@Negative" );
303+ if (maxMsg != null ) {
304+ result .append ("(message = \" " ).append (maxMsg ).append ("\" )" );
305+ }
306+ result .append (" " );
253307 } else {
254- result .append ("@Max(" ).append (longNumber ).append (") " );
308+ result .append ("@Max(" );
309+ if (maxMsg != null ) {
310+ result .append ("value = " );
311+ }
312+ result .append (longNumber );
313+ if (prop .isLong ) {
314+ result .append ("L" );
315+ }
316+ if (maxMsg != null ) {
317+ result .append (", message = \" " ).append (maxMsg ).append ("\" " );
318+ }
319+ result .append (") " );
320+
255321 }
256322 } catch (Exception e ) {
257323 result .append ("@DecimalMax(" );
258- if (prop .exclusiveMaximum ) {
324+ if (prop .exclusiveMaximum || maxMsg != null ) {
259325 result .append ("value = " );
260326 }
261327 result .append ('"' ).append (prop .maximum ).append ('"' );
262328 if (prop .exclusiveMaximum ) {
263329 result .append (", inclusive = false" );
264330 }
331+ if (maxMsg != null ) {
332+ result .append (", message = \" " ).append (maxMsg ).append ("\" " );
333+ }
265334 result .append (") " );
266335 }
267336 }
0 commit comments