Merge branch '1.0.x'

This commit is contained in:
Andy Wilkinson
2016-05-05 09:53:30 +01:00
14 changed files with 80 additions and 81 deletions

View File

@@ -278,8 +278,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST") .request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE) MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0]) .part("image", new byte[0])
.submittedFileName("documents/images/example.png").build()); .submittedFileName("documents/images/example.png").build());
} }
@Test @Test
@@ -309,7 +309,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION, .header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils "Basic " + Base64Utils
.encodeToString("user:secret".getBytes())) .encodeToString("user:secret".getBytes()))
.build()); .build());
} }
@Test @Test

View File

@@ -280,8 +280,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST") .request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE) MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0]) .part("image", new byte[0])
.submittedFileName("documents/images/example.png").build()); .submittedFileName("documents/images/example.png").build());
} }
@Test @Test
@@ -311,7 +311,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION, .header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils "Basic " + Base64Utils
.encodeToString("user:secret".getBytes())) .encodeToString("user:secret".getBytes()))
.build()); .build());
} }
@Test @Test

View File

@@ -61,16 +61,13 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
headerWithName("Accept-Language").description("four"), headerWithName("Accept-Language").description("four"),
headerWithName("Cache-Control").description("five"), headerWithName("Cache-Control").description("five"),
headerWithName("Connection").description("six"))) headerWithName("Connection").description("six")))
.document( .document(operationBuilder("request-with-headers")
operationBuilder("request-with-headers") .request("http://localhost")
.request("http://localhost") .header("X-Test", "test").header("Accept", "*/*")
.header("X-Test", "test") .header("Accept-Encoding", "gzip, deflate")
.header("Accept", "*/*") .header("Accept-Language", "en-US,en;q=0.5")
.header("Accept-Encoding", .header("Cache-Control", "max-age=0")
"gzip, deflate") .header("Connection", "keep-alive").build());
.header("Accept-Language", "en-US,en;q=0.5")
.header("Cache-Control", "max-age=0")
.header("Connection", "keep-alive").build());
} }
@Test @Test
@@ -140,7 +137,7 @@ public class RequestHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test") .header("X-Test", "test")
.header("Accept-Encoding", .header("Accept-Encoding",
"gzip, deflate") "gzip, deflate")
.header("Accept", "*/*").build()); .header("Accept", "*/*").build());
} }
@Test @Test

View File

@@ -64,9 +64,9 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.header("X-Test", "test") .header("X-Test", "test")
.header("Content-Type", .header("Content-Type",
"application/json") "application/json")
.header("Etag", "lskjadldj3ii32l2ij23") .header("Etag", "lskjadldj3ii32l2ij23")
.header("Cache-Control", "max-age=0") .header("Cache-Control", "max-age=0")
.header("Vary", "User-Agent").build()); .header("Vary", "User-Agent").build());
} }
@Test @Test
@@ -130,7 +130,8 @@ public class ResponseHeadersSnippetTests extends AbstractSnippetTests {
.response().header("X-Test", "test") .response().header("X-Test", "test")
.header("Content-Type", .header("Content-Type",
"application/json") "application/json")
.header("Etag", "lskjadldj3ii32l2ij23").build()); .header("Etag", "lskjadldj3ii32l2ij23")
.build());
} }
@Test @Test

View File

@@ -86,8 +86,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world"; String content = "Hello, world";
this.snippet.expectHttpRequest("post-request-with-content") this.snippet.expectHttpRequest("post-request-with-content")
.withContents(httpRequest(RequestMethod.POST, "/foo") .withContents(httpRequest(RequestMethod.POST, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content) .header(HttpHeaders.HOST, "localhost").content(content).header(
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length)); HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(operationBuilder("post-request-with-content") new HttpRequestSnippet().document(operationBuilder("post-request-with-content")
.request("http://localhost/foo").method("POST").content(content).build()); .request("http://localhost/foo").method("POST").content(content).build());
@@ -140,8 +140,8 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
String content = "Hello, world"; String content = "Hello, world";
this.snippet.expectHttpRequest("put-request-with-content") this.snippet.expectHttpRequest("put-request-with-content")
.withContents(httpRequest(RequestMethod.PUT, "/foo") .withContents(httpRequest(RequestMethod.PUT, "/foo")
.header(HttpHeaders.HOST, "localhost").content(content) .header(HttpHeaders.HOST, "localhost").content(content).header(
.header(HttpHeaders.CONTENT_LENGTH, content.getBytes().length)); HttpHeaders.CONTENT_LENGTH, content.getBytes().length));
new HttpRequestSnippet().document(operationBuilder("put-request-with-content") new HttpRequestSnippet().document(operationBuilder("put-request-with-content")
.request("http://localhost/foo").method("PUT").content(content).build()); .request("http://localhost/foo").method("PUT").content(content).build());
@@ -176,7 +176,7 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/upload").method("POST") .request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE) MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", "<< data >>".getBytes()).build()); .part("image", "<< data >>".getBytes()).build());
} }
@Test @Test

