File tree 2 files changed +22
-11
lines changed
spring-restdocs-core/src/test/java/org/springframework/restdocs/payload 2 files changed +22
-11
lines changed Original file line number Diff line number Diff line change @@ -368,6 +368,20 @@ public void mapRequestWithVaryingKeysMatchedUsingWildcard() throws IOException {
368
368
.build ());
369
369
}
370
370
371
+ @ Test
372
+ public void requestWithArrayContainingFieldThatIsSometimesNull () throws IOException {
373
+ this .snippets .expectRequestFields ()
374
+ .withContents (tableWithHeader ("Path" , "Type" , "Description" )
375
+ .row ("`assets[].name`" , "`String`" , "one" ));
376
+ new RequestFieldsSnippet (Arrays .asList (fieldWithPath ("assets[].name" )
377
+ .description ("one" ).type (JsonFieldType .STRING )))
378
+ .document (this .operationBuilder .request ("http://localhost" )
379
+ .content ("{\" assets\" : [" + "{\" name\" : \" sample1\" }, "
380
+ + "{\" name\" : null}, "
381
+ + "{\" name\" : \" sample2\" }]}" )
382
+ .build ());
383
+ }
384
+
371
385
private String escapeIfNecessary (String input ) {
372
386
if (this .templateFormat .equals (TemplateFormats .markdown ())) {
373
387
return input ;
Original file line number Diff line number Diff line change @@ -379,22 +379,19 @@ public void mapResponseWithVaryingKeysMatchedUsingWildcard() throws IOException
379
379
}
380
380
381
381
@ Test
382
- public void responseWithSomeNullOcurrencesOfAField () throws IOException {
382
+ public void responseWithArrayContainingFieldThatIsSometimesNull () throws IOException {
383
383
this .snippets .expectResponseFields ()
384
384
.withContents (tableWithHeader ("Path" , "Type" , "Description" )
385
385
.row ("`assets[].name`" , "`String`" , "one" ));
386
- new ResponseFieldsSnippet (Arrays .asList (
387
- fieldWithPath ("assets[].name" ).description ("one" )))
388
- .document (this .operationBuilder .response ()
389
- .content (
390
- "{\" assets\" : [" +
391
- "{\" name\" : \" sample1\" }, " +
392
- "{\" name\" : null}, " +
393
- "{\" name\" : \" sample2\" }]}" )
394
- .build ());
386
+ new ResponseFieldsSnippet (Arrays .asList (fieldWithPath ("assets[].name" )
387
+ .description ("one" ).type (JsonFieldType .STRING )))
388
+ .document (this .operationBuilder .response ()
389
+ .content ("{\" assets\" : [" + "{\" name\" : \" sample1\" }, "
390
+ + "{\" name\" : null}, "
391
+ + "{\" name\" : \" sample2\" }]}" )
392
+ .build ());
395
393
}
396
394
397
-
398
395
private String escapeIfNecessary (String input ) {
399
396
if (this .templateFormat .equals (TemplateFormats .markdown ())) {
400
397
return input ;
You can’t perform that action at this time.
0 commit comments