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

Open
#650 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
50/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
java, spring
Domain
cli, tooling

Research direction

Start with spring-restdocs-core/src/main/java/org/springframework/restdocs/cli/CurlRequestSnippet.java, especially line 148 and the other writer methods where single quotes are hardcoded. Review how curl and HTTPie request snippets are generated, then define the quote behavior requested by the issue. Done means generated requests support the chosen quote behavior and allow $TOKEN substitution when double quotes are used.

Written by the indexing model from the issue text.

Description

type: enhancement

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.

Dominant language
Java
Stars
1.2k
Forks
731
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spring-projects/spring-restdocs

All issues in spring-projects/spring-restdocs

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.