Polish contribution
This commit polishes the HTTPie request snippet contribution made in
b26d8c0. It makes the following significant changes:
- Applies project’s coding conventions for formatting and the like
- Moves to a composition-based approach for sharing functionality
between the curl and HTTPie snippets by replacing AbstractCliSnippet
with CliOperationRequest.
- Introduces a single package for CLI command snippets, thereby allowing
more code to be package-private.
See gh-207
This commit is contained in:
@@ -87,11 +87,12 @@ include::{examples-dir}/com/example/restassured/CustomFormat.java[tags=custom-fo
|
||||
[[configuration-default-snippets]]
|
||||
=== Default snippets
|
||||
|
||||
Three snippets are produced by default:
|
||||
Four snippets are produced by default:
|
||||
|
||||
- `curl-request`
|
||||
- `http-request`
|
||||
- `http-response`
|
||||
- `httpie-request`
|
||||
|
||||
You can change the default snippet configuration during setup using the
|
||||
`RestDocumentationConfigurer` API. For example, to only produce the `curl-request`
|
||||
|
||||
@@ -374,9 +374,9 @@ static `document` method on
|
||||
By default, four snippets are written:
|
||||
|
||||
* `<output-directory>/index/curl-request.adoc`
|
||||
* `<output-directory>/index/httpie-request.adoc`
|
||||
* `<output-directory>/index/http-request.adoc`
|
||||
* `<output-directory>/index/http-response.adoc`
|
||||
* `<output-directory>/index/httpie-request.adoc`
|
||||
|
||||
Refer to <<documenting-your-api>> for more information about these and other snippets
|
||||
that can be produced by Spring REST Docs.
|
||||
|
||||
@@ -18,19 +18,21 @@ package com.example.mockmvc;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.springframework.restdocs.cli.curl.CurlDocumentation.curlRequest;
|
||||
import static org.springframework.restdocs.cli.CliDocumentation.curlRequest;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
|
||||
|
||||
public class CustomDefaultSnippets {
|
||||
|
||||
@Rule
|
||||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build");
|
||||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(
|
||||
"build");
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext context;
|
||||
@@ -41,8 +43,8 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withDefaults(curlRequest()))
|
||||
.apply(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
@@ -16,20 +16,21 @@
|
||||
|
||||
package com.example.restassured;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
|
||||
import com.jayway.restassured.builder.RequestSpecBuilder;
|
||||
import com.jayway.restassured.specification.RequestSpecification;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
import static org.springframework.restdocs.cli.curl.CurlDocumentation.curlRequest;
|
||||
import org.springframework.restdocs.JUnitRestDocumentation;
|
||||
|
||||
import static org.springframework.restdocs.cli.CliDocumentation.curlRequest;
|
||||
import static org.springframework.restdocs.restassured.RestAssuredRestDocumentation.documentationConfiguration;
|
||||
|
||||
public class CustomDefaultSnippets {
|
||||
|
||||
@Rule
|
||||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation("build");
|
||||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation(
|
||||
"build");
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
@@ -37,8 +38,8 @@ public class CustomDefaultSnippets {
|
||||
public void setUp() {
|
||||
// tag::custom-default-snippets[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation)
|
||||
.snippets().withDefaults(curlRequest()))
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).snippets()
|
||||
.withDefaults(curlRequest()))
|
||||
.build();
|
||||
// end::custom-default-snippets[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user