spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 734 forks source link

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

Open ke4 opened 4 years ago

ke4 commented 4 years ago

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.

wilkinsona commented 4 years ago

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