Polish new response fields test and add equivalent for request fields
See gh-399
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user