Skip to content

[BUG][cpp-qt5-client] Header params in api-body operations use param name instead of value #2726

Closed
@aspaseltiner

Description

@aspaseltiner

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Header parameters don't get included in requests made by cpp-qt5-client because of a mistake in the Mustache template file for the API client:

{{#headerParams}}
if ({{paramName}} != nullptr) {
input.headers.insert("{{baseName}}", "{{paramName}}");
}
{{/headerParams}}

input.headers.insert("{{baseName}}", "{{paramName}}"); should be input.headers.insert("{{baseName}}", {{paramName}});.

openapi-generator version

Docker Hub, latest

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  description: Test
  version: 0.0.1
  title: Test
tags:
  - name: test
    description: test
paths:
  /test:
    get:
      tags:
        - test
      summary: test
      operationId: test
      parameters:
        - in: header
          name: TestHeader
          schema:
            type: string
      responses:
        "200":
          description: successful operation
Command line used for generation

docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli:latest generate -i /local/api.yaml -g cpp-qt5-client -o /local/out

Steps to reproduce

Generate a C++ QT5 client using the above docker run command.

${PWD}/out/client/OAITestAPI.cpp will contain:

void
OAITestApi::test(const QString& test_header) {
    QString fullPath;
    fullPath.append(this->host).append(this->basePath).append("/test");
    
    OAIHttpRequestWorker *worker = new OAIHttpRequestWorker();
    OAIHttpRequestInput input(fullPath, "GET");

    if (test_header != nullptr) {
        input.headers.insert("TestHeader", "test_header");
    }

    foreach(QString key, this->defaultHeaders.keys()) {
        input.headers.insert(key, this->defaultHeaders.value(key));
    }

    connect(worker,
            &OAIHttpRequestWorker::on_execution_finished,
            this,
            &OAITestApi::testCallback);

    worker->execute(&input);
}

Expected output:

    if (test_header != nullptr) {
        input.headers.insert("TestHeader", test_header);
    }
Related issues/PRs
Suggest a fix

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