Make the built-in snippets more extensible

The commit opens up all of the default snippets so that it's easier
to extend them and modify their behaviour. All of the built-in
snippets are now public with protected constructors. Also, where
appropriate the models used by the snippets have been made more
fine-grained.

Closes gh-73
This commit is contained in:
Andy Wilkinson
2015-09-08 10:30:50 +01:00
parent de095eb9fe
commit c2da4c912a
21 changed files with 249 additions and 84 deletions

View File

@@ -154,10 +154,10 @@ public class LinksSnippetTests {
new FileSystemResource(
"src/test/resources/custom-snippet-templates/links-with-title.snippet"));
new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha"),
new Link("b", "bravo")), attributes(key("title").value(
"Title for the links")), Arrays.asList(
new Link("b", "bravo")), Arrays.asList(
new LinkDescriptor("a").description("one"),
new LinkDescriptor("b").description("two")))
new LinkDescriptor("b").description("two")), attributes(key("title").value(
"Title for the links")))
.document(new OperationBuilder("links-with-custom-attributes",
this.snippet.getOutputDirectory()).attribute(
TemplateEngine.class.getName(),

View File

@@ -170,8 +170,8 @@ public class RequestFieldsSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
when(resolver.resolveTemplateResource("request-fields")).thenReturn(
snippetResource("request-fields-with-title"));
new RequestFieldsSnippet(attributes(key("title").value("Custom title")),
Arrays.asList(fieldWithPath("a").description("one")))
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")),
attributes(key("title").value("Custom title")))
.document(new OperationBuilder("request-fields-with-custom-attributes",
this.snippet.getOutputDirectory())
.attribute(TemplateEngine.class.getName(),

View File

@@ -139,8 +139,8 @@ public class ResponseFieldsSnippetTests {
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
when(resolver.resolveTemplateResource("response-fields")).thenReturn(
snippetResource("response-fields-with-title"));
new ResponseFieldsSnippet(attributes(key("title").value("Custom title")),
Arrays.asList(fieldWithPath("a").description("one")))
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")),
attributes(key("title").value("Custom title")))
.document(new OperationBuilder("response-fields-with-custom-attributes",
this.snippet.getOutputDirectory())
.attribute(TemplateEngine.class.getName(),

View File

@@ -147,11 +147,11 @@ public class PathParametersSnippetTests {
when(resolver.resolveTemplateResource("path-parameters")).thenReturn(
snippetResource("path-parameters-with-title"));
new PathParametersSnippet(
attributes(key("title").value("The title")),
Arrays.asList(
parameterWithName("a").description("one").attributes(
key("foo").value("alpha")), parameterWithName("b")
.description("two").attributes(key("foo").value("bravo"))))
.description("two").attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title")))
.document(new OperationBuilder("path-parameters-with-custom-attributes",
this.snippet.getOutputDirectory())
.attribute("org.springframework.restdocs.urlTemplate", "/{a}/{b}")

View File

@@ -131,11 +131,11 @@ public class RequestParametersSnippetTests {
when(resolver.resolveTemplateResource("request-parameters")).thenReturn(
snippetResource("request-parameters-with-title"));
new RequestParametersSnippet(
attributes(key("title").value("The title")),
Arrays.asList(
parameterWithName("a").description("one").attributes(
key("foo").value("alpha")), parameterWithName("b")
.description("two").attributes(key("foo").value("bravo"))))
.description("two").attributes(key("foo").value("bravo"))),
attributes(key("title").value("The title")))
.document(new OperationBuilder(
"request-parameters-with-custom-attributes", this.snippet
.getOutputDirectory())

View File

@@ -1,5 +1,5 @@
[source,bash]
.{{title}}
----
$ curl {{arguments}}
$ curl {{url}} {{options}}
----