1010import org .springframework .http .MediaType ;
1111import org .springframework .restdocs .RestDocumentationContextProvider ;
1212import org .springframework .restdocs .RestDocumentationExtension ;
13+ import org .springframework .restdocs .constraints .ConstraintDescriptions ;
1314import org .springframework .restdocs .payload .JsonFieldType ;
1415import org .springframework .test .web .reactive .server .WebTestClient ;
1516import reactor .core .publisher .Flux ;
2223import static de .ksbrwsk .people .Constants .API ;
2324import static org .springframework .restdocs .payload .PayloadDocumentation .fieldWithPath ;
2425import static org .springframework .restdocs .payload .PayloadDocumentation .responseFields ;
26+ import static org .springframework .restdocs .snippet .Attributes .key ;
2527import static org .springframework .restdocs .webtestclient .WebTestClientRestDocumentation .document ;
2628import static org .springframework .restdocs .webtestclient .WebTestClientRestDocumentation .documentationConfiguration ;
2729
2830@ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .RANDOM_PORT )
2931@ Import (TestReactivePeoplePostgresqlApplication .class )
30- public class RestAssuredDocsTest extends PostgreSqlContainer {
32+ public class RestDocsTest extends PostgreSqlContainer {
3133
3234 @ Autowired
3335 PersonRepository personRepository ;
@@ -62,6 +64,11 @@ public void setUp(ApplicationContext applicationContext, RestDocumentationContex
6264 .verifyComplete ();
6365 }
6466
67+ public List <String > constraintDescriptionForProperty (String property ) {
68+ ConstraintDescriptions userConstraints = new ConstraintDescriptions (Person .class );
69+ return userConstraints .descriptionsForProperty (property );
70+ }
71+
6572 @ Test
6673 void handleNotFound () {
6774 this .webTestClient
@@ -92,10 +99,12 @@ void handleFindAll() {
9299 responseFields (
93100 fieldWithPath ("[].id" )
94101 .type (JsonFieldType .NUMBER )
95- .description ("The person's id" ),
102+ .description ("The person's id" )
103+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("id" ))),
96104 fieldWithPath ("[].name" )
97105 .type (JsonFieldType .STRING )
98- .description ("The person's name" ))));
106+ .description ("The person's name" )
107+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("name" ))))));
99108 }
100109
101110 @ Test
@@ -114,10 +123,12 @@ void handleFindById() {
114123 responseFields (
115124 fieldWithPath ("id" )
116125 .type (JsonFieldType .NUMBER )
117- .description ("The person's id" ),
126+ .description ("The person's id" )
127+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("id" ))),
118128 fieldWithPath ("name" )
119129 .type (JsonFieldType .STRING )
120- .description ("The person's name" ))));
130+ .description ("The person's name" )
131+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("name" ))))));
121132 }
122133
123134 @ Test
@@ -177,10 +188,12 @@ void handleUpdate() {
177188 responseFields (
178189 fieldWithPath ("id" )
179190 .type (JsonFieldType .NUMBER )
180- .description ("The person's id" ),
191+ .description ("The person's id" )
192+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("id" ))),
181193 fieldWithPath ("name" )
182194 .type (JsonFieldType .STRING )
183- .description ("The person's name" ))));
195+ .description ("The person's name" )
196+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("name" ))))));
184197 }
185198
186199 @ Test
@@ -240,10 +253,12 @@ void handleCreate() {
240253 responseFields (
241254 fieldWithPath ("id" )
242255 .type (JsonFieldType .NUMBER )
243- .description ("The person's id" ),
256+ .description ("The person's id" )
257+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("id" ))),
244258 fieldWithPath ("name" )
245259 .type (JsonFieldType .STRING )
246- .description ("The person's name" ))));
260+ .description ("The person's name" )
261+ .attributes (key ("constraints" ).value (constraintDescriptionForProperty ("name" ))))));
247262 }
248263
249264 @ Test
0 commit comments