View File

@@ -149,12 +149,14 @@ public class LinksSnippetTests extends AbstractSnippetTests {
new LinkDescriptor("a").description("one") new LinkDescriptor("a").description("one")
.attributes(key("foo").value("alpha")), .attributes(key("foo").value("alpha")),
new LinkDescriptor("b").description("two").attributes( new LinkDescriptor("b").description("two").attributes(
key("foo").value("bravo")))).document(operationBuilder( key("foo").value("bravo"))))
"links-with-custom-descriptor-attributes") .document(operationBuilder(
.attribute(TemplateEngine.class.getName(), "links-with-custom-descriptor-attributes")
new MustacheTemplateEngine( .attribute(TemplateEngine.class
resolver)) .getName(),
.build()); new MustacheTemplateEngine(
resolver))
.build());
} }
@Test @Test
@@ -165,7 +167,7 @@ public class LinksSnippetTests extends AbstractSnippetTests {
HypermediaDocumentation HypermediaDocumentation
.links(new StubLinkExtractor().withLinks(new Link("a", "alpha"), .links(new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")), new Link("b", "bravo")),
new LinkDescriptor("a").description("one")) new LinkDescriptor("a").description("one"))
.and(new LinkDescriptor("b").description("two")) .and(new LinkDescriptor("b").description("two"))
.document(operationBuilder("additional-descriptors").build()); .document(operationBuilder("additional-descriptors").build());
} }

View File

@@ -56,7 +56,7 @@ public class PrettyPrintingContentModifierTests {
equalTo(String equalTo(String
.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n" .format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
+ "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n") + "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n")
.getBytes())); .getBytes()));
} }
@Test @Test

View File

