Skip to content

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

Open
@Anvil

Description

@Anvil

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 88c2fdb

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

cc: @frol @bkryza @kenjones-cisco

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions