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:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.restdocs.cli.curl;
|
||||
package org.springframework.restdocs.cli;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.restdocs.cli.httpie;
|
||||
package org.springframework.restdocs.cli;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -156,8 +156,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void postRequestWithUrlEncodedParameter() throws IOException {
|
||||
this.snippet.expectHttpieRequest("post-request-with-url-encoded-parameter")
|
||||
.withContents(codeBlock("bash").content(
|
||||
"$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
|
||||
.withContents(codeBlock("bash")
|
||||
.content("$ http --form POST 'http://localhost/foo' 'k1=a&b'"));
|
||||
new HttpieRequestSnippet()
|
||||
.document(operationBuilder("post-request-with-url-encoded-parameter")
|
||||
.request("http://localhost/foo").method("POST").param("k1", "a&b")
|
||||
@@ -214,8 +214,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
@Test
|
||||
public void putRequestWithUrlEncodedParameter() throws IOException {
|
||||
this.snippet.expectHttpieRequest("put-request-with-url-encoded-parameter")
|
||||
.withContents(codeBlock("bash").content(
|
||||
"$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
|
||||
.withContents(codeBlock("bash")
|
||||
.content("$ http --form PUT 'http://localhost/foo' 'k1=a&b'"));
|
||||
new HttpieRequestSnippet()
|
||||
.document(operationBuilder("put-request-with-url-encoded-parameter")
|
||||
.request("http://localhost/foo").method("PUT").param("k1", "a&b")
|
||||
@@ -224,8 +224,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws IOException {
|
||||
this.snippet.expectHttpieRequest("request-with-headers")
|
||||
.withContents(codeBlock("bash").content("$ http GET 'http://localhost/foo'"
|
||||
this.snippet.expectHttpieRequest("request-with-headers").withContents(
|
||||
codeBlock("bash").content("$ http GET 'http://localhost/foo'"
|
||||
+ " 'Content-Type:application/json' 'a:alpha'"));
|
||||
new HttpieRequestSnippet().document(
|
||||
operationBuilder("request-with-headers").request("http://localhost/foo")
|
||||
@@ -298,7 +298,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void basicAuthCredentialsAreSuppliedUsingUserOption() throws IOException {
|
||||
public void basicAuthCredentialsAreSuppliedUsingAuthOption() throws IOException {
|
||||
this.snippet.expectHttpieRequest("basic-auth").withContents(codeBlock("bash")
|
||||
.content("$ http --auth 'user:secret' GET 'http://localhost/foo'"));
|
||||
new HttpieRequestSnippet()
|
||||
@@ -24,9 +24,9 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.restdocs.RestDocumentationContext;
|
||||
import org.springframework.restdocs.cli.curl.CurlDocumentation;
|
||||
import org.springframework.restdocs.cli.curl.CurlRequestSnippet;
|
||||
import org.springframework.restdocs.cli.httpie.HttpieRequestSnippet;
|
||||
import org.springframework.restdocs.cli.CliDocumentation;
|
||||
import org.springframework.restdocs.cli.CurlRequestSnippet;
|
||||
import org.springframework.restdocs.cli.HttpieRequestSnippet;
|
||||
import org.springframework.restdocs.generate.RestDocumentationGenerator;
|
||||
import org.springframework.restdocs.http.HttpRequestSnippet;
|
||||
import org.springframework.restdocs.http.HttpResponseSnippet;
|
||||
@@ -108,7 +108,7 @@ public class RestDocumentationConfigurerTests {
|
||||
public void customDefaultSnippets() {
|
||||
RestDocumentationContext context = new RestDocumentationContext(null, null, null);
|
||||
Map<String, Object> configuration = new HashMap<>();
|
||||
this.configurer.snippets().withDefaults(CurlDocumentation.curlRequest())
|
||||
this.configurer.snippets().withDefaults(CliDocumentation.curlRequest())
|
||||
.apply(configuration, context);
|
||||
assertThat(configuration,
|
||||
hasEntry(
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[source,bash]
|
||||
.{{title}}
|
||||
----
|
||||
$ {{echo_content}}http {{options}} {{url}}{{request_items}}
|
||||
$ {{echoContent}}http {{options}} {{url}}{{requestItems}}
|
||||
----
|
||||
@@ -1,4 +1,4 @@
|
||||
{{title}}
|
||||
```bash
|
||||
$ {{echo_content}}http {{options}} {{url}}{{request_items}}
|
||||
$ {{echoContent}}http {{options}} {{url}}{{requestItems}}
|
||||
```
|
||||
Reference in New Issue
Block a user