@@ -75,11 +75,13 @@ public class RequestFieldsSnippetFailureTests {
@Test @Test
public void missingOptionalRequestFieldWithNoTypeProvided() throws IOException { public void missingOptionalRequestFieldWithNoTypeProvided() throws IOException {
this.thrown.expect(FieldTypeRequiredException.class); this.thrown.expect(FieldTypeRequiredException.class);
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one") new RequestFieldsSnippet(
.optional())).document(new OperationBuilder( Arrays.asList(fieldWithPath("a.b").description("one").optional()))
"missing-optional-request-field-with-no-type", .document(new OperationBuilder(
this.snippet.getOutputDirectory()).request("http://localhost") "missing-optional-request-field-with-no-type",
.content("{ }").build()); this.snippet.getOutputDirectory())
.request("http://localhost").content("{ }")
.build());
} }
@Test @Test
@@ -136,7 +138,7 @@ public class RequestFieldsSnippetFailureTests {
.content("<a></a>") .content("<a></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test

View File

@@ -51,8 +51,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
public void mapRequestWithFields() throws IOException { public void mapRequestWithFields() throws IOException {
this.snippet.expectRequestFields("map-request-with-fields") this.snippet.expectRequestFields("map-request-with-fields")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a.b", "Number", "one").row("a.c", "String", "two") .row("a.b", "Number", "one").row("a.c", "String", "two").row("a",
.row("a", "Object", "three")); "Object", "three"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one"), new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one"),
fieldWithPath("a.c").description("two"), fieldWithPath("a.c").description("two"),
@@ -150,15 +150,15 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.request("http://localhost") .request("http://localhost")
.content( .content(
"{\"a\": {\"b\": 5, \"c\": \"charlie\"}}") "{\"a\": {\"b\": 5, \"c\": \"charlie\"}}")
.build()); .build());
} }
@Test @Test
public void xmlRequestFields() throws IOException { public void xmlRequestFields() throws IOException {
this.snippet.expectRequestFields("xml-request") this.snippet.expectRequestFields("xml-request")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a/b", "b", "one").row("a/c", "c", "two") .row("a/b", "b", "one").row("a/c", "c", "two").row("a", "a",
.row("a", "a", "three")); "three"));
new RequestFieldsSnippet( new RequestFieldsSnippet(
Arrays.asList(fieldWithPath("a/b").description("one").type("b"), Arrays.asList(fieldWithPath("a/b").description("one").type("b"),
@@ -170,15 +170,15 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
.content("<a><b>5</b><c>charlie</c></a>") .content("<a><b>5</b><c>charlie</c></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
public void additionalDescriptors() throws IOException { public void additionalDescriptors() throws IOException {
this.snippet.expectRequestFields("additional-descriptors") this.snippet.expectRequestFields("additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a.b", "Number", "one").row("a.c", "String", "two") .row("a.b", "Number", "one").row("a.c", "String", "two").row("a",
.row("a", "Object", "three")); "Object", "three"));
PayloadDocumentation PayloadDocumentation
.requestFields(fieldWithPath("a.b").description("one"), .requestFields(fieldWithPath("a.b").description("one"),
@@ -193,8 +193,8 @@ public class RequestFieldsSnippetTests extends AbstractSnippetTests {
public void prefixedAdditionalDescriptors() throws IOException { public void prefixedAdditionalDescriptors() throws IOException {
this.snippet.expectRequestFields("prefixed-additional-descriptors") this.snippet.expectRequestFields("prefixed-additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a", "Object", "one").row("a.b", "Number", "two") .row("a", "Object", "one").row("a.b", "Number", "two").row("a.c",
.row("a.c", "String", "three")); "String", "three"));
PayloadDocumentation.requestFields(fieldWithPath("a").description("one")) PayloadDocumentation.requestFields(fieldWithPath("a").description("one"))
.andWithPrefix("a.", fieldWithPath("b").description("two"), .andWithPrefix("a.", fieldWithPath("b").description("two"),

View File

@@ -63,7 +63,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a><b>5</b></a>") .content("<a><b>5</b></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -79,7 +79,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a>foo</a>") .content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -89,15 +89,14 @@ public class ResponseFieldsSnippetFailureTests {
String.format("The following parts of the payload were not documented:" String.format("The following parts of the payload were not documented:"
+ "%n<a>bar</a>%n"))); + "%n<a>bar</a>%n")));
new ResponseFieldsSnippet( new ResponseFieldsSnippet(
Arrays.asList( Arrays.asList(fieldWithPath("a/@id").description("one").type("a")))
fieldWithPath("a/@id").description("one") .document(
.type("a"))).document(new OperationBuilder( new OperationBuilder("documented-attribute-is-removed",
"documented-attribute-is-removed",
this.snippet.getOutputDirectory()).response() this.snippet.getOutputDirectory()).response()
.content("<a id=\"foo\">bar</a>") .content("<a id=\"foo\">bar</a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -124,7 +123,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a></a>") .content("<a></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -145,7 +144,7 @@ public class ResponseFieldsSnippetFailureTests {
.content("<a><c>5</c></a>") .content("<a><c>5</c></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
} }

View File

@@ -80,7 +80,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
operationBuilder("array-response-with-fields").response() operationBuilder("array-response-with-fields").response()
.content( .content(
"[{\"a\": {\"b\": 5}},{\"a\": {\"c\": \"charlie\"}}]") "[{\"a\": {\"b\": 5}},{\"a\": {\"c\": \"charlie\"}}]")
.build()); .build());
} }
@Test @Test
@@ -145,8 +145,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.row("a", "Object", "three", "charlie")); .row("a", "Object", "three", "charlie"));
new ResponseFieldsSnippet(Arrays.asList( new ResponseFieldsSnippet(Arrays.asList(
fieldWithPath("a.b").description("one") fieldWithPath("a.b").description("one").attributes(key("foo")
.attributes(key("foo").value("alpha")), .value("alpha")),
fieldWithPath("a.c").description("two") fieldWithPath("a.c").description("two")
.attributes(key("foo").value("bravo")), .attributes(key("foo").value("bravo")),
fieldWithPath("a").description("three") fieldWithPath("a").description("three")
@@ -164,8 +164,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
public void xmlResponseFields() throws IOException { public void xmlResponseFields() throws IOException {
this.snippet.expectResponseFields("xml-response") this.snippet.expectResponseFields("xml-response")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a/b", "b", "one").row("a/c", "c", "two") .row("a/b", "b", "one").row("a/c", "c", "two").row("a", "a",
.row("a", "a", "three")); "three"));
new ResponseFieldsSnippet( new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("a/b").description("one").type("b"), Arrays.asList(fieldWithPath("a/b").description("one").type("b"),
fieldWithPath("a/c").description("two").type("c"), fieldWithPath("a/c").description("two").type("c"),
@@ -175,7 +175,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a><b>5</b><c>charlie</c></a>") .content("<a><b>5</b><c>charlie</c></a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -191,7 +191,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.content("<a id=\"1\">foo</a>") .content("<a id=\"1\">foo</a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -207,7 +207,7 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
.response().content("<a>foo</a>") .response().content("<a>foo</a>")
.header(HttpHeaders.CONTENT_TYPE, .header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE) MediaType.APPLICATION_XML_VALUE)
.build()); .build());
} }
@Test @Test
@@ -248,8 +248,8 @@ public class ResponseFieldsSnippetTests extends AbstractSnippetTests {
public void prefixedAdditionalDescriptors() throws IOException { public void prefixedAdditionalDescriptors() throws IOException {
this.snippet.expectResponseFields("prefixed-additional-descriptors") this.snippet.expectResponseFields("prefixed-additional-descriptors")
.withContents(tableWithHeader("Path", "Type", "Description") .withContents(tableWithHeader("Path", "Type", "Description")
.row("a", "Object", "one").row("a.b", "Number", "two") .row("a", "Object", "one").row("a.b", "Number", "two").row("a.c",
.row("a.c", "String", "three")); "String", "three"));
PayloadDocumentation.responseFields(fieldWithPath("a").description("one")) PayloadDocumentation.responseFields(fieldWithPath("a").description("one"))
.andWithPrefix("a.", fieldWithPath("b").description("two"), .andWithPrefix("a.", fieldWithPath("b").description("two"),

View File

@@ -77,11 +77,10 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("b", tableWithTitleAndHeader(getTitle(), "Parameter", "Description").row("b",
"two")); "two"));
new PathParametersSnippet( new PathParametersSnippet(
Arrays.asList(parameterWithName("b").description("two")), Arrays.asList(parameterWithName("b").description("two")), true)
true).document(operationBuilder("ignore-all-undocumented") .document(operationBuilder("ignore-all-undocumented").attribute(
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE, RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}") "/{a}/{b}").build());
.build());
} }
@Test @Test
@@ -125,8 +124,8 @@ public class PathParametersSnippetTests extends AbstractSnippetTests {
Arrays.asList( Arrays.asList(
parameterWithName("a").description("one") parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")), .attributes(key("foo").value("alpha")),
parameterWithName("b").description("two") parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))), .attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title"))).document( attributes(key("title").value("The title"))).document(
operationBuilder("path-parameters-with-custom-attributes") operationBuilder("path-parameters-with-custom-attributes")
.attribute( .attribute(

View File

@@ -116,8 +116,8 @@ public class RequestParametersSnippetTests extends AbstractSnippetTests {
Arrays.asList( Arrays.asList(
parameterWithName("a").description("one") parameterWithName("a").description("one")
.attributes(key("foo").value("alpha")), .attributes(key("foo").value("alpha")),
parameterWithName("b").description("two") parameterWithName("b").description("two")
.attributes(key("foo").value("bravo"))), .attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title"))).document( attributes(key("title").value("The title"))).document(
operationBuilder("request-parameters-with-custom-attributes") operationBuilder("request-parameters-with-custom-attributes")
.attribute(TemplateEngine.class.getName(), .attribute(TemplateEngine.class.getName(),

View File

@@ -266,9 +266,8 @@ public class MockMvcRestDocumentationIntegrationTests {
mockMvc.perform(get("/").param("foo", "bar").accept(MediaType.APPLICATION_JSON)) mockMvc.perform(get("/").param("foo", "bar").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andDo(document("links", .andDo(document("links", responseFields(
responseFields(fieldWithPath("a") fieldWithPath("a").description("The description"),
.description("The description"),
fieldWithPath("links").description("Links to other resources")))); fieldWithPath("links").description("Links to other resources"))));
assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"), assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"),