1515import io .swagger .v3 .oas .models .media .StringSchema ;
1616import org .testng .annotations .Test ;
1717
18+ import javax .validation .constraints .NotBlank ;
19+ import javax .validation .constraints .NotEmpty ;
20+ import javax .validation .constraints .NotNull ;
21+ import javax .validation .constraints .Size ;
1822import java .util .Date ;
1923import java .util .List ;
2024import java .util .Map ;
25+ import java .util .Set ;
2126
2227import static org .testng .Assert .assertEquals ;
2328import static org .testng .Assert .assertFalse ;
@@ -114,6 +119,8 @@ public void testRequiredProperty() {
114119 assertTrue (model .getRequired ().contains ("modeRequired" ));
115120 assertFalse (model .getRequired ().contains ("modeNotRequired" ));
116121 assertFalse (model .getRequired ().contains ("modeNotRequiredWithAnnotation" ));
122+ assertFalse (model .getRequired ().contains ("modeNotRequiredWithAnnotationForNotBlank" ));
123+ assertFalse (model .getRequired ().contains ("modeNotRequiredWithAnnotationForNotEmpty" ));
117124 }
118125
119126 @ Test
@@ -139,6 +146,55 @@ public void testIssue1743() {
139146 assertEquals (is .getEnum ().get (1 ), new Integer (2 ));
140147 }
141148
149+ @ Test
150+ public void testNotNullWithNotBlankAndNotEmpty () {
151+ final Map <String , Schema > models = ModelConverters .getInstance ().readAll (NotNullWithNotBlankNotEmptyModel .class );
152+ Schema model = models .get ("NotNullWithNotBlankNotEmptyModel" );
153+ assertTrue (model .getRequired ().contains ("notNullAndNotBlank" ));
154+ assertTrue (model .getRequired ().contains ("notNullAndNotEmptyList" ));
155+ assertTrue (model .getRequired ().contains ("notNullAndNotEmptySet" ));
156+ }
157+
158+ @ Test
159+ public void testCollectionWithNotEmpty () {
160+ final Map <String , Schema > models = ModelConverters .getInstance ().readAll (CollectionWithNotEmptyModel .class );
161+ Schema model = models .get ("CollectionWithNotEmptyModel" );
162+ ArraySchema listSchema = (ArraySchema ) model .getProperties ().get ("notEmptyList" );
163+ assertNotNull (listSchema );
164+ assertEquals (listSchema .getMinItems (), Integer .valueOf (1 ));
165+ ArraySchema setSchema = (ArraySchema ) model .getProperties ().get ("notEmptySet" );
166+ assertNotNull (setSchema );
167+ assertEquals (setSchema .getMinItems (), Integer .valueOf (1 ));
168+ }
169+
170+ @ Test
171+ public void testStringWithNotBlankAndSize () {
172+ final Map <String , Schema > models = ModelConverters .getInstance ().readAll (StringWithNotBlankAndSizeModel .class );
173+ Schema model = models .get ("StringWithNotBlankAndSizeModel" );
174+ Schema strSchema = (Schema ) model .getProperties ().get ("notBlankAndSized" );
175+ assertNotNull (strSchema );
176+ assertEquals (strSchema .getMinLength (), Integer .valueOf (5 ));
177+ assertEquals (strSchema .getMaxLength (), Integer .valueOf (10 ));
178+ }
179+
180+ @ Test
181+ public void testNotBlankNotEmptyWithRequiredModeNotRequired () {
182+ final Map <String , Schema > models = ModelConverters .getInstance ().readAll (NotBlankNotEmptyWithRequiredModeNotRequiredModel .class );
183+ Schema model = models .get ("NotBlankNotEmptyWithRequiredModeNotRequiredModel" );
184+ assertFalse (model .getRequired () != null && model .getRequired ().contains ("notBlankNotRequired" ));
185+ assertFalse (model .getRequired () != null && model .getRequired ().contains ("notEmptyListNotRequired" ));
186+ assertFalse (model .getRequired () != null && model .getRequired ().contains ("notEmptySetNotRequired" ));
187+ }
188+
189+ @ Test
190+ public void testNotBlankNotEmptyWithRequiredModeRequired () {
191+ final Map <String , Schema > models = ModelConverters .getInstance ().readAll (NotBlankNotEmptyWithRequiredModeRequiredModel .class );
192+ Schema model = models .get ("NotBlankNotEmptyWithRequiredModeRequiredModel" );
193+ assertTrue (model .getRequired ().contains ("notBlankRequired" ));
194+ assertTrue (model .getRequired ().contains ("notEmptyListRequired" ));
195+ assertTrue (model .getRequired ().contains ("notEmptySetRequired" ));
196+ }
197+
142198 class Family {
143199 public Date membersSince ;
144200 public List <Person > members ;
@@ -162,4 +218,60 @@ class IsModelTest {
162218 public Boolean is_happy ;
163219 public String name ;
164220 }
221+
222+ static class NotNullWithNotBlankNotEmptyModel {
223+ @ NotNull
224+ @ NotBlank
225+ public String notNullAndNotBlank ;
226+
227+ @ NotNull
228+ @ NotEmpty
229+ public List <String > notNullAndNotEmptyList ;
230+
231+ @ NotNull
232+ @ NotEmpty
233+ public Set <String > notNullAndNotEmptySet ;
234+ }
235+
236+ static class CollectionWithNotEmptyModel {
237+ @ NotEmpty
238+ public List <String > notEmptyList ;
239+
240+ @ NotEmpty
241+ public Set <String > notEmptySet ;
242+ }
243+
244+ static class StringWithNotBlankAndSizeModel {
245+ @ NotBlank
246+ @ Size (min = 5 , max = 10 )
247+ public String notBlankAndSized ;
248+ }
249+
250+ static class NotBlankNotEmptyWithRequiredModeRequiredModel {
251+ @ NotBlank
252+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .REQUIRED )
253+ public String notBlankRequired ;
254+
255+ @ NotEmpty
256+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .REQUIRED )
257+ public List <String > notEmptyListRequired ;
258+
259+ @ NotEmpty
260+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .REQUIRED )
261+ public Set <String > notEmptySetRequired ;
262+ }
263+
264+ static class NotBlankNotEmptyWithRequiredModeNotRequiredModel {
265+ @ NotBlank
266+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .NOT_REQUIRED )
267+ public String notBlankNotRequired ;
268+
269+ @ NotEmpty
270+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .NOT_REQUIRED )
271+ public List <String > notEmptyListNotRequired ;
272+
273+ @ NotEmpty
274+ @ io .swagger .v3 .oas .annotations .media .Schema (requiredMode = io .swagger .v3 .oas .annotations .media .Schema .RequiredMode .NOT_REQUIRED )
275+ public Set <String > notEmptySetNotRequired ;
276+ }
165277}
0 commit comments