Make descriptions more flexible

Previously, the description of a link, parameter, or field had to be a
String. Given the use of Mustache templates, this was unnecessarily
restrictive. It prevented the use of a richer object, the components of
which could then be accessed in a template.

This commit changes the description of links, parameters, and fields to
be an Object, thereby allowing richer objects to be used. The default
template will call toString on the description during rendering. Custom
templates can be used to make more sophisticated use of the description.

To ensure that the description is consistent across all descriptor
types, it has been moved up onto the AbstractDescriptor superclass.

Closes gh-123
This commit is contained in:
Andy Wilkinson
2015-09-13 11:58:22 -04:00
parent df40f63238
commit 14ad59d434
10 changed files with 64 additions and 70 deletions

View File

@@ -179,6 +179,26 @@ public class RequestFieldsSnippetTests {
.request("http://localhost").content("{\"a\": \"foo\"}").build());
}
@Test
public void requestFieldsWithListDescription() throws IOException {
this.snippet.expectRequestFields("request-fields-with-list-description")
.withContents(
tableWithHeader("Path", "Type", "Description")
//
.row("a", "String", String.format(" - one%n - two"))
.configuration("[cols=\"1,1,1a\"]"));
TemplateResourceResolver resolver = mock(TemplateResourceResolver.class);
when(resolver.resolveTemplateResource("request-fields")).thenReturn(
snippetResource("request-fields-with-list-description"));
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description(
Arrays.asList("one", "two"))))
.document(new OperationBuilder("request-fields-with-list-description",
this.snippet.getOutputDirectory())
.attribute(TemplateEngine.class.getName(),
new MustacheTemplateEngine(resolver))
.request("http://localhost").content("{\"a\": \"foo\"}").build());
}
@Test
public void xmlRequestFields() throws IOException {
this.snippet.expectRequestFields("xml-request").withContents( //

View File

@@ -191,6 +191,11 @@ public class SnippetMatchers {
this.addLine(-1, "");
return this;
}
public AsciidoctorTableMatcher configuration(String configuration) {
this.addLine(0, configuration);
return this;
}
}
public static class SnippetMatcher extends BaseMatcher<File> {

View File

@@ -0,0 +1,12 @@
[cols="1,1,1a"]
|===
|Path|Type|Description
{{#fields}}
|{{path}}
|{{type}}
|{{#description}} - {{.}}
{{/description}}
{{/fields}}
|===