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
This commit is contained in:
etherealjoy 2018-03-07 13:54:40 +01:00 committed by William Cheng
parent d5f3619199
commit 12f3661d6f
27 changed files with 219 additions and 240 deletions

View File

@ -47,7 +47,7 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
manager = new QNetworkAccessManager(this); 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() { {{prefix}}HttpRequestWorker::~{{prefix}}HttpRequestWorker() {

View File

@ -98,10 +98,10 @@ void
{{#bodyParams}} {{#bodyParams}}
{{#isContainer}} {{#isContainer}}
auto {{paramName}}_jobj = new QJsonObject(); QJsonObject {{paramName}}_jobj;
toJsonArray((QList<void*>*){{paramName}}, {{paramName}}_jobj, QString("body"), QString("{{prefix}}User*")); toJsonArray((QList<void*>*){{paramName}}, {{paramName}}_jobj, QString("body"), QString("{{prefix}}User*"));
QJsonDocument doc(*{{paramName}}_jobj); QJsonDocument doc({{paramName}}_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -175,7 +175,7 @@ void
foreach(QString key, obj.keys()) { foreach(QString key, obj.keys()) {
qint32* val; qint32* val;
setValue(&val, obj[key], "{{returnBaseType}}", ""); setValue(&val, obj[key], "{{returnBaseType}}", QString());
output->insert(key, *val); output->insert(key, *val);
} }
{{/isMapContainer}} {{/isMapContainer}}

View File

@ -32,7 +32,7 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
else if(QStringLiteral("float").compare(type) == 0) { else if(QStringLiteral("float").compare(type) == 0) {
float *val = static_cast<float*>(value); float *val = static_cast<float*>(value);
*val = obj.toDouble(); *val = static_cast<float>(obj.toDouble());
} }
else if(QStringLiteral("double").compare(type) == 0) { else if(QStringLiteral("double").compare(type) == 0) {
double *val = static_cast<double*>(value); double *val = static_cast<double*>(value);
@ -42,20 +42,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
QString **val = static_cast<QString**>(value); QString **val = static_cast<QString**>(value);
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return (*val)->clear();
if(*val != nullptr) delete *val; (*val)->append(obj.toString());
*val = new QString(obj.toString());
return; return;
} }
else { else {
// set target to nullptr (*val)->clear();
if(*val != nullptr) delete *val;
*val = nullptr;
} }
} }
else {
qDebug() << "Can't set value because the target pointer is nullptr";
}
} }
else if (QStringLiteral("QDateTime").compare(type) == 0) { else if (QStringLiteral("QDateTime").compare(type) == 0) {
QDateTime **val = static_cast<QDateTime**>(value); QDateTime **val = static_cast<QDateTime**>(value);
@ -371,67 +365,66 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
void void
toJsonValue(QString name, void* value, QJsonObject* output, QString type) { toJsonValue(QString name, void* value, QJsonObject& output, QString type) {
if(value == nullptr) { if(value == nullptr) {
return; return;
} }
if(type.startsWith("{{prefix}}")) { if(type.startsWith("{{prefix}}")) {
{{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(value); {{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(value);
if({{prefix}}object != nullptr) { if({{prefix}}object != nullptr) {
QJsonObject* o = (*{{prefix}}object).asJsonObject(); QJsonObject o = {{prefix}}object->asJsonObject();
if(name != nullptr) { if(!name.isNull()) {
output->insert(name, *o); output.insert(name, o);
if(o != nullptr) delete o;
} }
else { else {
output->empty(); output.empty();
for(QString key : o->keys()) { for(QString key : o.keys()) {
output->insert(key, o->value(key)); output.insert(key, o.value(key));
} }
} }
} }
} }
else if(QStringLiteral("QString").compare(type) == 0) { else if(QStringLiteral("QString").compare(type) == 0) {
QString* str = static_cast<QString*>(value); QString* str = static_cast<QString*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("qint32").compare(type) == 0) { else if(QStringLiteral("qint32").compare(type) == 0) {
qint32* str = static_cast<qint32*>(value); qint32* str = static_cast<qint32*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("qint64").compare(type) == 0) { else if(QStringLiteral("qint64").compare(type) == 0) {
qint64* str = static_cast<qint64*>(value); qint64* str = static_cast<qint64*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("bool").compare(type) == 0) { else if(QStringLiteral("bool").compare(type) == 0) {
bool* str = static_cast<bool*>(value); bool* str = static_cast<bool*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("float").compare(type) == 0) { else if(QStringLiteral("float").compare(type) == 0) {
float* str = static_cast<float*>(value); float* str = static_cast<float*>(value);
output->insert(name, QJsonValue((double)*str)); output.insert(name, QJsonValue((double)*str));
} }
else if(QStringLiteral("double").compare(type) == 0) { else if(QStringLiteral("double").compare(type) == 0) {
double* str = static_cast<double*>(value); double* str = static_cast<double*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("QDate").compare(type) == 0) { else if(QStringLiteral("QDate").compare(type) == 0) {
QDate* date = static_cast<QDate*>(value); QDate* date = static_cast<QDate*>(value);
output->insert(name, QJsonValue(date->toString(Qt::ISODate))); output.insert(name, QJsonValue(date->toString(Qt::ISODate)));
} }
else if(QStringLiteral("QDateTime").compare(type) == 0) { else if(QStringLiteral("QDateTime").compare(type) == 0) {
QDateTime* datetime = static_cast<QDateTime*>(value); QDateTime* datetime = static_cast<QDateTime*>(value);
output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); output.insert(name, QJsonValue(datetime->toString(Qt::ISODate)));
} }
else if(QStringLiteral("QByteArray").compare(type) == 0) { else if(QStringLiteral("QByteArray").compare(type) == 0) {
QByteArray* byteArray = static_cast<QByteArray*>(value); QByteArray* byteArray = static_cast<QByteArray*>(value);
output->insert(name, QJsonValue(QString(byteArray->toBase64()))); output.insert(name, QJsonValue(QString(byteArray->toBase64())));
} }
} }
void void
toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType) { toJsonArray(QList<void*>* value, QJsonObject& output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) { if(value == nullptr) {
return; return;
} }
QJsonArray outputarray; QJsonArray outputarray;
@ -439,7 +432,7 @@ toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString
for(void* obj : *value) { for(void* obj : *value) {
{{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(obj); {{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(obj);
if({{prefix}}object != nullptr) { if({{prefix}}object != nullptr) {
outputarray.append(*({{prefix}}object->asJsonObject())); outputarray.append({{prefix}}object->asJsonObject());
} }
} }
} }
@ -482,81 +475,81 @@ toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString
for(double obj : *(reinterpret_cast<QList<double>*>(value))) for(double obj : *(reinterpret_cast<QList<double>*>(value)))
outputarray.append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
output->insert(innerName, outputarray); output.insert(innerName, outputarray);
} }
void void
toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType) { toJsonMap(QMap<QString, void*>* value, QJsonObject& output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) { if(value == nullptr) {
return; return;
} }
QJsonObject mapobj; QJsonObject mapobj;
if(innerType.startsWith("{{prefix}}")){ if(innerType.startsWith("{{prefix}}")){
auto items = reinterpret_cast< QMap<QString, {{prefix}}Object*> *>(value); auto items = reinterpret_cast< QMap<QString, {{prefix}}Object*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QString").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QString*> *>(value); auto items = reinterpret_cast< QMap<QString, QString*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QDate").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QDate*> *>(value); auto items = reinterpret_cast< QMap<QString, QDate*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QDateTime").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QDateTime*> *>(value); auto items = reinterpret_cast< QMap<QString, QDateTime*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QByteArray").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QByteArray*> *>(value); auto items = reinterpret_cast< QMap<QString, QByteArray*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("qint32").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, qint32> *>(value); auto items = reinterpret_cast< QMap<QString, qint32> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("qint64").compare(innerType) == 0) { else if(QStringLiteral("qint64").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, qint64> *>(value); auto items = reinterpret_cast< QMap<QString, qint64> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("bool").compare(innerType) == 0) { else if(QStringLiteral("bool").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, bool> *>(value); auto items = reinterpret_cast< QMap<QString, bool> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("float").compare(innerType) == 0) { else if(QStringLiteral("float").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, float> *>(value); auto items = reinterpret_cast< QMap<QString, float> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType); ::{{cppNamespace}}::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("double").compare(innerType) == 0) { else if(QStringLiteral("double").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, double> *>(value); auto items = reinterpret_cast< QMap<QString, double> *>(value);
for(auto itemkey: items->keys() ) { for(auto itemkey: items->keys() ) {
auto val = items->value(itemkey); 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 QString
@ -582,4 +575,4 @@ stringValue(bool value) {
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
} }
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}

View File

@ -2,6 +2,7 @@
#ifndef {{prefix}}_HELPERS_H #ifndef {{prefix}}_HELPERS_H
#define {{prefix}}_HELPERS_H #define {{prefix}}_HELPERS_H
#include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
#include <QList> #include <QList>
#include <QMap> #include <QMap>
@ -11,9 +12,9 @@ namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}
void setValue(void* value, QJsonValue obj, QString type, QString complexType); void setValue(void* value, QJsonValue obj, QString type, QString complexType);
void toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType); void toJsonArray(QList<void*>* value, QJsonObject& output, QString innerName, QString innerType);
void toJsonValue(QString name, void* value, QJsonObject* output, QString type); void toJsonValue(QString name, void* value, QJsonObject& output, QString type);
void toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType); void toJsonMap(QMap<QString, void*>* value, QJsonObject& output, QString innerName, QString innerType);
bool isCompatibleJsonValue(QString type); bool isCompatibleJsonValue(QString type);
QString stringValue(QString* value); QString stringValue(QString* value);
QString stringValue(qint32 value); QString stringValue(qint32 value);

View File

@ -13,9 +13,9 @@
namespace {{this}} { namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}
{{classname}}::{{classname}}(QString* json) { {{classname}}::{{classname}}(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
{{classname}}::{{classname}}() { {{classname}}::{{classname}}() {
@ -52,7 +52,7 @@ void
} }
{{classname}}* {{classname}}*
{{classname}}::fromJson(QString &json) { {{classname}}::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -61,7 +61,7 @@ void
} }
void void
{{classname}}::fromJsonObject(QJsonObject &pJson) { {{classname}}::fromJsonObject(QJsonObject pJson) {
{{#vars}} {{#vars}}
{{^isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/isContainer}} {{^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}} {{#isContainer}}{{^items.isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}");{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
@ -94,16 +94,15 @@ void
QString QString
{{classname}}::asJson () {{classname}}::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
{{classname}}::asJsonObject() { {{classname}}::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}
{{#complexType}} {{#complexType}}
@ -129,7 +128,7 @@ QJsonObject*
{{^isDate}} {{^isDate}}
{{^isByteArray}} {{^isByteArray}}
if(m_{{name}}_isSet){ if(m_{{name}}_isSet){
obj->insert("{{baseName}}", QJsonValue({{name}})); obj.insert("{{baseName}}", QJsonValue({{name}}));
} }
{{/isByteArray}} {{/isByteArray}}
{{/isDate}} {{/isDate}}
@ -142,7 +141,7 @@ QJsonObject*
{{/isDate}} {{/isDate}}
{{#isByteArray}} {{#isByteArray}}
if({{name}} != nullptr) { if({{name}} != nullptr) {
obj->insert("{{name}}", QJsonValue(*{{name}})); obj.insert("{{name}}", QJsonValue(*{{name}}));
} }
{{/isByteArray}} {{/isByteArray}}
{{#isDateTime}} {{#isDateTime}}
@ -162,14 +161,14 @@ QJsonObject*
for(auto items : *{{name}}){ for(auto items : *{{name}}){
QJsonObject jobj; QJsonObject jobj;
{{#items.isListContainer}} {{#items.isListContainer}}
toJsonArray((QList<void*>*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}"); toJsonArray((QList<void*>*)items, jobj, "{{baseName}}", "{{items.items.baseType}}");
{{/items.isListContainer}} {{/items.isListContainer}}
{{#items.isMapContainer}} {{#items.isMapContainer}}
toJsonMap((QMap<QString, void*>*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}"); toJsonMap((QMap<QString, void*>*)items, jobj, "{{baseName}}", "{{items.items.baseType}}");
{{/items.isMapContainer}} {{/items.isMapContainer}}
jarray.append(jobj.value("{{baseName}}")); jarray.append(jobj.value("{{baseName}}"));
} }
obj->insert("{{baseName}}", jarray); obj.insert("{{baseName}}", jarray);
{{/items.isContainer}} {{/items.isContainer}}
} }
{{/isListContainer}} {{/isListContainer}}
@ -180,14 +179,14 @@ QJsonObject*
for(auto itemkey : {{name}}->keys()){ for(auto itemkey : {{name}}->keys()){
QJsonObject jobj; QJsonObject jobj;
{{#items.isListContainer}} {{#items.isListContainer}}
toJsonArray((QList<void*>*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}"); toJsonArray((QList<void*>*){{name}}->value(itemkey), jobj, itemkey, "{{items.items.baseType}}");
{{/items.isListContainer}} {{/items.isListContainer}}
{{#items.isMapContainer}} {{#items.isMapContainer}}
toJsonMap((QMap<QString, void*>*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}"); toJsonMap((QMap<QString, void*>*){{name}}->value(itemkey), jobj, itemkey, "{{items.items.baseType}}");
{{/items.isMapContainer}} {{/items.isMapContainer}}
mapobj.insert(itemkey, jobj); mapobj.insert(itemkey, jobj);
} }
obj->insert("{{baseName}}", mapobj);{{/items.isContainer}} obj.insert("{{baseName}}", mapobj);{{/items.isContainer}}
} }
{{/isMapContainer}} {{/isMapContainer}}
{{/isContainer}} {{/isContainer}}

View File

@ -25,15 +25,15 @@ namespace {{this}} {
class {{classname}}: public {{prefix}}Object { class {{classname}}: public {{prefix}}Object {
public: public:
{{classname}}(); {{classname}}();
{{classname}}(QString* json); {{classname}}(QString json);
virtual ~{{classname}}(); ~{{classname}}();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
{{classname}}* fromJson(QString &jsonString); {{classname}}* fromJson(QString jsonString);
{{#vars}} {{#vars}}
{{{datatype}}} {{getter}}(); {{{datatype}}} {{getter}}();

View File

@ -2,6 +2,7 @@
#ifndef ModelFactory_H_ #ifndef ModelFactory_H_
#define ModelFactory_H_ #define ModelFactory_H_
#include "{{prefix}}Object.h"
{{#models}}{{#model}} {{#models}}{{#model}}
#include "{{classname}}.h"{{/model}}{{/models}} #include "{{classname}}.h"{{/model}}{{/models}}
@ -18,13 +19,12 @@ namespace {{this}} {
} }
inline void* create(QString json, QString type) { 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")) { if(type.startsWith("QString")) {
return new QString(); return new QString();
}
auto val = static_cast<{{prefix}}Object*>(create(type));
if(val != nullptr) {
return val->fromJson(json);
} }
return nullptr; return nullptr;
} }

View File

@ -2,7 +2,7 @@
#ifndef _{{prefix}}_OBJECT_H_ #ifndef _{{prefix}}_OBJECT_H_
#define _{{prefix}}_OBJECT_H_ #define _{{prefix}}_OBJECT_H_
#include <QJsonValue> #include <QJsonObject>
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
namespace {{this}} { namespace {{this}} {
@ -10,15 +10,15 @@ namespace {{this}} {
class {{prefix}}Object { class {{prefix}}Object {
public: public:
virtual QJsonObject* asJsonObject() { virtual QJsonObject asJsonObject() {
return new QJsonObject(); return QJsonObject();
} }
virtual ~{{prefix}}Object() {} virtual ~{{prefix}}Object() {}
virtual {{prefix}}Object* fromJson(QString &jsonString) { virtual {{prefix}}Object* fromJson(QString jsonString) {
Q_UNUSED(jsonString); Q_UNUSED(jsonString);
return new {{prefix}}Object(); return new {{prefix}}Object();
} }
virtual void fromJsonObject(QJsonObject &json) { virtual void fromJsonObject(QJsonObject json) {
Q_UNUSED(json); Q_UNUSED(json);
} }
virtual QString asJson() { virtual QString asJson() {

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGApiResponse::SWGApiResponse(QString* json) { SWGApiResponse::SWGApiResponse(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGApiResponse::SWGApiResponse() { SWGApiResponse::SWGApiResponse() {
@ -57,7 +57,7 @@ SWGApiResponse::cleanup() {
} }
SWGApiResponse* SWGApiResponse*
SWGApiResponse::fromJson(QString &json) { SWGApiResponse::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -66,7 +66,7 @@ SWGApiResponse::fromJson(QString &json) {
} }
void void
SWGApiResponse::fromJsonObject(QJsonObject &pJson) { SWGApiResponse::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&code, pJson["code"], "qint32", ""); ::Swagger::setValue(&code, pJson["code"], "qint32", "");
::Swagger::setValue(&type, pJson["type"], "QString", "QString"); ::Swagger::setValue(&type, pJson["type"], "QString", "QString");
@ -78,18 +78,17 @@ SWGApiResponse::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGApiResponse::asJson () SWGApiResponse::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGApiResponse::asJsonObject() { SWGApiResponse::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_code_isSet){ if(m_code_isSet){
obj->insert("code", QJsonValue(code)); obj.insert("code", QJsonValue(code));
} }
if(type != nullptr && *type != QString("")){ if(type != nullptr && *type != QString("")){
toJsonValue(QString("type"), type, obj, QString("QString")); toJsonValue(QString("type"), type, obj, QString("QString"));

View File

@ -31,15 +31,15 @@ namespace Swagger {
class SWGApiResponse: public SWGObject { class SWGApiResponse: public SWGObject {
public: public:
SWGApiResponse(); SWGApiResponse();
SWGApiResponse(QString* json); SWGApiResponse(QString json);
virtual ~SWGApiResponse(); ~SWGApiResponse();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGApiResponse* fromJson(QString &jsonString); SWGApiResponse* fromJson(QString jsonString);
qint32 getCode(); qint32 getCode();
void setCode(qint32 code); void setCode(qint32 code);

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGCategory::SWGCategory(QString* json) { SWGCategory::SWGCategory(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGCategory::SWGCategory() { SWGCategory::SWGCategory() {
@ -52,7 +52,7 @@ SWGCategory::cleanup() {
} }
SWGCategory* SWGCategory*
SWGCategory::fromJson(QString &json) { SWGCategory::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -61,7 +61,7 @@ SWGCategory::fromJson(QString &json) {
} }
void void
SWGCategory::fromJsonObject(QJsonObject &pJson) { SWGCategory::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&id, pJson["id"], "qint64", "");
::Swagger::setValue(&name, pJson["name"], "QString", "QString"); ::Swagger::setValue(&name, pJson["name"], "QString", "QString");
@ -71,18 +71,17 @@ SWGCategory::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGCategory::asJson () SWGCategory::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGCategory::asJsonObject() { SWGCategory::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj.insert("id", QJsonValue(id));
} }
if(name != nullptr && *name != QString("")){ if(name != nullptr && *name != QString("")){
toJsonValue(QString("name"), name, obj, QString("QString")); toJsonValue(QString("name"), name, obj, QString("QString"));

View File

@ -31,15 +31,15 @@ namespace Swagger {
class SWGCategory: public SWGObject { class SWGCategory: public SWGObject {
public: public:
SWGCategory(); SWGCategory();
SWGCategory(QString* json); SWGCategory(QString json);
virtual ~SWGCategory(); ~SWGCategory();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGCategory* fromJson(QString &jsonString); SWGCategory* fromJson(QString jsonString);
qint64 getId(); qint64 getId();
void setId(qint64 id); void setId(qint64 id);

View File

@ -41,7 +41,7 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
else if(QStringLiteral("float").compare(type) == 0) { else if(QStringLiteral("float").compare(type) == 0) {
float *val = static_cast<float*>(value); float *val = static_cast<float*>(value);
*val = obj.toDouble(); *val = static_cast<float>(obj.toDouble());
} }
else if(QStringLiteral("double").compare(type) == 0) { else if(QStringLiteral("double").compare(type) == 0) {
double *val = static_cast<double*>(value); double *val = static_cast<double*>(value);
@ -51,20 +51,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
QString **val = static_cast<QString**>(value); QString **val = static_cast<QString**>(value);
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return (*val)->clear();
if(*val != nullptr) delete *val; (*val)->append(obj.toString());
*val = new QString(obj.toString());
return; return;
} }
else { else {
// set target to nullptr (*val)->clear();
if(*val != nullptr) delete *val;
*val = nullptr;
} }
} }
else {
qDebug() << "Can't set value because the target pointer is nullptr";
}
} }
else if (QStringLiteral("QDateTime").compare(type) == 0) { else if (QStringLiteral("QDateTime").compare(type) == 0) {
QDateTime **val = static_cast<QDateTime**>(value); QDateTime **val = static_cast<QDateTime**>(value);
@ -380,67 +374,66 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
void void
toJsonValue(QString name, void* value, QJsonObject* output, QString type) { toJsonValue(QString name, void* value, QJsonObject& output, QString type) {
if(value == nullptr) { if(value == nullptr) {
return; return;
} }
if(type.startsWith("SWG")) { if(type.startsWith("SWG")) {
SWGObject *SWGobject = reinterpret_cast<SWGObject *>(value); SWGObject *SWGobject = reinterpret_cast<SWGObject *>(value);
if(SWGobject != nullptr) { if(SWGobject != nullptr) {
QJsonObject* o = (*SWGobject).asJsonObject(); QJsonObject o = SWGobject->asJsonObject();
if(name != nullptr) { if(!name.isNull()) {
output->insert(name, *o); output.insert(name, o);
if(o != nullptr) delete o;
} }
else { else {
output->empty(); output.empty();
for(QString key : o->keys()) { for(QString key : o.keys()) {
output->insert(key, o->value(key)); output.insert(key, o.value(key));
} }
} }
} }
} }
else if(QStringLiteral("QString").compare(type) == 0) { else if(QStringLiteral("QString").compare(type) == 0) {
QString* str = static_cast<QString*>(value); QString* str = static_cast<QString*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("qint32").compare(type) == 0) { else if(QStringLiteral("qint32").compare(type) == 0) {
qint32* str = static_cast<qint32*>(value); qint32* str = static_cast<qint32*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("qint64").compare(type) == 0) { else if(QStringLiteral("qint64").compare(type) == 0) {
qint64* str = static_cast<qint64*>(value); qint64* str = static_cast<qint64*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("bool").compare(type) == 0) { else if(QStringLiteral("bool").compare(type) == 0) {
bool* str = static_cast<bool*>(value); bool* str = static_cast<bool*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("float").compare(type) == 0) { else if(QStringLiteral("float").compare(type) == 0) {
float* str = static_cast<float*>(value); float* str = static_cast<float*>(value);
output->insert(name, QJsonValue((double)*str)); output.insert(name, QJsonValue((double)*str));
} }
else if(QStringLiteral("double").compare(type) == 0) { else if(QStringLiteral("double").compare(type) == 0) {
double* str = static_cast<double*>(value); double* str = static_cast<double*>(value);
output->insert(name, QJsonValue(*str)); output.insert(name, QJsonValue(*str));
} }
else if(QStringLiteral("QDate").compare(type) == 0) { else if(QStringLiteral("QDate").compare(type) == 0) {
QDate* date = static_cast<QDate*>(value); QDate* date = static_cast<QDate*>(value);
output->insert(name, QJsonValue(date->toString(Qt::ISODate))); output.insert(name, QJsonValue(date->toString(Qt::ISODate)));
} }
else if(QStringLiteral("QDateTime").compare(type) == 0) { else if(QStringLiteral("QDateTime").compare(type) == 0) {
QDateTime* datetime = static_cast<QDateTime*>(value); QDateTime* datetime = static_cast<QDateTime*>(value);
output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); output.insert(name, QJsonValue(datetime->toString(Qt::ISODate)));
} }
else if(QStringLiteral("QByteArray").compare(type) == 0) { else if(QStringLiteral("QByteArray").compare(type) == 0) {
QByteArray* byteArray = static_cast<QByteArray*>(value); QByteArray* byteArray = static_cast<QByteArray*>(value);
output->insert(name, QJsonValue(QString(byteArray->toBase64()))); output.insert(name, QJsonValue(QString(byteArray->toBase64())));
} }
} }
void void
toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType) { toJsonArray(QList<void*>* value, QJsonObject& output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) { if(value == nullptr) {
return; return;
} }
QJsonArray outputarray; QJsonArray outputarray;
@ -448,7 +441,7 @@ toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString
for(void* obj : *value) { for(void* obj : *value) {
SWGObject *SWGobject = reinterpret_cast<SWGObject *>(obj); SWGObject *SWGobject = reinterpret_cast<SWGObject *>(obj);
if(SWGobject != nullptr) { if(SWGobject != nullptr) {
outputarray.append(*(SWGobject->asJsonObject())); outputarray.append(SWGobject->asJsonObject());
} }
} }
} }
@ -491,81 +484,81 @@ toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString
for(double obj : *(reinterpret_cast<QList<double>*>(value))) for(double obj : *(reinterpret_cast<QList<double>*>(value)))
outputarray.append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
output->insert(innerName, outputarray); output.insert(innerName, outputarray);
} }
void void
toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType) { toJsonMap(QMap<QString, void*>* value, QJsonObject& output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) { if(value == nullptr) {
return; return;
} }
QJsonObject mapobj; QJsonObject mapobj;
if(innerType.startsWith("SWG")){ if(innerType.startsWith("SWG")){
auto items = reinterpret_cast< QMap<QString, SWGObject*> *>(value); auto items = reinterpret_cast< QMap<QString, SWGObject*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QString").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QString*> *>(value); auto items = reinterpret_cast< QMap<QString, QString*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QDate").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QDate*> *>(value); auto items = reinterpret_cast< QMap<QString, QDate*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QDateTime").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QDateTime*> *>(value); auto items = reinterpret_cast< QMap<QString, QDateTime*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("QByteArray").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, QByteArray*> *>(value); auto items = reinterpret_cast< QMap<QString, QByteArray*> *>(value);
for(auto itemkey: items->keys()) { 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) { else if(QStringLiteral("qint32").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, qint32> *>(value); auto items = reinterpret_cast< QMap<QString, qint32> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("qint64").compare(innerType) == 0) { else if(QStringLiteral("qint64").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, qint64> *>(value); auto items = reinterpret_cast< QMap<QString, qint64> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("bool").compare(innerType) == 0) { else if(QStringLiteral("bool").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, bool> *>(value); auto items = reinterpret_cast< QMap<QString, bool> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("float").compare(innerType) == 0) { else if(QStringLiteral("float").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, float> *>(value); auto items = reinterpret_cast< QMap<QString, float> *>(value);
for(auto itemkey: items->keys()) { for(auto itemkey: items->keys()) {
auto val = items->value(itemkey); auto val = items->value(itemkey);
::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType); ::Swagger::toJsonValue(itemkey, &val, mapobj, innerType);
} }
} }
else if(QStringLiteral("double").compare(innerType) == 0) { else if(QStringLiteral("double").compare(innerType) == 0) {
auto items = reinterpret_cast< QMap<QString, double> *>(value); auto items = reinterpret_cast< QMap<QString, double> *>(value);
for(auto itemkey: items->keys() ) { for(auto itemkey: items->keys() ) {
auto val = items->value(itemkey); 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 QString

View File

@ -20,9 +20,9 @@
namespace Swagger { namespace Swagger {
void setValue(void* value, QJsonValue obj, QString type, QString complexType); void setValue(void* value, QJsonValue obj, QString type, QString complexType);
void toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType); void toJsonArray(QList<void*>* value, QJsonObject& output, QString innerName, QString innerType);
void toJsonValue(QString name, void* value, QJsonObject* output, QString type); void toJsonValue(QString name, void* value, QJsonObject& output, QString type);
void toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType); void toJsonMap(QMap<QString, void*>* value, QJsonObject& output, QString innerName, QString innerType);
bool isCompatibleJsonValue(QString type); bool isCompatibleJsonValue(QString type);
QString stringValue(QString* value); QString stringValue(QString* value);
QString stringValue(qint32 value); QString stringValue(qint32 value);

View File

@ -56,7 +56,7 @@ SWGHttpRequestWorker::SWGHttpRequestWorker(QObject *parent)
qsrand(QDateTime::currentDateTime().toTime_t()); qsrand(QDateTime::currentDateTime().toTime_t());
manager = new QNetworkAccessManager(this); 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() { SWGHttpRequestWorker::~SWGHttpRequestWorker() {

View File

@ -47,13 +47,12 @@ namespace Swagger {
} }
inline void* create(QString json, QString type) { inline void* create(QString json, QString type) {
void* val = create(type);
if(val != nullptr) {
SWGObject* obj = static_cast<SWGObject*>(val);
return obj->fromJson(json);
}
if(type.startsWith("QString")) { if(type.startsWith("QString")) {
return new QString(); return new QString();
}
auto val = static_cast<SWGObject*>(create(type));
if(val != nullptr) {
return val->fromJson(json);
} }
return nullptr; return nullptr;
} }

View File

@ -19,15 +19,15 @@ namespace Swagger {
class SWGObject { class SWGObject {
public: public:
virtual QJsonObject* asJsonObject() { virtual QJsonObject asJsonObject() {
return new QJsonObject(); return QJsonObject();
} }
virtual ~SWGObject() {} virtual ~SWGObject() {}
virtual SWGObject* fromJson(QString &jsonString) { virtual SWGObject* fromJson(QString jsonString) {
Q_UNUSED(jsonString); Q_UNUSED(jsonString);
return new SWGObject(); return new SWGObject();
} }
virtual void fromJsonObject(QJsonObject &json) { virtual void fromJsonObject(QJsonObject json) {
Q_UNUSED(json); Q_UNUSED(json);
} }
virtual QString asJson() { virtual QString asJson() {

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGOrder::SWGOrder(QString* json) { SWGOrder::SWGOrder(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGOrder::SWGOrder() { SWGOrder::SWGOrder() {
@ -66,7 +66,7 @@ SWGOrder::cleanup() {
} }
SWGOrder* SWGOrder*
SWGOrder::fromJson(QString &json) { SWGOrder::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -75,7 +75,7 @@ SWGOrder::fromJson(QString &json) {
} }
void void
SWGOrder::fromJsonObject(QJsonObject &pJson) { SWGOrder::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&id, pJson["id"], "qint64", "");
::Swagger::setValue(&pet_id, pJson["petId"], "qint64", ""); ::Swagger::setValue(&pet_id, pJson["petId"], "qint64", "");
@ -93,24 +93,23 @@ SWGOrder::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGOrder::asJson () SWGOrder::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGOrder::asJsonObject() { SWGOrder::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj.insert("id", QJsonValue(id));
} }
if(m_pet_id_isSet){ if(m_pet_id_isSet){
obj->insert("petId", QJsonValue(pet_id)); obj.insert("petId", QJsonValue(pet_id));
} }
if(m_quantity_isSet){ if(m_quantity_isSet){
obj->insert("quantity", QJsonValue(quantity)); obj.insert("quantity", QJsonValue(quantity));
} }
if(ship_date != nullptr) { if(ship_date != nullptr) {
toJsonValue(QString("shipDate"), ship_date, obj, QString("QDateTime")); toJsonValue(QString("shipDate"), ship_date, obj, QString("QDateTime"));
@ -119,7 +118,7 @@ SWGOrder::asJsonObject() {
toJsonValue(QString("status"), status, obj, QString("QString")); toJsonValue(QString("status"), status, obj, QString("QString"));
} }
if(m_complete_isSet){ if(m_complete_isSet){
obj->insert("complete", QJsonValue(complete)); obj.insert("complete", QJsonValue(complete));
} }
return obj; return obj;

View File

@ -32,15 +32,15 @@ namespace Swagger {
class SWGOrder: public SWGObject { class SWGOrder: public SWGObject {
public: public:
SWGOrder(); SWGOrder();
SWGOrder(QString* json); SWGOrder(QString json);
virtual ~SWGOrder(); ~SWGOrder();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGOrder* fromJson(QString &jsonString); SWGOrder* fromJson(QString jsonString);
qint64 getId(); qint64 getId();
void setId(qint64 id); void setId(qint64 id);

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGPet::SWGPet(QString* json) { SWGPet::SWGPet(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGPet::SWGPet() { SWGPet::SWGPet() {
@ -80,7 +80,7 @@ SWGPet::cleanup() {
} }
SWGPet* SWGPet*
SWGPet::fromJson(QString &json) { SWGPet::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -89,7 +89,7 @@ SWGPet::fromJson(QString &json) {
} }
void void
SWGPet::fromJsonObject(QJsonObject &pJson) { SWGPet::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&id, pJson["id"], "qint64", "");
::Swagger::setValue(&category, pJson["category"], "SWGCategory", "SWGCategory"); ::Swagger::setValue(&category, pJson["category"], "SWGCategory", "SWGCategory");
@ -107,18 +107,17 @@ SWGPet::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGPet::asJson () SWGPet::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGPet::asJsonObject() { SWGPet::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj.insert("id", QJsonValue(id));
} }
if((category != nullptr) && (category->isSet())){ if((category != nullptr) && (category->isSet())){
toJsonValue(QString("category"), category, obj, QString("SWGCategory")); toJsonValue(QString("category"), category, obj, QString("SWGCategory"));

View File

@ -34,15 +34,15 @@ namespace Swagger {
class SWGPet: public SWGObject { class SWGPet: public SWGObject {
public: public:
SWGPet(); SWGPet();
SWGPet(QString* json); SWGPet(QString json);
virtual ~SWGPet(); ~SWGPet();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGPet* fromJson(QString &jsonString); SWGPet* fromJson(QString jsonString);
qint64 getId(); qint64 getId();
void setId(qint64 id); void setId(qint64 id);

View File

@ -127,7 +127,7 @@ SWGStoreApi::getInventoryCallback(SWGHttpRequestWorker * worker) {
foreach(QString key, obj.keys()) { foreach(QString key, obj.keys()) {
qint32* val; qint32* val;
setValue(&val, obj[key], "qint32", ""); setValue(&val, obj[key], "qint32", QString());
output->insert(key, *val); output->insert(key, *val);
} }
worker->deleteLater(); worker->deleteLater();

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGTag::SWGTag(QString* json) { SWGTag::SWGTag(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGTag::SWGTag() { SWGTag::SWGTag() {
@ -52,7 +52,7 @@ SWGTag::cleanup() {
} }
SWGTag* SWGTag*
SWGTag::fromJson(QString &json) { SWGTag::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -61,7 +61,7 @@ SWGTag::fromJson(QString &json) {
} }
void void
SWGTag::fromJsonObject(QJsonObject &pJson) { SWGTag::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&id, pJson["id"], "qint64", "");
::Swagger::setValue(&name, pJson["name"], "QString", "QString"); ::Swagger::setValue(&name, pJson["name"], "QString", "QString");
@ -71,18 +71,17 @@ SWGTag::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGTag::asJson () SWGTag::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGTag::asJsonObject() { SWGTag::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj.insert("id", QJsonValue(id));
} }
if(name != nullptr && *name != QString("")){ if(name != nullptr && *name != QString("")){
toJsonValue(QString("name"), name, obj, QString("QString")); toJsonValue(QString("name"), name, obj, QString("QString"));

View File

@ -31,15 +31,15 @@ namespace Swagger {
class SWGTag: public SWGObject { class SWGTag: public SWGObject {
public: public:
SWGTag(); SWGTag();
SWGTag(QString* json); SWGTag(QString json);
virtual ~SWGTag(); ~SWGTag();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGTag* fromJson(QString &jsonString); SWGTag* fromJson(QString jsonString);
qint64 getId(); qint64 getId();
void setId(qint64 id); void setId(qint64 id);

View File

@ -22,9 +22,9 @@
namespace Swagger { namespace Swagger {
SWGUser::SWGUser(QString* json) { SWGUser::SWGUser(QString json) {
init(); init();
this->fromJson(*json); this->fromJson(json);
} }
SWGUser::SWGUser() { SWGUser::SWGUser() {
@ -80,7 +80,7 @@ SWGUser::cleanup() {
} }
SWGUser* SWGUser*
SWGUser::fromJson(QString &json) { SWGUser::fromJson(QString json) {
QByteArray array (json.toStdString().c_str()); QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array); QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object(); QJsonObject jsonObject = doc.object();
@ -89,7 +89,7 @@ SWGUser::fromJson(QString &json) {
} }
void void
SWGUser::fromJsonObject(QJsonObject &pJson) { SWGUser::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&id, pJson["id"], "qint64", ""); ::Swagger::setValue(&id, pJson["id"], "qint64", "");
::Swagger::setValue(&username, pJson["username"], "QString", "QString"); ::Swagger::setValue(&username, pJson["username"], "QString", "QString");
@ -111,18 +111,17 @@ SWGUser::fromJsonObject(QJsonObject &pJson) {
QString QString
SWGUser::asJson () SWGUser::asJson ()
{ {
QJsonObject* obj = this->asJsonObject(); QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
return QString(bytes); return QString(bytes);
} }
QJsonObject* QJsonObject
SWGUser::asJsonObject() { SWGUser::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject obj;
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj.insert("id", QJsonValue(id));
} }
if(username != nullptr && *username != QString("")){ if(username != nullptr && *username != QString("")){
toJsonValue(QString("username"), username, obj, QString("QString")); toJsonValue(QString("username"), username, obj, QString("QString"));
@ -143,7 +142,7 @@ SWGUser::asJsonObject() {
toJsonValue(QString("phone"), phone, obj, QString("QString")); toJsonValue(QString("phone"), phone, obj, QString("QString"));
} }
if(m_user_status_isSet){ if(m_user_status_isSet){
obj->insert("userStatus", QJsonValue(user_status)); obj.insert("userStatus", QJsonValue(user_status));
} }
return obj; return obj;

View File

@ -31,15 +31,15 @@ namespace Swagger {
class SWGUser: public SWGObject { class SWGUser: public SWGObject {
public: public:
SWGUser(); SWGUser();
SWGUser(QString* json); SWGUser(QString json);
virtual ~SWGUser(); ~SWGUser();
void init(); void init();
void cleanup(); void cleanup();
QString asJson (); QString asJson ();
QJsonObject* asJsonObject(); QJsonObject asJsonObject();
void fromJsonObject(QJsonObject &json); void fromJsonObject(QJsonObject json);
SWGUser* fromJson(QString &jsonString); SWGUser* fromJson(QString jsonString);
qint64 getId(); qint64 getId();
void setId(qint64 id); void setId(qint64 id);

View File

@ -91,10 +91,10 @@ SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>*& body) {
SWGHttpRequestInput input(fullPath, "POST"); SWGHttpRequestInput input(fullPath, "POST");
auto body_jobj = new QJsonObject(); QJsonObject body_jobj;
toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*")); toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*body_jobj); QJsonDocument doc(body_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -147,10 +147,10 @@ SWGUserApi::createUsersWithListInput(QList<SWGUser*>*& body) {
SWGHttpRequestInput input(fullPath, "POST"); SWGHttpRequestInput input(fullPath, "POST");
auto body_jobj = new QJsonObject(); QJsonObject body_jobj;
toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*")); toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*body_jobj); QJsonDocument doc(body_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);