Merge branch '1.2.x'
This commit is contained in:
@@ -23,6 +23,7 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.operation.Operation;
|
||||
import org.springframework.restdocs.operation.OperationRequest;
|
||||
import org.springframework.restdocs.operation.OperationRequestPart;
|
||||
@@ -96,7 +97,9 @@ public class CurlRequestSnippet extends TemplatedSnippet {
|
||||
}
|
||||
|
||||
private boolean includeParametersInUri(OperationRequest request) {
|
||||
return request.getMethod() == HttpMethod.GET || request.getContent().length > 0;
|
||||
return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0
|
||||
&& !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private String getOptions(Operation operation) {
|
||||
|
||||
@@ -129,13 +129,22 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
|
||||
private void writeOptions(OperationRequest request, PrintWriter writer) {
|
||||
if (!request.getParts().isEmpty()
|
||||
|| (!request.getParameters().getUniqueParameters(request.getUri())
|
||||
.isEmpty() && !includeParametersInUri(request))) {
|
||||
.isEmpty() && !includeParametersInUri(request)
|
||||
&& includeParametersAsFormOptions(request))) {
|
||||
writer.print("--form ");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean includeParametersInUri(OperationRequest request) {
|
||||
return request.getMethod() == HttpMethod.GET || request.getContent().length > 0;
|
||||
return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0
|
||||
&& !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private boolean includeParametersAsFormOptions(OperationRequest request) {
|
||||
return request.getMethod() != HttpMethod.GET && (request.getContent().length == 0
|
||||
|| !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private void writeUserOptionIfNecessary(CliOperationRequest request,
|
||||
|
||||
@@ -94,7 +94,9 @@ public class HttpRequestSnippet extends TemplatedSnippet {
|
||||
}
|
||||
|
||||
private boolean includeParametersInUri(OperationRequest request) {
|
||||
return request.getMethod() == HttpMethod.GET || request.getContent().length > 0;
|
||||
return request.getMethod() == HttpMethod.GET || (request.getContent().length > 0
|
||||
&& !MediaType.APPLICATION_FORM_URLENCODED
|
||||
.isCompatibleWith(request.getHeaders().getContentType()));
|
||||
}
|
||||
|
||||
private List<Map<String, String>> getHeaders(OperationRequest request) {
|
||||
|
||||
Reference in New Issue
Block a user