diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java index 4544c13a..ef04fd83 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/curl/CurlRequestSnippet.java @@ -36,31 +36,43 @@ import org.springframework.util.StringUtils; * A {@link Snippet} that documents the curl command for a request. * * @author Andy Wilkinson + * @see CurlDocumentation#curlRequest() + * @see CurlDocumentation#curlRequest(Map) */ -class CurlRequestSnippet extends TemplatedSnippet { +public class CurlRequestSnippet extends TemplatedSnippet { - CurlRequestSnippet() { + /** + * Creates a new {@code CurlRequestSnippet} with no additional attributes. + */ + protected CurlRequestSnippet() { this(null); } - CurlRequestSnippet(Map attributes) { + /** + * Creates a new {@code CurlRequestSnippet} with the given additional + * {@code attributes} that will be included in the model during template rendering. + * + * @param attributes The additional attributes + */ + protected CurlRequestSnippet(Map attributes) { super("curl-request", attributes); } @Override - public Map createModel(Operation operation) throws IOException { + protected Map createModel(Operation operation) throws IOException { Map model = new HashMap(); - model.put("arguments", getCurlCommandArguments(operation)); + model.put("url", getUrl(operation)); + model.put("options", getOptions(operation)); return model; } - private String getCurlCommandArguments(Operation operation) throws IOException { + private String getUrl(Operation operation) { + return String.format("'%s'", operation.getRequest().getUri()); + } + + private String getOptions(Operation operation) throws IOException { StringWriter command = new StringWriter(); PrintWriter printer = new PrintWriter(command); - printer.print("'"); - printer.print(operation.getRequest().getUri()); - printer.print("'"); - writeOptionToIncludeHeadersInOutput(printer); writeHttpMethodIfNecessary(operation.getRequest(), printer); writeHeaders(operation.getRequest(), printer); @@ -72,7 +84,7 @@ class CurlRequestSnippet extends TemplatedSnippet { } private void writeOptionToIncludeHeadersInOutput(PrintWriter writer) { - writer.print(" -i"); + writer.print("-i"); } private void writeHttpMethodIfNecessary(OperationRequest request, PrintWriter writer) { diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java index fd30849a..b98e33c8 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpRequestSnippet.java @@ -39,21 +39,32 @@ import org.springframework.util.StringUtils; * A {@link Snippet} that documents an HTTP request. * * @author Andy Wilkinson + * @see HttpDocumentation#httpRequest() + * @see HttpDocumentation#httpRequest(Map) */ -class HttpRequestSnippet extends TemplatedSnippet { +public class HttpRequestSnippet extends TemplatedSnippet { private static final String MULTIPART_BOUNDARY = "6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm"; - HttpRequestSnippet() { + /** + * Creates a new {@code HttpRequestSnippet} with no additional attributes. + */ + protected HttpRequestSnippet() { this(null); } - HttpRequestSnippet(Map attributes) { + /** + * Creates a new {@code HttpRequestSnippet} with the given additional + * {@code attributes} that will be included in the model during template rendering. + * + * @param attributes The additional attributes + */ + protected HttpRequestSnippet(Map attributes) { super("http-request", attributes); } @Override - public Map createModel(Operation operation) throws IOException { + protected Map createModel(Operation operation) throws IOException { Map model = new HashMap(); model.put("method", operation.getRequest().getMethod()); model.put( @@ -61,8 +72,7 @@ class HttpRequestSnippet extends TemplatedSnippet { operation.getRequest().getUri().getRawPath() + (StringUtils.hasText(operation.getRequest().getUri() .getRawQuery()) ? "?" - + operation.getRequest().getUri().getRawQuery() - : "")); + + operation.getRequest().getUri().getRawQuery() : "")); model.put("headers", getHeaders(operation.getRequest())); model.put("requestBody", getRequestBody(operation.getRequest())); return model; diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java index 7f4f6b65..07f9a5b0 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/http/HttpResponseSnippet.java @@ -33,19 +33,30 @@ import org.springframework.restdocs.snippet.TemplatedSnippet; * A {@link Snippet} that documents an HTTP response. * * @author Andy Wilkinson + * @see HttpDocumentation#httpResponse() + * @see HttpDocumentation#httpResponse(Map) */ -class HttpResponseSnippet extends TemplatedSnippet { +public class HttpResponseSnippet extends TemplatedSnippet { - HttpResponseSnippet() { + /** + * Creates a new {@code HttpResponseSnippet} with no additional attributes. + */ + protected HttpResponseSnippet() { this(null); } - HttpResponseSnippet(Map attributes) { + /** + * Creates a new {@code HttpResponseSnippet} with the given additional + * {@code attributes} that will be included in the model during template rendering. + * + * @param attributes The additional attributes + */ + protected HttpResponseSnippet(Map attributes) { super("http-response", attributes); } @Override - public Map createModel(Operation operation) throws IOException { + protected Map createModel(Operation operation) throws IOException { OperationResponse response = operation.getResponse(); HttpStatus status = response.getStatus(); Map model = new HashMap(); diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/HypermediaDocumentation.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/HypermediaDocumentation.java index 52c0cccb..968f5dad 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/HypermediaDocumentation.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/HypermediaDocumentation.java @@ -67,8 +67,8 @@ public abstract class HypermediaDocumentation { */ public static Snippet links(Map attributes, LinkDescriptor... descriptors) { - return new LinksSnippet(new ContentTypeLinkExtractor(), attributes, - Arrays.asList(descriptors)); + return new LinksSnippet(new ContentTypeLinkExtractor(), Arrays.asList(descriptors), + attributes); } /** @@ -98,8 +98,8 @@ public abstract class HypermediaDocumentation { */ public static Snippet links(LinkExtractor linkExtractor, Map attributes, LinkDescriptor... descriptors) { - return new LinksSnippet(linkExtractor, attributes, - Arrays.asList(descriptors)); + return new LinksSnippet(linkExtractor, Arrays.asList(descriptors), + attributes); } /** diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java index 1e01716c..551d83ab 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/hypermedia/LinksSnippet.java @@ -37,8 +37,12 @@ import org.springframework.util.Assert; * A {@link Snippet} that documents a RESTful resource's links. * * @author Andy Wilkinson + * @see HypermediaDocumentation#links(LinkDescriptor...) + * @see HypermediaDocumentation#links(LinkExtractor, LinkDescriptor...) + * @see HypermediaDocumentation#links(Map, LinkDescriptor...) + * @see HypermediaDocumentation#links(LinkExtractor, Map, LinkDescriptor...) */ -class LinksSnippet extends TemplatedSnippet { +public class LinksSnippet extends TemplatedSnippet { private final Map descriptorsByRel = new LinkedHashMap<>(); @@ -46,12 +50,28 @@ class LinksSnippet extends TemplatedSnippet { private final LinkExtractor linkExtractor; - LinksSnippet(LinkExtractor linkExtractor, List descriptors) { - this(linkExtractor, null, descriptors); + /** + * Creates a new {@code LinksSnippet} that will extract links using the given + * {@code linkExtractor} and document them using the given {@code descriptors}. + * + * @param linkExtractor the link extractor + * @param descriptors the link descriptors + */ + protected LinksSnippet(LinkExtractor linkExtractor, List descriptors) { + this(linkExtractor, descriptors, null); } - LinksSnippet(LinkExtractor linkExtractor, Map attributes, - List descriptors) { + /** + * Creates a new {@code LinksSnippet} that will extract links using the given + * {@code linkExtractor} and document them using the given {@code descriptors}. The + * given {@code attributes} will be included in the model during template rendering. + * + * @param linkExtractor the link extractor + * @param descriptors the link descriptors + * @param attributes the additional attributes + */ + protected LinksSnippet(LinkExtractor linkExtractor, List descriptors, + Map attributes) { super("links", attributes); this.linkExtractor = linkExtractor; for (LinkDescriptor descriptor : descriptors) { diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java index ec93b8d1..802d34c1 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/AbstractFieldsSnippet.java @@ -30,8 +30,8 @@ import org.springframework.util.Assert; import org.springframework.util.StringUtils; /** - * A {@link TemplatedSnippet} that produces a snippet documenting a RESTful resource's - * request or response fields. + * Abstract {@link TemplatedSnippet} subclass that provides a base for snippets that + * document a RESTful resource's request or response fields. * * @author Andreas Evers * @author Andy Wilkinson @@ -40,8 +40,18 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet { private List fieldDescriptors; - AbstractFieldsSnippet(String type, Map attributes, - List descriptors) { + /** + * Creates a new {@code AbstractFieldsSnippet} that will produce a snippet named + * {@code -fields}. The fields will be documented using the given + * {@code descriptors} and the given {@code attributes} will be included in the model + * during template rendering. + * + * @param type the type of the fields + * @param descriptors the field descriptors + * @param attributes the additional attributes + */ + protected AbstractFieldsSnippet(String type, List descriptors, + Map attributes) { super(type + "-fields", attributes); for (FieldDescriptor descriptor : descriptors) { Assert.notNull(descriptor.getPath()); @@ -106,8 +116,23 @@ public abstract class AbstractFieldsSnippet extends TemplatedSnippet { } } + /** + * Returns the content type of the request or response extracted from the given + * {@code operation}. + * + * @param operation The operation + * @return The content type + */ protected abstract MediaType getContentType(Operation operation); + /** + * Returns the content of the request or response extracted form the given + * {@code operation}. + * + * @param operation The operation + * @return The content + * @throws IOException if the content cannot be extracted + */ protected abstract byte[] getContent(Operation operation) throws IOException; } \ No newline at end of file diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java index 72b0494a..c32df1ba 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/PayloadDocumentation.java @@ -136,7 +136,7 @@ public abstract class PayloadDocumentation { */ public static Snippet requestFields(Map attributes, FieldDescriptor... descriptors) { - return new RequestFieldsSnippet(attributes, Arrays.asList(descriptors)); + return new RequestFieldsSnippet(Arrays.asList(descriptors), attributes); } /** @@ -177,7 +177,7 @@ public abstract class PayloadDocumentation { */ public static Snippet responseFields(Map attributes, FieldDescriptor... descriptors) { - return new ResponseFieldsSnippet(attributes, Arrays.asList(descriptors)); + return new ResponseFieldsSnippet(Arrays.asList(descriptors), attributes); } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/RequestFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/RequestFieldsSnippet.java index 1f72d4a3..130357fa 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/RequestFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/RequestFieldsSnippet.java @@ -28,15 +28,32 @@ import org.springframework.restdocs.snippet.Snippet; * A {@link Snippet} that documents the fields in a request. * * @author Andy Wilkinson + * @see PayloadDocumentation#requestFields(FieldDescriptor...) + * @see PayloadDocumentation#requestFields(Map, FieldDescriptor...) */ -class RequestFieldsSnippet extends AbstractFieldsSnippet { +public class RequestFieldsSnippet extends AbstractFieldsSnippet { - RequestFieldsSnippet(List descriptors) { - this(null, descriptors); + /** + * Creates a new {@code RequestFieldsSnippet} that will document the fields in the + * request using the given {@code descriptors}. + * + * @param descriptors the descriptors + */ + protected RequestFieldsSnippet(List descriptors) { + this(descriptors, null); } - RequestFieldsSnippet(Map attributes, List descriptors) { - super("request", attributes, descriptors); + /** + * Creates a new {@code RequestFieldsSnippet} that will document the fields in the + * request using the given {@code descriptors}. The given {@code attributes} will be + * included in the model during template rendering. + * + * @param descriptors the descriptors + * @param attributes the additional attributes + */ + protected RequestFieldsSnippet(List descriptors, + Map attributes) { + super("request", descriptors, attributes); } @Override diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/ResponseFieldsSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/ResponseFieldsSnippet.java index 4cd92cea..4e829cad 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/ResponseFieldsSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/payload/ResponseFieldsSnippet.java @@ -27,16 +27,32 @@ import org.springframework.restdocs.snippet.Snippet; * A {@link Snippet} that documents the fields in a response. * * @author Andy Wilkinson + * @see PayloadDocumentation#responseFields(FieldDescriptor...) + * @see PayloadDocumentation#responseFields(Map, FieldDescriptor...) */ -class ResponseFieldsSnippet extends AbstractFieldsSnippet { +public class ResponseFieldsSnippet extends AbstractFieldsSnippet { - ResponseFieldsSnippet(List descriptors) { - this(null, descriptors); + /** + * Creates a new {@code ResponseFieldsSnippet} that will document the fields in the + * response using the given {@code descriptors}. + * + * @param descriptors the descriptors + */ + protected ResponseFieldsSnippet(List descriptors) { + this(descriptors, null); } - ResponseFieldsSnippet(Map attributes, - List descriptors) { - super("response", attributes, descriptors); + /** + * Creates a new {@code ResponseFieldsSnippet} that will document the fields in the + * response using the given {@code descriptors}. The given {@code attributes} will be + * included in the model during template rendering. + * + * @param descriptors the descriptors + * @param attributes the additional attributes + */ + protected ResponseFieldsSnippet(List descriptors, + Map attributes) { + super("response", descriptors, attributes); } @Override diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java index df0411dc..0a89f4c2 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/AbstractParametersSnippet.java @@ -30,12 +30,29 @@ import org.springframework.restdocs.operation.Operation; import org.springframework.restdocs.snippet.TemplatedSnippet; import org.springframework.util.Assert; -abstract class AbstractParametersSnippet extends TemplatedSnippet { +/** + * Abstract {@link TemplatedSnippet} subclass that provides a base for snippets that + * document parameters from a request sent to a RESTful resource. + * + * @author Andreas Evers + * @author Andy Wilkinson + */ +public abstract class AbstractParametersSnippet extends TemplatedSnippet { private final Map descriptorsByName = new LinkedHashMap<>(); + /** + * Creates a new {@code AbstractParametersSnippet} that will produce a snippet with + * the given {@code snippetName} that will document parameters using the given + * {@code descriptors}. The given {@code attributes} will be included in the model + * during template rendering. + * + * @param snippetName The snippet name + * @param descriptors The descriptors + * @param attributes The additional attributes + */ protected AbstractParametersSnippet(String snippetName, - Map attributes, List descriptors) { + List descriptors, Map attributes) { super(snippetName, attributes); for (ParameterDescriptor descriptor : descriptors) { Assert.hasText(descriptor.getName()); diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java index 99c3c765..4082d282 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/PathParametersSnippet.java @@ -33,28 +33,44 @@ import org.springframework.util.Assert; * A {@link Snippet} that documents the path parameters supported by a RESTful resource. * * @author Andy Wilkinson + * @see RequestDocumentation#pathParameters(ParameterDescriptor...) + * @see RequestDocumentation#pathParameters(Map, ParameterDescriptor...) */ -class PathParametersSnippet extends AbstractParametersSnippet { +public class PathParametersSnippet extends AbstractParametersSnippet { private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}"); - PathParametersSnippet(List descriptors) { - this(null, descriptors); + /** + * Creates a new {@code PathParametersSnippet} that will document the request's path + * parameters using the given {@code descriptors}. + * + * @param descriptors the parameter descriptors + */ + protected PathParametersSnippet(List descriptors) { + this(descriptors, null); } - PathParametersSnippet(Map attributes, - List descriptors) { - super("path-parameters", attributes, descriptors); + /** + * Creates a new {@code PathParametersSnippet} that will document the request's path + * parameters using the given {@code descriptors}. The given {@code attributes} will + * be included in the model during template rendering. + * + * @param descriptors the parameter descriptors + * @param attributes the additional attributes + */ + protected PathParametersSnippet(List descriptors, + Map attributes) { + super("path-parameters", descriptors, attributes); } @Override protected Map createModel(Operation operation) throws IOException { Map model = super.createModel(operation); - model.put("path", remoteQueryStringIfPresent(extractUrlTemplate(operation))); + model.put("path", removeQueryStringIfPresent(extractUrlTemplate(operation))); return model; } - private String remoteQueryStringIfPresent(String urlTemplate) { + private String removeQueryStringIfPresent(String urlTemplate) { int index = urlTemplate.indexOf('?'); if (index == -1) { return urlTemplate; diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestDocumentation.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestDocumentation.java index 9f3887f2..1a051077 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestDocumentation.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestDocumentation.java @@ -71,7 +71,7 @@ public abstract class RequestDocumentation { */ public static Snippet pathParameters(Map attributes, ParameterDescriptor... descriptors) { - return new PathParametersSnippet(attributes, Arrays.asList(descriptors)); + return new PathParametersSnippet(Arrays.asList(descriptors), attributes); } /** @@ -100,7 +100,7 @@ public abstract class RequestDocumentation { */ public static Snippet requestParameters(Map attributes, ParameterDescriptor... descriptors) { - return new RequestParametersSnippet(attributes, Arrays.asList(descriptors)); + return new RequestParametersSnippet(Arrays.asList(descriptors), attributes); } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java index 386fcd1a..dbe4e372 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/request/RequestParametersSnippet.java @@ -20,32 +20,45 @@ import java.util.List; import java.util.Map; import java.util.Set; -import javax.servlet.ServletRequest; - import org.springframework.restdocs.operation.Operation; +import org.springframework.restdocs.operation.OperationRequest; import org.springframework.restdocs.snippet.Snippet; import org.springframework.restdocs.snippet.SnippetException; -import org.springframework.web.bind.annotation.RequestParam; /** * A {@link Snippet} that documents the request parameters supported by a RESTful * resource. *

