Skip to content

[BUG][JS] Description - ApiClient.js generated 'User-Agent' header but should be optional #12743

Description

@dcmwong
Description

When using our site in Chrome there is an error in the console:

Refused to set unsafe header "User-Agent"

We use the openapi-generator-cli tool that generates the ApiClient.js setting the header User-Agent even though we haven't specified it in the cli. There is no way, that we've seen, to tell the cli to not set the User-Agent header and therefore no way to remove the above error from Chrome, besides manually removing it after the build.

openapi-generator version

With version :

    "@openapitools/openapi-generator-cli": "^2.4.26",

The actual version in yarn is:
"resolved" "https://registry.npmjs.org/@openapitools/openapi-generator-cli/-/openapi-generator-cli-2.4.26.tgz"

Generation Details

We use: this command to generate our js client code

openapi-generator-cli generate -g javascript -i swagger.json -o api --additional-properties=usePromises=true
Steps to reproduce

Generate client js code by running the below command on an example swagger.json

openapi-generator-cli generate -g javascript -i swagger.json -o api --additional-properties=usePromises=true

Navigate to the generated code api/src/ApiClient.js you will see the User-Agent code is there:

        /**
         * The default HTTP headers to be included for all API calls.
         * @type {Array.<String>}
         * @default {}
         */
        this.defaultHeaders = {
            'User-Agent': 'OpenAPI-Generator/1.0.0/Javascript'
        };

        /**

Even though it wasn't specified.

Related issues/PRs

I believe
this commit was where the issue was introduced.

Suggest a fix

The mustache template should probably check to see if the User Agent variable was passed before generating it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions