swagger-api/swagger-codegen

Qt/C++ generated code crashes if response is of type string

Open

#4.835 geöffnet am 22. Feb. 2017

Auf GitHub ansehen
 (3 Kommentare) (0 Reaktionen) (0 zugewiesene Personen)HTML (5.474 Forks)batch import
Client: QTIssue: Bughelp wanted

Repository-Metriken

Stars
 (12.701 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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:

  1. Generate Qt/C++ code
  2. Create a slot corresponding to the callback and connect the callback signal to it
  3. Instantiate the API interface class (e.g. SWGDefaultApi) and call the endpoint
Suggest a Fix

I believe the problem is this line of code:

https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache#L169

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