OpenAPITools / OpenAPITools/openapi-generator

[BUG] cpp-qt-client uses wrong header name for API key

Open
#21,616 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

The C++ generator will insert "{{name}}" as the key in the addHeaders function of the API body. Consider https://github.com/OpenAPITools/openapi-generator/blob/777b7eeea064ab0ba22242ca2d47e93de0c2084c/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache#L232

This will generate code similar to

void OAISomeApi::doSomething(...) {
    QString fullPath = QString(_serverConfigs["doSomething"][_serverIndices.value("doSomething")].URL()+"/someService/doSomething");
    
    if (_apiKeys.contains("OurAuth")) {
        addHeaders("OurAuth",_apiKeys.find("OurAuth").value());
    }

However, in this example "OurAuth" equals the name of the schema, not the value of the name field (cf. the example below).
In my understanding, and also considering how I understand the generated documentation, the addHeaders function look like

    if (_apiKeys.contains("OurAuth")) {
        addHeaders("api-key",_apiKeys.find("OurAuth").value());
    }
openapi-generator version

We are using the openAPI generator provided in the openapitools/openapi-generator-cli:v7.14.0 Docker image.

OpenAPI declaration file content or url
components:
  securitySchemes:
    OurAuth:
      type: apiKey
      in: header
      name: api-key
      description: Does something
#...
Generation Details

This is our config:

'!include': 'common.yml'
outputDir: /local/generated-rest-api/cpp/
generatorName: cpp-qt-client
additionalProperties:
    cppNamespace: SomeApi
    packageName: QtOpenAPIClient
    disallowAdditionalPropertiesIfNotPresent: false
    optionalProjectFile: false

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 with modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache at the referenced addHeaders code around line 232, then compare it with the provided OpenAPI securitySchemes example. Generate the cpp-qt-client output and verify that the API-key lookup still uses the schema key while the emitted header uses the security scheme's name field.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
api, tooling
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.