spring-restdocs icon indicating copy to clipboard operation
spring-restdocs copied to clipboard

Provide more control over quotes used in curl and HTTPie request snippets

Open ke4 opened this issue 6 years ago • 1 comments

Currently Spring REST Docs generates snippets using single quotes around header values:

$ curl 'https://some.url.com/teams' -i -X POST -H 'Content-Type: application/json' -H 'Accept: application/hal+json' -H 'Authorization: Bearer $TOKEN' -d '{ "name" : "Test Team" }'

In the above generated curl request $TOKEN would be an environmental variable, but because of the single quotes the variable substitution would not work. This behaviour is hard coded in CurlRequestSnippet at this line: https://github.com/spring-projects/spring-restdocs/blob/master/spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java#L148

As I checked that class I realised that the single quotes are hardcoded in each writer methods of the CurlRequestSnippet class.

Is it possible to change this behaviour either to change the single quotes to double quotes or make it configurable?

I asked this question on Stack Overflow: https://stackoverflow.com/questions/58208877/how-to-create-a-curl-snippet-with-spring-rest-docs-to-use-double-quotes-instead/58211173?noredirect=1#comment102822959_58211173 Andy Wilkinson (@wilkinsona) from the Spring team asked me to create a github issue related to this problem.

ke4 avatar Oct 15 '19 10:10 ke4

See https://github.com/spring-projects/spring-restdocs/pull/55, which switched things, for good reasons, to consistently use single quotes.

wilkinsona avatar Oct 15 '19 20:10 wilkinsona