Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #6218
Closed
Open
Issue created May 08, 2020 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG][QT5] Invalid QT5-CPP code for generated API methods when input parameter header is used

Created by: ghost

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

The generated CPP QT5 code is invalid when generating code using the SPEC below, although SPEC is valid.

More precisely, the cpp-qt5-client mustache code is affected at least in file:

  • api-body.mustache / api-header.mustache

In the generated code file "TestDefaultApi.cpp", the following method is invalid due to following two errors:

  • nullptr check to a const reference
  • insert into header list with invalid type <QString, TestLocale>. Needed types are <QString, QString>. TestLocale is the generated class, and has no QString() operator.
void TestDefaultApi::getEndpoint(const TestLocale &accept_language) {
    ...
    if (accept_language != nullptr) {
        input.headers.insert("Accept-Language", accept_language);
    }
    ...
}
openapi-generator version

First appearance in 4.3.0. Problem exists also in 4.3.1 and 4.2.3. and probably also lower versions.

OpenAPI declaration file content or url
openapi: 3.0.0
info:
  version: 0.0.1
  title: Test
paths:
  /endpoint:
    get:
      operationId: getEndpoint
      description: "-"
      parameters:
      - name: Accept-Language
        in: header
        schema:
          $ref: '#/components/schemas/Locale'
      responses:
        200:
          description: Success
components:
  schemas:
    Locale:
      type: string
      description: 'Locale'
      enum: [ de_AT, en_US ]
Command line used for generation

java -cp openapi-generator-cli-4.3.1.jar org.openapitools.codegen.OpenAPIGenerator generate -i -g cpp-qt5-client -o ./ --model-name-prefix Test

Steps to reproduce
Related issues/PRs
Suggest a fix

Two approaches came quickly into my mind:

  1. Add an "generally applicable" QString operator() to the model-header.mustache code. This code might be similar as the asJson() mustache-code parts (but only returns the plain value as QString representation if set). This QString operator() is afterwards called in the api-body.mustache part, e.g.:
{{#headerParams}}
    if (!(static_cast<QString>({{paramName}}).isEmpty())) {
        input.headers.insert("{{baseName}}", static_cast<QString>({{paramName}})); // <-- QString() operator is called
    }
{{/headerParams}}
  1. An "addHeader" method already exists in api-body.mustache, which is fine. Therefore, remove the method input parameter and the code-part below from the mustache code which creates the endpoint API call (e.g. void TestDefaultApi::getEndpoint(const TestLocale &accept_language)). But only iff the input parameter is used for inserting headers (and the code below is created):
{{#headerParams}}
...
{{/headerParams}}
Assignee
Assign to
Time tracking