From 288ebf771a364d5f9fce7813c2b9e6ca06547bc7 Mon Sep 17 00:00:00 2001 From: Nakul Chaudhari Date: Tue, 6 Jun 2017 16:42:52 +0200 Subject: [PATCH] Add a test that shows problem with sometimes null field within an array Closes gh-399 --- .../payload/ResponseFieldsSnippetTests.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java index a7f2f047..294f4028 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java @@ -378,6 +378,23 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests { .build()); } + @Test + public void responseWithSomeNullOcurrencesOfAField() throws IOException { + this.snippets.expectResponseFields() + .withContents(tableWithHeader("Path", "Type", "Description") + .row("`assets[].name`", "`String`", "one")); + new ResponseFieldsSnippet(Arrays.asList( + fieldWithPath("assets[].name").description("one"))) + .document(this.operationBuilder.response() + .content( + "{\"assets\": [" + + "{\"name\": \"sample1\"}, " + + "{\"name\": null}, " + + "{\"name\": \"sample2\"}]}") + .build()); + } + + private String escapeIfNecessary(String input) { if (this.templateFormat.equals(TemplateFormats.markdown())) { return input;