swagger-api / swagger-api/swagger-codegen
Qt/C++ generated code crashes if response is of type string
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
Qt/C++ code crashes during the API callback when output is cast to QString*
On Mac, this causes a fatal SIGSEGV exception in QtCore at QString::append(QString const&) + 17 according to the crash log.
Swagger-codegen version
Current version used by http://editor.swagger.io/#/ at time of posting.
Steps to reproduce
Include the following in the yaml:
responses:
'200':
description: OK
schema:
type: string
title: jsonData
then:
- Generate Qt/C++ code
- Create a slot corresponding to the callback and connect the callback signal to it
- Instantiate the API interface class (e.g. SWGDefaultApi) and call the endpoint
Suggest a Fix
I believe the problem is this line of code:
I believe the solution is to detect when {{returnType}} is QString* and in this case just replace the line with:
{{{returnType}}} output = &json;
I have tested this locally by replacing (in the generated code)
QString* output = static_cast<QString*>(create(json, QString("QString")));
with
QString* output = &json;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache around line 169 and reproduce the issue with a response schema whose type is string. Inspect the generated Qt/C++ callback code and compare the QString* handling with the reported replacement. Done means generated code handles string responses without the callback crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 50/100