swagger-api / swagger-api/swagger-codegen

qt5cpp codegen appears wrong for arrays of integers

Open
#12,256 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The qt5cpp code generated for arrays of integers appears incorrect.

java -jar swagger-codegen-cli.jar generate -i Test.yaml -l qt5cpp -o out

definitions:
  Test:
    description: A test case
    properties:
     title:
       type: string
     data:
       type: array
       items:
         type: integer
     data2:
       type: array
       items:
         type: string
     data3:
       type: array
       items:
         type: integer
         format: int64

In this test case, string arrays work OK, but integer and int64 don't.

In generated SWGTest::asJsonObject() method, we get:

    if(data->size() > 0){
        toJsonArray((QList<void*>*)data, obj, "data", "");
    }
    if(data2->size() > 0){
        toJsonArray((QList<void*>*)data2, obj, "data2", "QString");
    }
    if(data3->size() > 0){
        toJsonArray((QList<void*>*)data3, obj, "data3", "");
    }

We can see the last parameter that specifies the inner type is correct for the string array, but not integer or int64.

If I manually change the code to:

    toJsonArray((QList<void*>*)data, obj, "data", "qint32");

And

    toJsonArray((QList<void*>*)data, obj, "data", "qint64");

Then it works.

It seems complexType isn't being substituted correctly.

Swagger-codegen version

2.4.34

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

Run the provided swagger-codegen-cli command with the Test.yaml schema, then inspect the generated SWGTest::asJsonObject() method and the qt5cpp generator templates. Trace how array element types reach toJsonArray for data, data2, and data3; done means integer arrays use qint32 or qint64 while string arrays remain correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, java
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.