Skip to content

[bash] Bug in handling security for generating clients #6526

@kenjones-cisco

Description

@kenjones-cisco
Description

Code reference section:

if{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}{{/hasAuthMethods}} [[ "${collection_type}" == "" ]]; then

If there is no security defined, generated code as following:

        #
        # Append parameters without specific cardinality
        #
        local collection_type="${operation_parameters_collection_type["${operation}:::${qparam}"]}"
 [[ "${collection_type}" == "" ]]; then

If security is defined but only does not include apiKey, generated code as following:

        #
        # Append parameters without specific cardinality
        #
        local collection_type="${operation_parameters_collection_type["${operation}:::${qparam}"]}"
 [[ "${collection_type}" == "" ]]; then

If security is defined with two entries for apiKey with one in header and one in query, generated code as following:

        #
        # Append parameters without specific cardinality
        #
        local collection_type="${operation_parameters_collection_type["${operation}:::${qparam}"]}"

        if        if [[ ${qparam} == "auth" ]]; then
Swagger-codegen version

v2.2.3

Command line used for generation

swagger-codegen-cli
generate -i api.yml -l bash -c swagger_config.json -o ./ --additional-properties hideGenerationTimestamp=true

{
  "processMarkdown": true,
  "curlOptions": "-k -s",
  "scriptName": "capi-cli",
  "generateBashCompletion": true,
  "generateZshCompletion": false,
  "hostEnvironmentVariable": "CAPI_HOST",
  "basicAuthEnvironmentVariable": "",
  "apiKeyAuthEnvironmentVariable": ""
}
Suggest a fix/enhancement

{{#hasAuthMethods}}
{{#authMethods}}
{{#isApiKey}}
{{#isKeyInQuery}}
if [[ ${qparam} == "{{keyParamName}}" ]]; then
if [[ -n "${parameter_values[@]}" ]]; then
parameter_value+="${qparam}=${parameter_values}"
{{#x-codegen-apikey-env}}
elif [[ -n "$MATRIX_API_KEY" ]]; then
parameter_value+="${qparam}=${{x-codegen-apikey-env}}"
{{/x-codegen-apikey-env}}
else
echo "Missing ApiKey!!! {{#x-codegen-apikey-env}}Define env variable {{x-codegen-apikey-env}} like 'export {{x-codegen-apikey-env}}=...' or{{/x-codegen-apikey-env}}{{^x-codegen-apikey-env}}You have to{{/x-codegen-apikey-env}} provide on command line option '{{keyParamName}}=...'"
exit 1
fi
elif{{/isKeyInQuery}}{{^isKeyInQuery}}
if{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}}{{/hasAuthMethods}} [[ "${collection_type}" == "" ]]; then

Reporting the issue; still looking at it to determine fix.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions