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:
@@ -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(),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -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}")
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[source,bash]
|
||||
.{{title}}
|
||||
----
|
||||
$ curl {{arguments}}
|
||||
$ curl {{url}} {{options}}
|
||||
----
|
||||
Reference in New Issue
Block a user