Fix HTTP request snippet's handling of query strings and params
Closes gh-763
This commit is contained in:
@@ -134,7 +134,7 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
}
|
||||
else if (isPutOrPost(request)) {
|
||||
if (request.getParts().isEmpty()) {
|
||||
String queryString = request.getParameters().toQueryString();
|
||||
String queryString = request.getParameters().getUniqueParameters(request.getUri()).toQueryString();
|
||||
if (StringUtils.hasText(queryString)) {
|
||||
writer.println();
|
||||
writer.print(queryString);
|
||||
@@ -206,7 +206,8 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
|
||||
private boolean requiresFormEncodingContentTypeHeader(OperationRequest request) {
|
||||
return request.getHeaders().get(HttpHeaders.CONTENT_TYPE) == null && isPutOrPost(request)
|
||||
&& (!request.getParameters().isEmpty() && !includeParametersInUri(request));
|
||||
&& !request.getParameters().getUniqueParameters(request.getUri()).isEmpty()
|
||||
&& !includeParametersInUri(request);
|
||||
}
|
||||
|
||||
private Map<String, String> header(String name, String value) {
|
||||
|
||||
@@ -224,6 +224,14 @@ public class HttpRequestSnippetTests extends AbstractSnippetTests {
|
||||
.header("Content-Type", "application/x-www-form-urlencoded").content("b%26r=baz&a=alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void putRequestWithTotallyOverlappingQueryStringAndParameters() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/foo?a=alpha&b=bravo")
|
||||
.method("PUT").param("a", "alpha").param("b", "bravo").build());
|
||||
assertThat(this.generatedSnippets.httpRequest())
|
||||
.is(httpRequest(RequestMethod.PUT, "/foo?a=alpha&b=bravo").header(HttpHeaders.HOST, "localhost"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartPost() throws IOException {
|
||||
new HttpRequestSnippet().document(this.operationBuilder.request("http://localhost/upload").method("POST")
|
||||
|
||||
Reference in New Issue
Block a user