File tree Expand file tree Collapse file tree 2 files changed +22
-11
lines changed
spring-restdocs-core/src/test/java/org/springframework/restdocs/payload Expand file tree Collapse file tree 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 {
368368 .build ());
369369 }
370370
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+
371385 private String escapeIfNecessary (String input ) {
372386 if (this .templateFormat .equals (TemplateFormats .markdown ())) {
373387 return input ;
Original file line number Diff line number Diff line change @@ -379,22 +379,19 @@ public void mapResponseWithVaryingKeysMatchedUsingWildcard() throws IOException
379379 }
380380
381381 @ Test
382- public void responseWithSomeNullOcurrencesOfAField () throws IOException {
382+ public void responseWithArrayContainingFieldThatIsSometimesNull () throws IOException {
383383 this .snippets .expectResponseFields ()
384384 .withContents (tableWithHeader ("Path" , "Type" , "Description" )
385385 .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 ());
395393 }
396394
397-
398395 private String escapeIfNecessary (String input ) {
399396 if (this .templateFormat .equals (TemplateFormats .markdown ())) {
400397 return input ;
You can’t perform that action at this time.
0 commit comments