Skip to content

Commit 8f8b118

Browse files
committed
Merge branch '2.0.x'
2 parents a6687cf + 90e0721 commit 8f8b118

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/HttpieRequestSnippet.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,11 @@ private String getRequestItems(CliOperationRequest request) {
122122
}
123123

124124
private void writeOptions(OperationRequest request, PrintWriter writer) {
125-
if (!request.getParts().isEmpty() || (!request.getParameters().getUniqueParameters(request.getUri()).isEmpty()
126-
&& !includeParametersInUri(request) && includeParametersAsFormOptions(request))) {
125+
if (!request.getParts().isEmpty()) {
126+
writer.print("--multipart ");
127+
}
128+
else if (!request.getParameters().getUniqueParameters(request.getUri()).isEmpty()
129+
&& !includeParametersInUri(request) && includeParametersAsFormOptions(request)) {
127130
writer.print("--form ");
128131
}
129132
}
@@ -156,8 +159,7 @@ private void writeFormDataIfNecessary(OperationRequest request, List<String> lin
156159
StringBuilder oneLine = new StringBuilder();
157160
oneLine.append(String.format("'%s'", part.getName()));
158161
if (!StringUtils.hasText(part.getSubmittedFileName())) {
159-
// https://github.com/jkbrzt/httpie/issues/342
160-
oneLine.append(String.format("@<(echo '%s')", part.getContentAsString()));
162+
oneLine.append(String.format("='%s'", part.getContentAsString()));
161163
}
162164
else {
163165
oneLine.append(String.format("@'%s'", part.getSubmittedFileName()));

spring-restdocs-core/src/test/java/org/springframework/restdocs/cli/HttpieRequestSnippetTests.java

+7-7
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,8 @@ public void multipartPostWithNoSubmittedFileName() throws IOException {
262262
.document(this.operationBuilder.request("http://localhost/upload").method("POST")
263263
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
264264
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
265-
String expectedContent = "$ http --form POST 'http://localhost/upload'"
266-
+ " 'metadata'@<(echo '{\"description\": \"foo\"}')";
265+
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
266+
+ " 'metadata'='{\"description\": \"foo\"}'";
267267
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
268268
}
269269

@@ -275,7 +275,7 @@ public void multipartPostWithContentType() throws IOException {
275275
.part("image", new byte[0]).header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
276276
.submittedFileName("documents/images/example.png").build());
277277
// httpie does not yet support manually set content type by part
278-
String expectedContent = "$ http --form POST 'http://localhost/upload'"
278+
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
279279
+ " 'image'@'documents/images/example.png'";
280280
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
281281
}
@@ -286,7 +286,7 @@ public void multipartPost() throws IOException {
286286
.document(this.operationBuilder.request("http://localhost/upload").method("POST")
287287
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
288288
.part("image", new byte[0]).submittedFileName("documents/images/example.png").build());
289-
String expectedContent = "$ http --form POST 'http://localhost/upload'"
289+
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
290290
+ " 'image'@'documents/images/example.png'";
291291
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
292292
}
@@ -298,7 +298,7 @@ public void multipartPostWithParameters() throws IOException {
298298
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
299299
.part("image", new byte[0]).submittedFileName("documents/images/example.png").and()
300300
.param("a", "apple", "avocado").param("b", "banana").build());
301-
String expectedContent = "$ http --form POST 'http://localhost/upload'"
301+
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
302302
+ " 'image'@'documents/images/example.png' 'a=apple' 'a=avocado'" + " 'b=banana'";
303303
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
304304
}
@@ -310,8 +310,8 @@ public void multipartPostWithOverlappingPartsAndParameters() throws IOException
310310
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
311311
.part("image", new byte[0]).submittedFileName("documents/images/example.png").and()
312312
.part("a", "apple".getBytes()).and().param("a", "apple").build());
313-
String expectedContent = "$ http --form POST 'http://localhost/upload'"
314-
+ " 'image'@'documents/images/example.png' 'a'@<(echo 'apple')";
313+
String expectedContent = "$ http --multipart POST 'http://localhost/upload'"
314+
+ " 'image'@'documents/images/example.png' 'a'='apple'";
315315
assertThat(this.generatedSnippets.httpieRequest()).is(codeBlock("bash").withContent(expectedContent));
316316
}
317317

0 commit comments

Comments
 (0)