-
Notifications
You must be signed in to change notification settings - Fork 738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide an option to switch off the curl snippet's use of -i #552
Comments
It's an interesting problem, but I think it applies to more than just binary content. For example, it's quite common to use curl and then pipe the response into
The current situation hinders 2 and the proposal here will hinder 1. I can't think of an alternative that will enable both. A compromise would be to make it easier to configure whether or not |
The HTTPie snippets do not have this problem. HTTPie's default behaviour is to show the full response (headers and body) when output is going to the terminal. When output has been redirected it changes its defaults so that only the body is output and binary data isn't suppressed. The problem described in this issue is largely a usability problem with curl. There's an argument to be made that the best solution is to use HTTPie rather than curl. |
@wilkinsona
I agree the only one who probably know the customers respective the concrete integration is the REST API writer.
hmmm...it depends...in my case the customers are system administrators which prefer the curl snippets. |
This worked perfectly for me. And, for anyone interested, I used this class from Kotlin, and this worked for me after a few tweaks to what IntelliJ did to convert it for me: package com.concur.sca
import org.springframework.http.MediaType
import org.springframework.http.MediaType.APPLICATION_JSON
import org.springframework.restdocs.cli.CommandFormatter
import org.springframework.restdocs.cli.CurlRequestSnippet
import org.springframework.restdocs.operation.Operation
class CustomCurlRequestSnippet(commandFormatter: CommandFormatter?) :
CurlRequestSnippet(commandFormatter) {
override fun createModel(operation: Operation): Map<String, Any> {
val model = super.createModel(operation)
val responseContentType : MediaType? = operation.response.headers!!.contentType
if (responseContentType != null &&
operation.response.content.isNotEmpty() && !responseContentType.isCompatibleWith(APPLICATION_JSON)
) {
val options = model["options"] as String?
model["options"] = options!!.replace("-i ", "")
}
return model
}
} I am now able to literally copy-paste-run examples from my API doc in our testing environment and pipe the output to Thanks again! |
Situation
In case that a REST Endpoint provide a binary content ex.
application/zip
. The generated curl request snippet should not contains the curl options-i
. Because it include HTTP headers in the curl response stream and processing of that content will fail.HINT
Most user will copy that curl command and save the binary content with curl option
-o export.zip
.Proposal
In case the response payload is not text based the curl option
-i
will not added in the snippetWorkaround
Create a custom CurlRequestSnippet which remove the options -i and register it
The text was updated successfully, but these errors were encountered: