Skip to content

Commit 288ebf7

Browse files
Nakul Chaudhariwilkinsona
Nakul Chaudhari
authored andcommitted
Add a test that shows problem with sometimes null field within an array
Closes gh-399
1 parent dff9062 commit 288ebf7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,23 @@ public void mapResponseWithVaryingKeysMatchedUsingWildcard() throws IOException
378378
.build());
379379
}
380380

381+
@Test
382+
public void responseWithSomeNullOcurrencesOfAField() throws IOException {
383+
this.snippets.expectResponseFields()
384+
.withContents(tableWithHeader("Path", "Type", "Description")
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());
395+
}
396+
397+
381398
private String escapeIfNecessary(String input) {
382399
if (this.templateFormat.equals(TemplateFormats.markdown())) {
383400
return input;

0 commit comments

Comments
 (0)