- * Request parameters are sent as part of the query string or as posted from data. + * Request parameters are sent as part of the query string or as POSTed form data. * * @author Andy Wilkinson - * @see ServletRequest#getParameterMap() - * @see RequestParam + * @see OperationRequest#getParameters() + * @see RequestDocumentation#requestParameters(ParameterDescriptor...) + * @see RequestDocumentation#requestParameters(Map, ParameterDescriptor...) */ -class RequestParametersSnippet extends AbstractParametersSnippet { +public class RequestParametersSnippet extends AbstractParametersSnippet { - RequestParametersSnippet(List descriptors) { - this(null, descriptors); + /** + * Creates a new {@code RequestParametersSnippet} that will document the request's + * parameters using the given {@code descriptors}. + * + * @param descriptors the parameter descriptors + */ + protected RequestParametersSnippet(List descriptors) { + this(descriptors, null); } - RequestParametersSnippet(Map attributes, - List descriptors) { - super("request-parameters", attributes, descriptors); + /** + * Creates a new {@code RequestParametersSnippet} that will document the request's + * parameters using the given {@code descriptors}. The given {@code attributes} will + * be included in the model during template rendering. + * + * @param descriptors the parameter descriptors + * @param attributes the additional attributes + */ + protected RequestParametersSnippet(List descriptors, + Map attributes) { + super("request-parameters", descriptors, attributes); } @Override diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java index 4e0cf65d..87050ce5 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/snippet/TemplatedSnippet.java @@ -38,6 +38,14 @@ public abstract class TemplatedSnippet implements Snippet { private final String snippetName; + /** + * Creates a new {@code TemplatedSnippet} that will produce a snippet with the given + * {@code snippetName}. The given {@code attributes} will be included in the model + * during rendering of the template. + * + * @param snippetName The name of the snippet + * @param attributes The additional attributes + */ protected TemplatedSnippet(String snippetName, Map attributes) { this.snippetName = snippetName; if (attributes != null) { diff --git a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/default-curl-request.snippet b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/default-curl-request.snippet index 8eaef9e1..81fe65ee 100644 --- a/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/default-curl-request.snippet +++ b/spring-restdocs-core/src/main/resources/org/springframework/restdocs/templates/default-curl-request.snippet @@ -1,4 +1,4 @@ [source,bash] ---- -$ curl {{arguments}} +$ curl {{url}} {{options}} ---- \ No newline at end of file diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java index f5a51480..24bd7ec7 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/hypermedia/LinksSnippetTests.java @@ -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(), diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java index 35168549..819dd592 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/RequestFieldsSnippetTests.java @@ -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(), diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java index 16f5a853..e8459d7f 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/payload/ResponseFieldsSnippetTests.java @@ -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(), diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java index 5c5657c8..5d858d93 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/PathParametersSnippetTests.java @@ -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}") diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java index 5a071ffd..330d411c 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/request/RequestParametersSnippetTests.java @@ -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()) diff --git a/spring-restdocs-core/src/test/resources/custom-snippet-templates/curl-request-with-title.snippet b/spring-restdocs-core/src/test/resources/custom-snippet-templates/curl-request-with-title.snippet index b53c203c..fa5ee3f4 100644 --- a/spring-restdocs-core/src/test/resources/custom-snippet-templates/curl-request-with-title.snippet +++ b/spring-restdocs-core/src/test/resources/custom-snippet-templates/curl-request-with-title.snippet @@ -1,5 +1,5 @@ [source,bash] .{{title}} ---- -$ curl {{arguments}} +$ curl {{url}} {{options}} ---- \ No newline at end of file