Polish new response fields test and add equivalent for request fields

See gh-399
This commit is contained in:
Andy Wilkinson
2017-07-01 10:56:47 +01:00
parent 288ebf771a
commit 5cef4745f7
2 changed files with 22 additions and 11 deletions

View File

@@ -368,6 +368,20 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.build());
}
@Test
public void requestWithArrayContainingFieldThatIsSometimesNull() throws IOException {
this.snippets.expectRequestFields()
.withContents(tableWithHeader("Path", "Type", "Description")
.row("`assets[].name`", "`String`", "one"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("assets[].name")
.description("one").type(JsonFieldType.STRING)))
.document(this.operationBuilder.request("http://localhost")
.content("{\"assets\": [" + "{\"name\": \"sample1\"}, "
+ "{\"name\": null}, "
+ "{\"name\": \"sample2\"}]}")
.build());
}
private String escapeIfNecessary(String input) {
if (this.templateFormat.equals(TemplateFormats.markdown())) {
return input;

View File

@@ -379,22 +379,19 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
}
@Test
public void responseWithSomeNullOcurrencesOfAField() throws IOException {
public void responseWithArrayContainingFieldThatIsSometimesNull() 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());
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("assets[].name")
.description("one").type(JsonFieldType.STRING)))
.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;