OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Bash] HTTP Headers passed as `key:value` are not detected as such

Open
#5,007 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Bash Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
Description

In the generated bash script --help, one can read read this:

  my_api.sh [-h|--help] [-V|--version] [--about] [<curl-options>]
           [-ac|--accept <mime-type>] [-ct,--content-type <mime-type>]
           [--host <url>] [--dry-run] [-nc|--no-colors] <operation> [-h|--help]
           [<headers>] [<parameters>] [<body-parameters>]
[...]
  - <headers> - HTTP headers can be passed in the form HEADER:VALUE
[...]

According to that, I should be able to declare HTTP headers using the following syntax:

./my_api.sh --host example.com collectionGet header_name:header_value

And it does not work because the pattern used to match header_name:header_value is incorect.

openapi-generator version

I've checked the master branch (as of 2020/01/15) , the problem is there.

OpenAPI declaration file content or url

N/A

Command line used for generation
    docker run --rm  openapitools/openapi-generator-cli \
	   generate --skip-validate-spec -i swagger_file -g bash \
	   -o /data --additional-properties=scriptName=my_api.sh
Steps to reproduce
  1. ./my_api.sh --dry-run --host https://example.com collectionGet Authorization:xxxx

reports

curl     -X GET "https://example.com/v0/collection"

While it should report

curl   -H "Authorization:xxxx"   -X GET "https://example.com/v0/collection"
Related issues/PRs

Looked for bash in issues. Found none related.

Suggest a fix

The fix is kinda trivial. The parentheses in the pattern have been incorrectly back-slashed. Just un-back-slash them. See https://github.com/OpenAPITools/openapi-generator/commit/88c2fdbecde7c024e614ab63f78ee1b0a0c540d8

It's a regression that has been brought in commit 8b61b1d4660, apparently to satisfy an incomplete shell syntax checker.

cc: @frol @bkryza @kenjones-cisco

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.

Research direction

Start by locating the Bash generator code that parses header arguments and inspect the pattern used to recognize HEADER:VALUE. Reproduce the issue with the provided docker generation command and dry-run invocation, then verify that the output includes the expected curl header option.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash
Domain
cli
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.