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
  • #8648
Closed
Open
Issue created Feb 09, 2021 by Administrator@rootContributor4 of 6 checklist items completed4/6 checklist items

[BUG] [C++][Qt5] Optional parameters are not optional in generated code for API

Created by: xconverge

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

The qt5 generator does not output optional parameters to the api. All parameters are still required and the client code does not provide a way of omitting them.

openapi-generator version

5.0.1

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: param1
          required: true
          in: query
          description: required parameter 1
          schema:
            type: string
        - name: param2
          required: false
          in: query
          description: should be optional parameter 2
          schema:
            type: string
      responses:
        200:
          description: Success
Generation Details
openapi-generator-cli generate -i test.yaml -g cpp-qt5-client --additional-properties=optionalProjectFile=false  -o te
stOutput
Steps to reproduce

header:

    void getEndpoint(const QString &param1, const QString &param2);

and the implementation::


void OAIDefaultApi::getEndpoint(const QString &param1, const QString &param2) {
    QString fullPath = QString(_serverConfigs["getEndpoint"][_serverIndices.value("getEndpoint")].URL()+"/endpoint");


    if (fullPath.indexOf("?") > 0)
        fullPath.append("&");
    else
        fullPath.append("?");
    fullPath.append(QUrl::toPercentEncoding("param1")).append("=").append(QUrl::toPercentEncoding(::OpenAPI::toStringValue(param1)));

    if (fullPath.indexOf("?") > 0)
        fullPath.append("&");
    else
        fullPath.append("?");
    fullPath.append(QUrl::toPercentEncoding("param2")).append("=").append(QUrl::toPercentEncoding(::OpenAPI::toStringValue(param2)));
Related issues/PRs

Similar to these bugs/associated PRs, but for qt5 of course... https://github.com/OpenAPITools/openapi-generator/issues/2012 https://github.com/OpenAPITools/openapi-generator/issues/3052

Suggest a fix

cpp-rest-sdk-client uses boost::optional and cpp-ue4 uses TOptional, so using std::optional with a flag to utilize c++17 seems pretty clean to me

QVariant could also potentially be used but then you lose a lot of the self documenting niceties of the types

Could also just be a change to the api mustache files to utilize the required parameter from the definition, and then either create an overload or utilize some sort of default parameters and detect it and not append to the fullpath if it is set to these defaults (probably not a good idea). I think std::optional is the best answer though, even though it should have a flag.

I am willing to put some legwork into this if someone wants to push me in the right direction

Assignee
Assign to
Time tracking