diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java index d0f80f52..c0a7db3c 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -91,8 +91,10 @@ public class CurlRequestSnippet extends TemplatedSnippet { } private boolean includeParametersInUri(OperationRequest request) { - return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 - && !MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(request.getHeaders().getContentType())); + HttpMethod method = request.getMethod(); + return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH) + || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED + .isCompatibleWith(request.getHeaders().getContentType())); } private String getOptions(Operation operation) { diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java index 93393082..2617c80c 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -129,8 +129,10 @@ public class HttpieRequestSnippet extends TemplatedSnippet { } private boolean includeParametersInUri(OperationRequest request) { - return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 - && !MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(request.getHeaders().getContentType())); + HttpMethod method = request.getMethod(); + return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH) + || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED + .isCompatibleWith(request.getHeaders().getContentType())); } private boolean includeParametersAsFormOptions(OperationRequest request) { 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 7193bd8a..1fb83582 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 @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -92,8 +92,10 @@ public class HttpRequestSnippet extends TemplatedSnippet { } private boolean includeParametersInUri(OperationRequest request) { - return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0 - && !MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(request.getHeaders().getContentType())); + HttpMethod method = request.getMethod(); + return (method != HttpMethod.PUT && method != HttpMethod.POST && method != HttpMethod.PATCH) + || (request.getContent().length > 0 && !MediaType.APPLICATION_FORM_URLENCODED + .isCompatibleWith(request.getHeaders().getContentType())); } private List> getHeaders(OperationRequest request) { diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java index fd7d2977..779c0077 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/CurlRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -326,4 +326,20 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests { .withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X POST -d 'Some content'")); } + @Test + public void deleteWithParameters() throws IOException { + new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo") + .method("DELETE").param("a", "alpha").param("b", "bravo").build()); + assertThat(this.generatedSnippets.curlRequest()) + .is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE")); + } + + @Test + public void deleteWithQueryString() throws IOException { + new CurlRequestSnippet(this.commandFormatter).document( + this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build()); + assertThat(this.generatedSnippets.curlRequest()) + .is(codeBlock("bash").withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i " + "-X DELETE")); + } + } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java index 14579657..4ef85cb7 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -330,4 +330,20 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests { .withContent("$ echo 'Some content' | http POST " + "'http://localhost/foo?a=alpha&b=bravo'")); } + @Test + public void deleteWithParameters() throws IOException { + new HttpieRequestSnippet(this.commandFormatter).document(this.operationBuilder.request("http://localhost/foo") + .method("DELETE").param("a", "alpha").param("b", "bravo").build()); + assertThat(this.generatedSnippets.httpieRequest()) + .is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'")); + } + + @Test + public void deleteWithQueryString() throws IOException { + new HttpieRequestSnippet(this.commandFormatter).document( + this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build()); + assertThat(this.generatedSnippets.httpieRequest()) + .is(codeBlock("bash").withContent("$ http DELETE 'http://localhost/foo?a=alpha&b=bravo'")); + } + } diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java index 5ac9889d..ae9ef1a4 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/http/HttpRequestSnippetTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -307,6 +307,22 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests { assertThat(this.generatedSnippets.httpRequest()).contains("Title for the request"); } + @Test + public void deleteWithParameters() throws IOException { + new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo").method("DELETE") + .param("a", "alpha").param("b", "bravo").build()); + assertThat(this.generatedSnippets.httpRequest()) + .is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost")); + } + + @Test + public void deleteWithQueryString() throws IOException { + new HttpRequestSnippet().document( + this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo").method("DELETE").build()); + assertThat(this.generatedSnippets.httpRequest()) + .is(httpRequest(RequestMethod.DELETE, "/foo?a=alpha&b=bravo").header("Host", "localhost")); + } + private String createPart(String content) { return this.createPart(content, true); }