From 12f3661d6fc56f0c7a828c6f7f751f3e40ebfe22 Mon Sep 17 00:00:00 2001 From: etherealjoy <33183834+etherealjoy@users.noreply.github.com> Date: Wed, 7 Mar 2018 13:54:40 +0100 Subject: [PATCH] Qt5cpp plug memleaks (#7695) * Small fixes to prevent crash when empty json body is provided. * WIP: plug mem-leaks * fixup: add the QJsonObject instance in toJsonArray instead of pointer * fixup: simplify toJsonMap Actually the original solution is incomplete, because "innerType" maps to a single C++ type. Have a look at Qt's builtin QJsonObject::fromVariantMap. * Updates to antis81:patch-1 after tests. * update to remove string allocation * Updates due to address of members being passed * Update PetStore Examples * Small updates for Header includes --- .../resources/qt5cpp/HttpRequest.cpp.mustache | 2 +- .../main/resources/qt5cpp/api-body.mustache | 6 +- .../resources/qt5cpp/helpers-body.mustache | 83 +++++++++---------- .../resources/qt5cpp/helpers-header.mustache | 7 +- .../main/resources/qt5cpp/model-body.mustache | 33 ++++---- .../resources/qt5cpp/model-header.mustache | 10 +-- .../resources/qt5cpp/modelFactory.mustache | 10 +-- .../src/main/resources/qt5cpp/object.mustache | 10 +-- .../petstore/qt5cpp/client/SWGApiResponse.cpp | 19 ++--- .../petstore/qt5cpp/client/SWGApiResponse.h | 10 +-- .../petstore/qt5cpp/client/SWGCategory.cpp | 19 ++--- .../petstore/qt5cpp/client/SWGCategory.h | 10 +-- .../petstore/qt5cpp/client/SWGHelpers.cpp | 81 +++++++++--------- .../petstore/qt5cpp/client/SWGHelpers.h | 6 +- .../petstore/qt5cpp/client/SWGHttpRequest.cpp | 2 +- .../petstore/qt5cpp/client/SWGModelFactory.h | 9 +- .../client/petstore/qt5cpp/client/SWGObject.h | 8 +- .../petstore/qt5cpp/client/SWGOrder.cpp | 25 +++--- .../client/petstore/qt5cpp/client/SWGOrder.h | 10 +-- .../client/petstore/qt5cpp/client/SWGPet.cpp | 19 ++--- .../client/petstore/qt5cpp/client/SWGPet.h | 10 +-- .../petstore/qt5cpp/client/SWGStoreApi.cpp | 2 +- .../client/petstore/qt5cpp/client/SWGTag.cpp | 19 ++--- .../client/petstore/qt5cpp/client/SWGTag.h | 10 +-- .../client/petstore/qt5cpp/client/SWGUser.cpp | 21 +++-- .../client/petstore/qt5cpp/client/SWGUser.h | 10 +-- .../petstore/qt5cpp/client/SWGUserApi.cpp | 8 +- 27 files changed, 219 insertions(+), 240 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/HttpRequest.cpp.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/HttpRequest.cpp.mustache index cf3a82bece54..594fe111fa3e 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/HttpRequest.cpp.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/HttpRequest.cpp.mustache @@ -47,7 +47,7 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f qsrand(QDateTime::currentDateTime().toTime_t()); manager = new QNetworkAccessManager(this); - connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_manager_finished(QNetworkReply*))); + connect(manager, &QNetworkAccessManager::finished, this, &{{prefix}}HttpRequestWorker::on_manager_finished); } {{prefix}}HttpRequestWorker::~{{prefix}}HttpRequestWorker() { diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache index 3188753295f2..80edd8b10240 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache @@ -98,10 +98,10 @@ void {{#bodyParams}} {{#isContainer}} - auto {{paramName}}_jobj = new QJsonObject(); + QJsonObject {{paramName}}_jobj; toJsonArray((QList*){{paramName}}, {{paramName}}_jobj, QString("body"), QString("{{prefix}}User*")); - QJsonDocument doc(*{{paramName}}_jobj); + QJsonDocument doc({{paramName}}_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -175,7 +175,7 @@ void foreach(QString key, obj.keys()) { qint32* val; - setValue(&val, obj[key], "{{returnBaseType}}", ""); + setValue(&val, obj[key], "{{returnBaseType}}", QString()); output->insert(key, *val); } {{/isMapContainer}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache index 1ef996838b8b..0b35496ff64c 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -32,7 +32,7 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } else if(QStringLiteral("float").compare(type) == 0) { float *val = static_cast(value); - *val = obj.toDouble(); + *val = static_cast(obj.toDouble()); } else if(QStringLiteral("double").compare(type) == 0) { double *val = static_cast(value); @@ -42,20 +42,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { QString **val = static_cast(value); if(val != nullptr) { if(!obj.isNull()) { - // create a new value and return - if(*val != nullptr) delete *val; - *val = new QString(obj.toString()); + (*val)->clear(); + (*val)->append(obj.toString()); return; } else { - // set target to nullptr - if(*val != nullptr) delete *val; - *val = nullptr; + (*val)->clear(); } } - else { - qDebug() << "Can't set value because the target pointer is nullptr"; - } } else if (QStringLiteral("QDateTime").compare(type) == 0) { QDateTime **val = static_cast(value); @@ -371,67 +365,66 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } void -toJsonValue(QString name, void* value, QJsonObject* output, QString type) { +toJsonValue(QString name, void* value, QJsonObject& output, QString type) { if(value == nullptr) { return; } if(type.startsWith("{{prefix}}")) { {{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(value); if({{prefix}}object != nullptr) { - QJsonObject* o = (*{{prefix}}object).asJsonObject(); - if(name != nullptr) { - output->insert(name, *o); - if(o != nullptr) delete o; + QJsonObject o = {{prefix}}object->asJsonObject(); + if(!name.isNull()) { + output.insert(name, o); } else { - output->empty(); - for(QString key : o->keys()) { - output->insert(key, o->value(key)); + output.empty(); + for(QString key : o.keys()) { + output.insert(key, o.value(key)); } } } } else if(QStringLiteral("QString").compare(type) == 0) { QString* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint32").compare(type) == 0) { qint32* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint64").compare(type) == 0) { qint64* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("bool").compare(type) == 0) { bool* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("float").compare(type) == 0) { float* str = static_cast(value); - output->insert(name, QJsonValue((double)*str)); + output.insert(name, QJsonValue((double)*str)); } else if(QStringLiteral("double").compare(type) == 0) { double* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("QDate").compare(type) == 0) { QDate* date = static_cast(value); - output->insert(name, QJsonValue(date->toString(Qt::ISODate))); + output.insert(name, QJsonValue(date->toString(Qt::ISODate))); } else if(QStringLiteral("QDateTime").compare(type) == 0) { QDateTime* datetime = static_cast(value); - output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); + output.insert(name, QJsonValue(datetime->toString(Qt::ISODate))); } else if(QStringLiteral("QByteArray").compare(type) == 0) { QByteArray* byteArray = static_cast(value); - output->insert(name, QJsonValue(QString(byteArray->toBase64()))); + output.insert(name, QJsonValue(QString(byteArray->toBase64()))); } } void -toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType) { - if((value == nullptr) || (output == nullptr)) { +toJsonArray(QList* value, QJsonObject& output, QString innerName, QString innerType) { + if(value == nullptr) { return; } QJsonArray outputarray; @@ -439,7 +432,7 @@ toJsonArray(QList* value, QJsonObject* output, QString innerName, QString for(void* obj : *value) { {{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(obj); if({{prefix}}object != nullptr) { - outputarray.append(*({{prefix}}object->asJsonObject())); + outputarray.append({{prefix}}object->asJsonObject()); } } } @@ -482,81 +475,81 @@ toJsonArray(QList* value, QJsonObject* output, QString innerName, QString for(double obj : *(reinterpret_cast*>(value))) outputarray.append(QJsonValue(obj)); } - output->insert(innerName, outputarray); + output.insert(innerName, outputarray); } void -toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType) { - if((value == nullptr) || (output == nullptr)) { +toJsonMap(QMap* value, QJsonObject& output, QString innerName, QString innerType) { + if(value == nullptr) { return; } QJsonObject mapobj; if(innerType.startsWith("{{prefix}}")){ auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey),mapobj, innerType); } } else if(QStringLiteral("QString").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QDate").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QDateTime").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QByteArray").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("qint32").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("qint64").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("bool").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("float").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("double").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys() ) { auto val = items->value(itemkey); - ::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); + ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType); } } - output->insert(innerName, mapobj); + output.insert(innerName, mapobj); } QString @@ -582,4 +575,4 @@ stringValue(bool value) { {{#cppNamespaceDeclarations}} } -{{/cppNamespaceDeclarations}} \ No newline at end of file +{{/cppNamespaceDeclarations}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache index b40c2ee8ba6c..a74e3b15cd95 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache @@ -2,6 +2,7 @@ #ifndef {{prefix}}_HELPERS_H #define {{prefix}}_HELPERS_H +#include #include #include #include @@ -11,9 +12,9 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} void setValue(void* value, QJsonValue obj, QString type, QString complexType); - void toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType); - void toJsonValue(QString name, void* value, QJsonObject* output, QString type); - void toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType); + void toJsonArray(QList* value, QJsonObject& output, QString innerName, QString innerType); + void toJsonValue(QString name, void* value, QJsonObject& output, QString type); + void toJsonMap(QMap* value, QJsonObject& output, QString innerName, QString innerType); bool isCompatibleJsonValue(QString type); QString stringValue(QString* value); QString stringValue(qint32 value); diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache index b75312dd995e..7728ac58369c 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache @@ -13,9 +13,9 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} -{{classname}}::{{classname}}(QString* json) { +{{classname}}::{{classname}}(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } {{classname}}::{{classname}}() { @@ -52,7 +52,7 @@ void } {{classname}}* -{{classname}}::fromJson(QString &json) { +{{classname}}::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -61,7 +61,7 @@ void } void -{{classname}}::fromJsonObject(QJsonObject &pJson) { +{{classname}}::fromJsonObject(QJsonObject pJson) { {{#vars}} {{^isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/isContainer}} {{#isContainer}}{{^items.isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}");{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}} @@ -94,16 +94,15 @@ void QString {{classname}}::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject {{classname}}::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; {{#vars}} {{^isContainer}} {{#complexType}} @@ -129,7 +128,7 @@ QJsonObject* {{^isDate}} {{^isByteArray}} if(m_{{name}}_isSet){ - obj->insert("{{baseName}}", QJsonValue({{name}})); + obj.insert("{{baseName}}", QJsonValue({{name}})); } {{/isByteArray}} {{/isDate}} @@ -142,7 +141,7 @@ QJsonObject* {{/isDate}} {{#isByteArray}} if({{name}} != nullptr) { - obj->insert("{{name}}", QJsonValue(*{{name}})); + obj.insert("{{name}}", QJsonValue(*{{name}})); } {{/isByteArray}} {{#isDateTime}} @@ -162,14 +161,14 @@ QJsonObject* for(auto items : *{{name}}){ QJsonObject jobj; {{#items.isListContainer}} - toJsonArray((QList*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}"); + toJsonArray((QList*)items, jobj, "{{baseName}}", "{{items.items.baseType}}"); {{/items.isListContainer}} {{#items.isMapContainer}} - toJsonMap((QMap*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}"); + toJsonMap((QMap*)items, jobj, "{{baseName}}", "{{items.items.baseType}}"); {{/items.isMapContainer}} jarray.append(jobj.value("{{baseName}}")); } - obj->insert("{{baseName}}", jarray); + obj.insert("{{baseName}}", jarray); {{/items.isContainer}} } {{/isListContainer}} @@ -180,14 +179,14 @@ QJsonObject* for(auto itemkey : {{name}}->keys()){ QJsonObject jobj; {{#items.isListContainer}} - toJsonArray((QList*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}"); + toJsonArray((QList*){{name}}->value(itemkey), jobj, itemkey, "{{items.items.baseType}}"); {{/items.isListContainer}} {{#items.isMapContainer}} - toJsonMap((QMap*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}"); + toJsonMap((QMap*){{name}}->value(itemkey), jobj, itemkey, "{{items.items.baseType}}"); {{/items.isMapContainer}} mapobj.insert(itemkey, jobj); } - obj->insert("{{baseName}}", mapobj);{{/items.isContainer}} + obj.insert("{{baseName}}", mapobj);{{/items.isContainer}} } {{/isMapContainer}} {{/isContainer}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache index d042330567b8..0150f5b6b9da 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache @@ -25,15 +25,15 @@ namespace {{this}} { class {{classname}}: public {{prefix}}Object { public: {{classname}}(); - {{classname}}(QString* json); - virtual ~{{classname}}(); + {{classname}}(QString json); + ~{{classname}}(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - {{classname}}* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + {{classname}}* fromJson(QString jsonString); {{#vars}} {{{datatype}}} {{getter}}(); diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache index c1fbc136433d..0b1c789d6189 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache @@ -2,6 +2,7 @@ #ifndef ModelFactory_H_ #define ModelFactory_H_ +#include "{{prefix}}Object.h" {{#models}}{{#model}} #include "{{classname}}.h"{{/model}}{{/models}} @@ -18,13 +19,12 @@ namespace {{this}} { } inline void* create(QString json, QString type) { - void* val = create(type); - if(val != nullptr) { - {{prefix}}Object* obj = static_cast<{{prefix}}Object*>(val); - return obj->fromJson(json); - } if(type.startsWith("QString")) { return new QString(); + } + auto val = static_cast<{{prefix}}Object*>(create(type)); + if(val != nullptr) { + return val->fromJson(json); } return nullptr; } diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache index e82bc31073aa..87d3a828d0c7 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache @@ -2,7 +2,7 @@ #ifndef _{{prefix}}_OBJECT_H_ #define _{{prefix}}_OBJECT_H_ -#include +#include {{#cppNamespaceDeclarations}} namespace {{this}} { @@ -10,15 +10,15 @@ namespace {{this}} { class {{prefix}}Object { public: - virtual QJsonObject* asJsonObject() { - return new QJsonObject(); + virtual QJsonObject asJsonObject() { + return QJsonObject(); } virtual ~{{prefix}}Object() {} - virtual {{prefix}}Object* fromJson(QString &jsonString) { + virtual {{prefix}}Object* fromJson(QString jsonString) { Q_UNUSED(jsonString); return new {{prefix}}Object(); } - virtual void fromJsonObject(QJsonObject &json) { + virtual void fromJsonObject(QJsonObject json) { Q_UNUSED(json); } virtual QString asJson() { diff --git a/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp b/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp index 66e021fd4025..2b9d23315077 100644 --- a/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGApiResponse::SWGApiResponse(QString* json) { +SWGApiResponse::SWGApiResponse(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGApiResponse::SWGApiResponse() { @@ -57,7 +57,7 @@ SWGApiResponse::cleanup() { } SWGApiResponse* -SWGApiResponse::fromJson(QString &json) { +SWGApiResponse::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -66,7 +66,7 @@ SWGApiResponse::fromJson(QString &json) { } void -SWGApiResponse::fromJsonObject(QJsonObject &pJson) { +SWGApiResponse::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&code, pJson["code"], "qint32", ""); ::Swagger::setValue(&type, pJson["type"], "QString", "QString"); @@ -78,18 +78,17 @@ SWGApiResponse::fromJsonObject(QJsonObject &pJson) { QString SWGApiResponse::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGApiResponse::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_code_isSet){ - obj->insert("code", QJsonValue(code)); + obj.insert("code", QJsonValue(code)); } if(type != nullptr && *type != QString("")){ toJsonValue(QString("type"), type, obj, QString("QString")); diff --git a/samples/client/petstore/qt5cpp/client/SWGApiResponse.h b/samples/client/petstore/qt5cpp/client/SWGApiResponse.h index 423e29adf326..dc94e40a7363 100644 --- a/samples/client/petstore/qt5cpp/client/SWGApiResponse.h +++ b/samples/client/petstore/qt5cpp/client/SWGApiResponse.h @@ -31,15 +31,15 @@ namespace Swagger { class SWGApiResponse: public SWGObject { public: SWGApiResponse(); - SWGApiResponse(QString* json); - virtual ~SWGApiResponse(); + SWGApiResponse(QString json); + ~SWGApiResponse(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGApiResponse* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGApiResponse* fromJson(QString jsonString); qint32 getCode(); void setCode(qint32 code); diff --git a/samples/client/petstore/qt5cpp/client/SWGCategory.cpp b/samples/client/petstore/qt5cpp/client/SWGCategory.cpp index d5f05e218937..b399e0343f54 100644 --- a/samples/client/petstore/qt5cpp/client/SWGCategory.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGCategory.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGCategory::SWGCategory(QString* json) { +SWGCategory::SWGCategory(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGCategory::SWGCategory() { @@ -52,7 +52,7 @@ SWGCategory::cleanup() { } SWGCategory* -SWGCategory::fromJson(QString &json) { +SWGCategory::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -61,7 +61,7 @@ SWGCategory::fromJson(QString &json) { } void -SWGCategory::fromJsonObject(QJsonObject &pJson) { +SWGCategory::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); @@ -71,18 +71,17 @@ SWGCategory::fromJsonObject(QJsonObject &pJson) { QString SWGCategory::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGCategory::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_id_isSet){ - obj->insert("id", QJsonValue(id)); + obj.insert("id", QJsonValue(id)); } if(name != nullptr && *name != QString("")){ toJsonValue(QString("name"), name, obj, QString("QString")); diff --git a/samples/client/petstore/qt5cpp/client/SWGCategory.h b/samples/client/petstore/qt5cpp/client/SWGCategory.h index 28486418b8e5..8ccae6b87ce7 100644 --- a/samples/client/petstore/qt5cpp/client/SWGCategory.h +++ b/samples/client/petstore/qt5cpp/client/SWGCategory.h @@ -31,15 +31,15 @@ namespace Swagger { class SWGCategory: public SWGObject { public: SWGCategory(); - SWGCategory(QString* json); - virtual ~SWGCategory(); + SWGCategory(QString json); + ~SWGCategory(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGCategory* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGCategory* fromJson(QString jsonString); qint64 getId(); void setId(qint64 id); diff --git a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp index cf8aa7eaf40e..3da7251ff14c 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp @@ -41,7 +41,7 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } else if(QStringLiteral("float").compare(type) == 0) { float *val = static_cast(value); - *val = obj.toDouble(); + *val = static_cast(obj.toDouble()); } else if(QStringLiteral("double").compare(type) == 0) { double *val = static_cast(value); @@ -51,20 +51,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { QString **val = static_cast(value); if(val != nullptr) { if(!obj.isNull()) { - // create a new value and return - if(*val != nullptr) delete *val; - *val = new QString(obj.toString()); + (*val)->clear(); + (*val)->append(obj.toString()); return; } else { - // set target to nullptr - if(*val != nullptr) delete *val; - *val = nullptr; + (*val)->clear(); } } - else { - qDebug() << "Can't set value because the target pointer is nullptr"; - } } else if (QStringLiteral("QDateTime").compare(type) == 0) { QDateTime **val = static_cast(value); @@ -380,67 +374,66 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } void -toJsonValue(QString name, void* value, QJsonObject* output, QString type) { +toJsonValue(QString name, void* value, QJsonObject& output, QString type) { if(value == nullptr) { return; } if(type.startsWith("SWG")) { SWGObject *SWGobject = reinterpret_cast(value); if(SWGobject != nullptr) { - QJsonObject* o = (*SWGobject).asJsonObject(); - if(name != nullptr) { - output->insert(name, *o); - if(o != nullptr) delete o; + QJsonObject o = SWGobject->asJsonObject(); + if(!name.isNull()) { + output.insert(name, o); } else { - output->empty(); - for(QString key : o->keys()) { - output->insert(key, o->value(key)); + output.empty(); + for(QString key : o.keys()) { + output.insert(key, o.value(key)); } } } } else if(QStringLiteral("QString").compare(type) == 0) { QString* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint32").compare(type) == 0) { qint32* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint64").compare(type) == 0) { qint64* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("bool").compare(type) == 0) { bool* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("float").compare(type) == 0) { float* str = static_cast(value); - output->insert(name, QJsonValue((double)*str)); + output.insert(name, QJsonValue((double)*str)); } else if(QStringLiteral("double").compare(type) == 0) { double* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output.insert(name, QJsonValue(*str)); } else if(QStringLiteral("QDate").compare(type) == 0) { QDate* date = static_cast(value); - output->insert(name, QJsonValue(date->toString(Qt::ISODate))); + output.insert(name, QJsonValue(date->toString(Qt::ISODate))); } else if(QStringLiteral("QDateTime").compare(type) == 0) { QDateTime* datetime = static_cast(value); - output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); + output.insert(name, QJsonValue(datetime->toString(Qt::ISODate))); } else if(QStringLiteral("QByteArray").compare(type) == 0) { QByteArray* byteArray = static_cast(value); - output->insert(name, QJsonValue(QString(byteArray->toBase64()))); + output.insert(name, QJsonValue(QString(byteArray->toBase64()))); } } void -toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType) { - if((value == nullptr) || (output == nullptr)) { +toJsonArray(QList* value, QJsonObject& output, QString innerName, QString innerType) { + if(value == nullptr) { return; } QJsonArray outputarray; @@ -448,7 +441,7 @@ toJsonArray(QList* value, QJsonObject* output, QString innerName, QString for(void* obj : *value) { SWGObject *SWGobject = reinterpret_cast(obj); if(SWGobject != nullptr) { - outputarray.append(*(SWGobject->asJsonObject())); + outputarray.append(SWGobject->asJsonObject()); } } } @@ -491,81 +484,81 @@ toJsonArray(QList* value, QJsonObject* output, QString innerName, QString for(double obj : *(reinterpret_cast*>(value))) outputarray.append(QJsonValue(obj)); } - output->insert(innerName, outputarray); + output.insert(innerName, outputarray); } void -toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType) { - if((value == nullptr) || (output == nullptr)) { +toJsonMap(QMap* value, QJsonObject& output, QString innerName, QString innerType) { + if(value == nullptr) { return; } QJsonObject mapobj; if(innerType.startsWith("SWG")){ auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::Swagger::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, items->value(itemkey),mapobj, innerType); } } else if(QStringLiteral("QString").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::Swagger::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QDate").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::Swagger::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QDateTime").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::Swagger::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("QByteArray").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { - ::Swagger::toJsonValue(itemkey, items->value(itemkey), &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, items->value(itemkey), mapobj, innerType); } } else if(QStringLiteral("qint32").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("qint64").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("bool").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("float").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys()) { auto val = items->value(itemkey); - ::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType); } } else if(QStringLiteral("double").compare(innerType) == 0) { auto items = reinterpret_cast< QMap *>(value); for(auto itemkey: items->keys() ) { auto val = items->value(itemkey); - ::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); + ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType); } } - output->insert(innerName, mapobj); + output.insert(innerName, mapobj); } QString diff --git a/samples/client/petstore/qt5cpp/client/SWGHelpers.h b/samples/client/petstore/qt5cpp/client/SWGHelpers.h index 337d2150d3d2..bbb43e43d8a6 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.h +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.h @@ -20,9 +20,9 @@ namespace Swagger { void setValue(void* value, QJsonValue obj, QString type, QString complexType); - void toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType); - void toJsonValue(QString name, void* value, QJsonObject* output, QString type); - void toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType); + void toJsonArray(QList* value, QJsonObject& output, QString innerName, QString innerType); + void toJsonValue(QString name, void* value, QJsonObject& output, QString type); + void toJsonMap(QMap* value, QJsonObject& output, QString innerName, QString innerType); bool isCompatibleJsonValue(QString type); QString stringValue(QString* value); QString stringValue(qint32 value); diff --git a/samples/client/petstore/qt5cpp/client/SWGHttpRequest.cpp b/samples/client/petstore/qt5cpp/client/SWGHttpRequest.cpp index bf2fe17f6b08..e3dcc5dfab74 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHttpRequest.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGHttpRequest.cpp @@ -56,7 +56,7 @@ SWGHttpRequestWorker::SWGHttpRequestWorker(QObject *parent) qsrand(QDateTime::currentDateTime().toTime_t()); manager = new QNetworkAccessManager(this); - connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_manager_finished(QNetworkReply*))); + connect(manager, &QNetworkAccessManager::finished, this, &SWGHttpRequestWorker::on_manager_finished); } SWGHttpRequestWorker::~SWGHttpRequestWorker() { diff --git a/samples/client/petstore/qt5cpp/client/SWGModelFactory.h b/samples/client/petstore/qt5cpp/client/SWGModelFactory.h index 625d2e75aae6..dcea2ef855ba 100644 --- a/samples/client/petstore/qt5cpp/client/SWGModelFactory.h +++ b/samples/client/petstore/qt5cpp/client/SWGModelFactory.h @@ -47,13 +47,12 @@ namespace Swagger { } inline void* create(QString json, QString type) { - void* val = create(type); - if(val != nullptr) { - SWGObject* obj = static_cast(val); - return obj->fromJson(json); - } if(type.startsWith("QString")) { return new QString(); + } + auto val = static_cast(create(type)); + if(val != nullptr) { + return val->fromJson(json); } return nullptr; } diff --git a/samples/client/petstore/qt5cpp/client/SWGObject.h b/samples/client/petstore/qt5cpp/client/SWGObject.h index 26e6b905df96..7f953ae59ecb 100644 --- a/samples/client/petstore/qt5cpp/client/SWGObject.h +++ b/samples/client/petstore/qt5cpp/client/SWGObject.h @@ -19,15 +19,15 @@ namespace Swagger { class SWGObject { public: - virtual QJsonObject* asJsonObject() { - return new QJsonObject(); + virtual QJsonObject asJsonObject() { + return QJsonObject(); } virtual ~SWGObject() {} - virtual SWGObject* fromJson(QString &jsonString) { + virtual SWGObject* fromJson(QString jsonString) { Q_UNUSED(jsonString); return new SWGObject(); } - virtual void fromJsonObject(QJsonObject &json) { + virtual void fromJsonObject(QJsonObject json) { Q_UNUSED(json); } virtual QString asJson() { diff --git a/samples/client/petstore/qt5cpp/client/SWGOrder.cpp b/samples/client/petstore/qt5cpp/client/SWGOrder.cpp index 5b997fffc1b1..59184cbc12b2 100644 --- a/samples/client/petstore/qt5cpp/client/SWGOrder.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGOrder.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGOrder::SWGOrder(QString* json) { +SWGOrder::SWGOrder(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGOrder::SWGOrder() { @@ -66,7 +66,7 @@ SWGOrder::cleanup() { } SWGOrder* -SWGOrder::fromJson(QString &json) { +SWGOrder::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -75,7 +75,7 @@ SWGOrder::fromJson(QString &json) { } void -SWGOrder::fromJsonObject(QJsonObject &pJson) { +SWGOrder::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&pet_id, pJson["petId"], "qint64", ""); @@ -93,24 +93,23 @@ SWGOrder::fromJsonObject(QJsonObject &pJson) { QString SWGOrder::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGOrder::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_id_isSet){ - obj->insert("id", QJsonValue(id)); + obj.insert("id", QJsonValue(id)); } if(m_pet_id_isSet){ - obj->insert("petId", QJsonValue(pet_id)); + obj.insert("petId", QJsonValue(pet_id)); } if(m_quantity_isSet){ - obj->insert("quantity", QJsonValue(quantity)); + obj.insert("quantity", QJsonValue(quantity)); } if(ship_date != nullptr) { toJsonValue(QString("shipDate"), ship_date, obj, QString("QDateTime")); @@ -119,7 +118,7 @@ SWGOrder::asJsonObject() { toJsonValue(QString("status"), status, obj, QString("QString")); } if(m_complete_isSet){ - obj->insert("complete", QJsonValue(complete)); + obj.insert("complete", QJsonValue(complete)); } return obj; diff --git a/samples/client/petstore/qt5cpp/client/SWGOrder.h b/samples/client/petstore/qt5cpp/client/SWGOrder.h index 43dc7cfc68c3..90d9c850bf3d 100644 --- a/samples/client/petstore/qt5cpp/client/SWGOrder.h +++ b/samples/client/petstore/qt5cpp/client/SWGOrder.h @@ -32,15 +32,15 @@ namespace Swagger { class SWGOrder: public SWGObject { public: SWGOrder(); - SWGOrder(QString* json); - virtual ~SWGOrder(); + SWGOrder(QString json); + ~SWGOrder(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGOrder* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGOrder* fromJson(QString jsonString); qint64 getId(); void setId(qint64 id); diff --git a/samples/client/petstore/qt5cpp/client/SWGPet.cpp b/samples/client/petstore/qt5cpp/client/SWGPet.cpp index 70dc8ebf891f..e98abbd431cb 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPet.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGPet.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGPet::SWGPet(QString* json) { +SWGPet::SWGPet(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGPet::SWGPet() { @@ -80,7 +80,7 @@ SWGPet::cleanup() { } SWGPet* -SWGPet::fromJson(QString &json) { +SWGPet::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -89,7 +89,7 @@ SWGPet::fromJson(QString &json) { } void -SWGPet::fromJsonObject(QJsonObject &pJson) { +SWGPet::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&category, pJson["category"], "SWGCategory", "SWGCategory"); @@ -107,18 +107,17 @@ SWGPet::fromJsonObject(QJsonObject &pJson) { QString SWGPet::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGPet::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_id_isSet){ - obj->insert("id", QJsonValue(id)); + obj.insert("id", QJsonValue(id)); } if((category != nullptr) && (category->isSet())){ toJsonValue(QString("category"), category, obj, QString("SWGCategory")); diff --git a/samples/client/petstore/qt5cpp/client/SWGPet.h b/samples/client/petstore/qt5cpp/client/SWGPet.h index e356f1360211..428b260c4020 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPet.h +++ b/samples/client/petstore/qt5cpp/client/SWGPet.h @@ -34,15 +34,15 @@ namespace Swagger { class SWGPet: public SWGObject { public: SWGPet(); - SWGPet(QString* json); - virtual ~SWGPet(); + SWGPet(QString json); + ~SWGPet(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGPet* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGPet* fromJson(QString jsonString); qint64 getId(); void setId(qint64 id); diff --git a/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp b/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp index 2a747610340a..3b38f5710a25 100644 --- a/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp @@ -127,7 +127,7 @@ SWGStoreApi::getInventoryCallback(SWGHttpRequestWorker * worker) { foreach(QString key, obj.keys()) { qint32* val; - setValue(&val, obj[key], "qint32", ""); + setValue(&val, obj[key], "qint32", QString()); output->insert(key, *val); } worker->deleteLater(); diff --git a/samples/client/petstore/qt5cpp/client/SWGTag.cpp b/samples/client/petstore/qt5cpp/client/SWGTag.cpp index 82ee1d57fe64..844a1a18e205 100644 --- a/samples/client/petstore/qt5cpp/client/SWGTag.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGTag.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGTag::SWGTag(QString* json) { +SWGTag::SWGTag(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGTag::SWGTag() { @@ -52,7 +52,7 @@ SWGTag::cleanup() { } SWGTag* -SWGTag::fromJson(QString &json) { +SWGTag::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -61,7 +61,7 @@ SWGTag::fromJson(QString &json) { } void -SWGTag::fromJsonObject(QJsonObject &pJson) { +SWGTag::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); @@ -71,18 +71,17 @@ SWGTag::fromJsonObject(QJsonObject &pJson) { QString SWGTag::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGTag::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_id_isSet){ - obj->insert("id", QJsonValue(id)); + obj.insert("id", QJsonValue(id)); } if(name != nullptr && *name != QString("")){ toJsonValue(QString("name"), name, obj, QString("QString")); diff --git a/samples/client/petstore/qt5cpp/client/SWGTag.h b/samples/client/petstore/qt5cpp/client/SWGTag.h index fd2fd6436e5f..dd7b41015631 100644 --- a/samples/client/petstore/qt5cpp/client/SWGTag.h +++ b/samples/client/petstore/qt5cpp/client/SWGTag.h @@ -31,15 +31,15 @@ namespace Swagger { class SWGTag: public SWGObject { public: SWGTag(); - SWGTag(QString* json); - virtual ~SWGTag(); + SWGTag(QString json); + ~SWGTag(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGTag* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGTag* fromJson(QString jsonString); qint64 getId(); void setId(qint64 id); diff --git a/samples/client/petstore/qt5cpp/client/SWGUser.cpp b/samples/client/petstore/qt5cpp/client/SWGUser.cpp index 1dd64b356a0e..3690ee45c9f2 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUser.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGUser.cpp @@ -22,9 +22,9 @@ namespace Swagger { -SWGUser::SWGUser(QString* json) { +SWGUser::SWGUser(QString json) { init(); - this->fromJson(*json); + this->fromJson(json); } SWGUser::SWGUser() { @@ -80,7 +80,7 @@ SWGUser::cleanup() { } SWGUser* -SWGUser::fromJson(QString &json) { +SWGUser::fromJson(QString json) { QByteArray array (json.toStdString().c_str()); QJsonDocument doc = QJsonDocument::fromJson(array); QJsonObject jsonObject = doc.object(); @@ -89,7 +89,7 @@ SWGUser::fromJson(QString &json) { } void -SWGUser::fromJsonObject(QJsonObject &pJson) { +SWGUser::fromJsonObject(QJsonObject pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&username, pJson["username"], "QString", "QString"); @@ -111,18 +111,17 @@ SWGUser::fromJsonObject(QJsonObject &pJson) { QString SWGUser::asJson () { - QJsonObject* obj = this->asJsonObject(); - - QJsonDocument doc(*obj); + QJsonObject obj = this->asJsonObject(); + QJsonDocument doc(obj); QByteArray bytes = doc.toJson(); return QString(bytes); } -QJsonObject* +QJsonObject SWGUser::asJsonObject() { - QJsonObject* obj = new QJsonObject(); + QJsonObject obj; if(m_id_isSet){ - obj->insert("id", QJsonValue(id)); + obj.insert("id", QJsonValue(id)); } if(username != nullptr && *username != QString("")){ toJsonValue(QString("username"), username, obj, QString("QString")); @@ -143,7 +142,7 @@ SWGUser::asJsonObject() { toJsonValue(QString("phone"), phone, obj, QString("QString")); } if(m_user_status_isSet){ - obj->insert("userStatus", QJsonValue(user_status)); + obj.insert("userStatus", QJsonValue(user_status)); } return obj; diff --git a/samples/client/petstore/qt5cpp/client/SWGUser.h b/samples/client/petstore/qt5cpp/client/SWGUser.h index 02ddd3af61b1..5e3e7e54a4b1 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUser.h +++ b/samples/client/petstore/qt5cpp/client/SWGUser.h @@ -31,15 +31,15 @@ namespace Swagger { class SWGUser: public SWGObject { public: SWGUser(); - SWGUser(QString* json); - virtual ~SWGUser(); + SWGUser(QString json); + ~SWGUser(); void init(); void cleanup(); QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); - SWGUser* fromJson(QString &jsonString); + QJsonObject asJsonObject(); + void fromJsonObject(QJsonObject json); + SWGUser* fromJson(QString jsonString); qint64 getId(); void setId(qint64 id); diff --git a/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp b/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp index 6af3d3116238..328e1e82d3a0 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp @@ -91,10 +91,10 @@ SWGUserApi::createUsersWithArrayInput(QList*& body) { SWGHttpRequestInput input(fullPath, "POST"); - auto body_jobj = new QJsonObject(); + QJsonObject body_jobj; toJsonArray((QList*)body, body_jobj, QString("body"), QString("SWGUser*")); - QJsonDocument doc(*body_jobj); + QJsonDocument doc(body_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -147,10 +147,10 @@ SWGUserApi::createUsersWithListInput(QList*& body) { SWGHttpRequestInput input(fullPath, "POST"); - auto body_jobj = new QJsonObject(); + QJsonObject body_jobj; toJsonArray((QList*)body, body_jobj, QString("body"), QString("SWGUser*")); - QJsonDocument doc(*body_jobj); + QJsonDocument doc(body_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes);