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 5e3290aded4b..263c089d2449 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache @@ -22,7 +22,7 @@ namespace {{this}} { {{#operations}} {{#operation}} void -{{classname}}::{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { +{{classname}}::{{nickname}}({{#allParams}}{{{dataType}}}{{#isBodyParam}}&{{/isBodyParam}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("{{{path}}}"); @@ -98,17 +98,17 @@ void {{#bodyParams}} {{#isContainer}} - QJsonArray* {{paramName}}Array = new QJsonArray(); - toJsonArray((QList*){{paramName}}, {{paramName}}Array, QString("body"), QString("{{prefix}}User*")); + auto {{paramName}}_jobj = new QJsonObject(); + toJsonArray((QList*){{paramName}}, {{paramName}}_jobj, QString("body"), QString("{{prefix}}User*")); - QJsonDocument doc(*{{paramName}}Array); + QJsonDocument doc(*{{paramName}}_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); {{/isContainer}} {{^isContainer}}{{#isString}} - QString output(*{{paramName}});{{/isString}}{{^isString}} - QString output = {{paramName}}.asJson();{{/isString}} + QString output(*{{paramName}});{{/isString}}{{#isByteArray}}QString output(*{{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}} + QString output = {{paramName}}.asJson();{{/isByteArray}}{{/isString}} input.request_body.append(output); {{/isContainer}}{{/bodyParams}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache index 286936ef64a5..b992c16c1d12 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache @@ -25,7 +25,7 @@ public: QString basePath; QMap defaultHeaders; - {{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + {{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}}{{#isBodyParam}}&{{/isBodyParam}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); {{/operation}}{{/operations}} private: {{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker); 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 8bd673e980e5..1ef996838b8b 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -40,17 +40,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } else if (QStringLiteral("QString").compare(type) == 0) { QString **val = static_cast(value); - if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QString(obj.toString()); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -64,13 +63,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -84,13 +83,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -104,14 +103,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString()))); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -122,124 +121,253 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { else if(type.startsWith("{{prefix}}") && obj.isObject()) { // complex type QJsonObject jsonObj = obj.toObject(); - {{prefix}}Object * so = ({{prefix}}Object*)::{{cppNamespace}}::create(type); + {{prefix}}Object * so = ({{prefix}}Object*)::{{cppNamespace}}::create(complexType); if(so != nullptr) { so->fromJsonObject(jsonObj); {{prefix}}Object **val = static_cast<{{prefix}}Object**>(value); - delete *val; + if(*val != nullptr) delete *val; *val = so; } } else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { // list of values if(complexType.startsWith("{{prefix}}")) { - QList<{{prefix}}Object*>* output = new QList<{{prefix}}Object*>(); + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr) { // it's an object - {{prefix}}Object * val = ({{prefix}}Object*)create(complexType); + {{prefix}}Object * val = ({{prefix}}Object*)::{{cppNamespace}}::create(complexType); QJsonObject t = jval.toObject(); - val->fromJsonObject(t); - output->append(val); - } - QList<{{prefix}}Object*> **val = static_cast**>(value); - for (auto item : **val) { - delete item; + (*output)->append(val); } - delete *val; - *val = output; } else if(QStringLiteral("qint32").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ qint32 val; - setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("qint64").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ qint64 val; - setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("bool").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ bool val; - setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("float").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ float val; - setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("double").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ double val; - setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QString").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QString * val = new QString(); - setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QDate").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QDate * val = new QDate(); - setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QDateTime").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QDateTime * val = new QDateTime(); - setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); + ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); (*output)->push_back(val); } } } + else if(type.startsWith("QMap") && QString("").compare(complexType) != 0 && obj.isObject()) { + // list of values + if(complexType.startsWith("{{prefix}}")) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + auto val = ({{prefix}}Object*)::{{cppNamespace}}::create(complexType); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, complexType, complexType); + (*output)->insert(itemkey, val); + } + } + } + else if(QStringLiteral("qint32").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + qint32 val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("qint32"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("qint64").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + qint64 val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("qint64"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("bool").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + bool val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("bool"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("float").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + float val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("float"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("double").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + double val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("double"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QString").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QString * val = new QString(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("QString"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QDate").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QDate * val = new QDate(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("QDate"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QDateTime").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QDateTime * val = new QDateTime(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::{{cppNamespace}}::setValue(&val, jsonval, QStringLiteral("QDateTime"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + } } void @@ -253,7 +381,7 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { QJsonObject* o = (*{{prefix}}object).asJsonObject(); if(name != nullptr) { output->insert(name, *o); - delete o; + if(o != nullptr) delete o; } else { output->empty(); @@ -302,54 +430,133 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { } void -toJsonArray(QList* value, QJsonArray* output, QString innerName, QString innerType) { +toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType) { + if((value == nullptr) || (output == nullptr)) { + return; + } + QJsonArray outputarray; if(innerType.startsWith("{{prefix}}")){ for(void* obj : *value) { {{prefix}}Object *{{prefix}}object = reinterpret_cast<{{prefix}}Object *>(obj); if({{prefix}}object != nullptr) { - output->append(*({{prefix}}object->asJsonObject())); + outputarray.append(*({{prefix}}object->asJsonObject())); } } } else if(QStringLiteral("QString").compare(innerType) == 0) { for(QString* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(*obj)); + outputarray.append(QJsonValue(*obj)); } } else if(QStringLiteral("QDate").compare(innerType) == 0) { for(QDate* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(obj->toString(Qt::ISODate))); + outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); } } else if(QStringLiteral("QDateTime").compare(innerType) == 0) { for(QDateTime* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(obj->toString(Qt::ISODate))); } + outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); } } else if(QStringLiteral("QByteArray").compare(innerType) == 0) { for(QByteArray* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(QString(obj->toBase64()))); + outputarray.append(QJsonValue(QString(obj->toBase64()))); } } else if(QStringLiteral("qint32").compare(innerType) == 0) { for(qint32 obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("qint64").compare(innerType) == 0) { for(qint64 obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("bool").compare(innerType) == 0) { for(bool obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("float").compare(innerType) == 0) { for(float obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("double").compare(innerType) == 0) { for(double obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); + } + output->insert(innerName, outputarray); +} + +void +toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType) { + if((value == nullptr) || (output == 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } } + output->insert(innerName, mapobj); } QString 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 d35465685bfb..c3569d7e7be6 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache @@ -9,8 +9,9 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} void setValue(void* value, QJsonValue obj, QString type, QString complexType); - void toJsonArray(QList* value, QJsonArray* 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 ceb8b05cdb73..f5e707f56052 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache @@ -38,12 +38,15 @@ void {{classname}}::cleanup() { {{#vars}} {{#complexType}} - if({{name}} != nullptr) { - {{#isContainer}}{{#isListContainer}}QList<{{complexType}}*>* arr = {{name}};{{/isListContainer}}{{#isMapContainer}}QMap* arr = {{name}};{{/isMapContainer}} - foreach({{complexType}}* o, *arr) { + if({{name}} != nullptr) { {{#isContainer}} + auto arr = {{name}}; + for(auto o: *arr) { {{#items.isContainer}} + for(auto o1: *o) { + delete o1; + }{{/items.isContainer}} delete o; - } - {{/isContainer}}delete {{name}}; + }{{/isContainer}} + delete {{name}}; }{{/complexType}} {{/vars}} } @@ -60,33 +63,30 @@ void void {{classname}}::fromJsonObject(QJsonObject &pJson) { {{#vars}} - {{^isContainer}} - ::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}"); - {{/isContainer}} - {{#isListContainer}} - {{#complexType}} - ::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}"); - {{/complexType}} - {{^complexType}} - ::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}"); - {{/complexType}} - {{/isListContainer}} - {{#isMapContainer}} - if( pJson["{{baseName}}"].isObject()){ + {{^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}} + if(pJson["{{baseName}}"].isArray()){ + auto arr = pJson["{{baseName}}"].toArray(); + for (const QJsonValue & jval : arr) { + {{#items.isListContainer}}auto {{name}}_item = new QList<{{items.items.baseType}}{{^items.items.isLong}}{{^items.items.isInteger}}{{^items.items.isDouble}}{{^items.items.isFloat}}{{^items.items.isBoolean}}*{{/items.items.isBoolean}}{{/items.items.isFloat}}{{/items.items.isDouble}}{{/items.items.isInteger}}{{/items.items.isLong}}>();{{/items.isListContainer}} + {{#items.isMapContainer}}auto {{name}}_item = new QMap();{{/items.isMapContainer}} + auto jsonval = jval.toObject(); + ::{{cppNamespace}}::setValue({{name}}_item, jsonval, "{{items.baseType}}", "{{items.items.baseType}}"); + {{name}}->push_back({{name}}_item); + } + }{{/isListContainer}}{{#isMapContainer}} + if(pJson["{{baseName}}"].isObject()){ auto varmap = pJson["{{baseName}}"].toObject().toVariantMap(); if(varmap.count() > 0){ - for(auto val : varmap.keys() ){ - { - {{items.baseType}} *{{name}}_item = new {{items.baseType}}(); - auto jsonval = QJsonValue::fromVariant(varmap[val]); - ::{{cppNamespace}}::setValue(&{{name}}_item, jsonval, "{{items.baseType}}", "{{items.baseType}}"); - {{name}}->insert({{name}}->end(), val, {{name}}_item); - } + for(auto val : varmap.keys()){ + {{#items.isListContainer}}auto {{name}}_item = new QList<{{items.items.baseType}}{{^items.items.isLong}}{{^items.items.isInteger}}{{^items.items.isDouble}}{{^items.items.isFloat}}{{^items.items.isBoolean}}*{{/items.items.isBoolean}}{{/items.items.isFloat}}{{/items.items.isDouble}}{{/items.items.isInteger}}{{/items.items.isLong}}>();{{/items.isListContainer}} + {{#items.isMapContainer}}auto {{name}}_item = new QMap();{{/items.isMapContainer}} + auto jsonval = QJsonValue::fromVariant(varmap.value(val)); + ::{{cppNamespace}}::setValue((QMap*)&{{name}}_item, jsonval, "{{items.baseType}}", "{{items.items.baseType}}"); + {{name}}->insert({{name}}->end(), val, {{name}}_item); } } - } - - {{/isMapContainer}} + }{{/isMapContainer}}{{/items.isContainer}}{{/isContainer}} {{/vars}} } @@ -104,77 +104,47 @@ QJsonObject* {{classname}}::asJsonObject() { QJsonObject* obj = new QJsonObject(); {{#vars}} - {{#complexType}} - {{^isContainer}} - {{#complexType}} - {{^isString}} - {{^isDateTime}} + {{^isContainer}}{{#complexType}}{{^isString}}{{^isDate}}{{^isDateTime}}{{^isByteArray}} if({{name}}->isSet()){ toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); - } - {{/isDateTime}} - {{/isString}} - {{#isString}} + }{{/isByteArray}}{{/isDateTime}}{{/isDate}}{{/isString}}{{#isString}} if({{name}} != nullptr && *{{name}} != QString("")){ toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); - } - {{/isString}} - {{/complexType}} - {{^complexType}} - if({{name}} != nullptr && *{{name}} != nullptr) { - obj->insert("{{name}}", QJsonValue(*{{name}})); - } - {{/complexType}} - {{/isContainer}} - {{#isListContainer}} - if({{name}}->size() > 0){ - QJsonArray {{name}}JsonArray; - toJsonArray((QList*){{name}}, &{{name}}JsonArray, "{{name}}", "{{complexType}}"); - obj->insert("{{baseName}}", {{name}}JsonArray); - } - {{/isListContainer}} - {{#isMapContainer}} - if({{name}}->size() > 0) { - QJsonObject {{name}}_jobj; - for(auto keyval : {{name}}->keys()){ - toJsonValue(keyval, ((*{{name}})[keyval]), &{{name}}_jobj, "{{complexType}}"); - } - obj->insert("{{baseName}}", {{name}}_jobj); - } - {{/isMapContainer}} - {{/complexType}} - {{^complexType}} - {{^isContainer}} - {{^isString}} - {{^isDateTime}} + }{{/isString}}{{/complexType}}{{#isPrimitiveType}}{{^isDateTime}}{{^isDate}}{{^isByteArray}} if(m_{{name}}_isSet){ obj->insert("{{baseName}}", QJsonValue({{name}})); - } - {{/isDateTime}} - {{/isString}} - {{#isString}} - if({{name}} != nullptr && *{{name}} != QString("")) { + }{{/isByteArray}}{{/isDate}}{{/isDateTime}}{{/isPrimitiveType}}{{#isDate}} + if({{name}} != nullptr) { + toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); + }{{/isDate}}{{#isByteArray}} + if({{name}} != nullptr) { obj->insert("{{name}}", QJsonValue(*{{name}})); - } - {{/isString}} - {{/isContainer}} - {{#isListContainer}} + }{{/isByteArray}}{{#isDateTime}} + if({{name}} != nullptr) { + toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); + }{{/isDateTime}}{{/isContainer}}{{#isContainer}}{{#isListContainer}} if({{name}}->size() > 0){ - QJsonArray {{name}}JsonArray; - toJsonArray((QList*){{name}}, &{{name}}JsonArray, "{{name}}", "{{items.baseType}}"); - obj->insert("{{baseName}}", {{name}}JsonArray); - } - {{/isListContainer}} - {{#isMapContainer}} + {{^items.isContainer}}toJsonArray((QList*){{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}} + QJsonArray jarray; + for(auto items : *{{name}}){ + QJsonObject jobj; + {{#items.isListContainer}}toJsonArray((QList*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}");{{/items.isListContainer}} + {{#items.isMapContainer}}toJsonMap((QMap*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}");{{/items.isMapContainer}} + jarray.append(jobj.value("{{baseName}}")); + } + obj->insert("{{baseName}}", jarray);{{/items.isContainer}} + }{{/isListContainer}}{{#isMapContainer}} if({{name}}->size() > 0){ - QJsonObject {{name}}_jobj; - for(auto keyval : {{name}}->keys()){ - toJsonValue(keyval, ((*{{name}})[keyval]), &{{name}}_jobj, "{{items.baseType}}"); - } - obj->insert("{{baseName}}", {{name}}_jobj); - } - {{/isMapContainer}} - {{/complexType}} + {{^items.isContainer}}toJsonMap((QMap*) {{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}} + QJsonObject mapobj; + for(auto itemkey : {{name}}->keys()){ + QJsonObject jobj; + {{#items.isListContainer}}toJsonArray((QList*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}");{{/items.isListContainer}} + {{#items.isMapContainer}}toJsonMap((QMap*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}");{{/items.isMapContainer}} + mapobj.insert(itemkey, jobj); + } + obj->insert("{{baseName}}", mapobj);{{/items.isContainer}} + }{{/isMapContainer}}{{/isContainer}} {{/vars}} return obj; diff --git a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro index f8c5480023d3..64f27a3c9249 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro +++ b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro @@ -18,31 +18,31 @@ TEMPLATE = app SOURCES += main.cpp \ - ../client/Category.cpp \ + ../client/SWGCategory.cpp \ ../client/SWGHelpers.cpp \ ../client/SWGHttpRequest.cpp \ - ../client/Order.cpp \ - ../client/Pet.cpp \ + ../client/SWGOrder.cpp \ + ../client/SWGPet.cpp \ ../client/SWGPetApi.cpp \ ../client/SWGStoreApi.cpp \ - ../client/Tag.cpp \ - ../client/User.cpp \ + ../client/SWGTag.cpp \ + ../client/SWGUser.cpp \ ../client/SWGUserApi.cpp \ - ../client/ApiResponse.cpp \ + ../client/SWGApiResponse.cpp \ PetApiTests.cpp HEADERS += \ - ../client/Category.h \ + ../client/SWGCategory.h \ ../client/SWGHelpers.h \ ../client/SWGHttpRequest.h \ ../client/SWGObject.h \ - ../client/Order.h \ - ../client/Pet.h \ + ../client/SWGOrder.h \ + ../client/SWGPet.h \ ../client/SWGPetApi.h \ ../client/SWGStoreApi.h \ - ../client/Tag.h \ - ../client/User.h \ + ../client/SWGTag.h \ + ../client/SWGUser.h \ ../client/SWGUserApi.h \ PetApiTests.h \ - ../client/ApiResponse.h \ + ../client/SWGApiResponse.h \ ../client/SWGModelFactory.h diff --git a/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp b/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp index 276270ae3cd4..84999f3b7071 100644 --- a/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGApiResponse.cpp @@ -48,10 +48,10 @@ SWGApiResponse::init() { void SWGApiResponse::cleanup() { - if(type != nullptr) { + if(type != nullptr) { delete type; } - if(message != nullptr) { + if(message != nullptr) { delete message; } } @@ -68,8 +68,11 @@ SWGApiResponse::fromJson(QString &json) { void SWGApiResponse::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&code, pJson["code"], "qint32", ""); + ::Swagger::setValue(&type, pJson["type"], "QString", "QString"); + ::Swagger::setValue(&message, pJson["message"], "QString", "QString"); + } QString @@ -85,12 +88,15 @@ SWGApiResponse::asJson () QJsonObject* SWGApiResponse::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_code_isSet){ obj->insert("code", QJsonValue(code)); } + if(type != nullptr && *type != QString("")){ toJsonValue(QString("type"), type, obj, QString("QString")); } + if(message != nullptr && *message != QString("")){ toJsonValue(QString("message"), message, obj, QString("QString")); } diff --git a/samples/client/petstore/qt5cpp/client/SWGCategory.cpp b/samples/client/petstore/qt5cpp/client/SWGCategory.cpp index b383141403df..b508e66e0147 100644 --- a/samples/client/petstore/qt5cpp/client/SWGCategory.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGCategory.cpp @@ -46,7 +46,7 @@ SWGCategory::init() { void SWGCategory::cleanup() { - if(name != nullptr) { + if(name != nullptr) { delete name; } } @@ -63,7 +63,9 @@ SWGCategory::fromJson(QString &json) { void SWGCategory::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); + ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); + } QString @@ -79,9 +81,11 @@ SWGCategory::asJson () QJsonObject* SWGCategory::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_id_isSet){ 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/SWGHelpers.cpp b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp index ed33368f1f73..cf8aa7eaf40e 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp @@ -49,17 +49,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { } else if (QStringLiteral("QString").compare(type) == 0) { QString **val = static_cast(value); - if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QString(obj.toString()); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -73,13 +72,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -93,13 +92,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -113,14 +112,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { if(val != nullptr) { if(!obj.isNull()) { // create a new value and return - delete *val; + if(*val != nullptr) delete *val; *val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString()))); return; } else { // set target to nullptr - delete *val; + if(*val != nullptr) delete *val; *val = nullptr; } } @@ -131,124 +130,253 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { else if(type.startsWith("SWG") && obj.isObject()) { // complex type QJsonObject jsonObj = obj.toObject(); - SWGObject * so = (SWGObject*)::Swagger::create(type); + SWGObject * so = (SWGObject*)::Swagger::create(complexType); if(so != nullptr) { so->fromJsonObject(jsonObj); SWGObject **val = static_cast(value); - delete *val; + if(*val != nullptr) delete *val; *val = so; } } else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { // list of values if(complexType.startsWith("SWG")) { - QList* output = new QList(); + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr) { // it's an object - SWGObject * val = (SWGObject*)create(complexType); + SWGObject * val = (SWGObject*)::Swagger::create(complexType); QJsonObject t = jval.toObject(); - val->fromJsonObject(t); - output->append(val); - } - QList **val = static_cast**>(value); - for (auto item : **val) { - delete item; + (*output)->append(val); } - delete *val; - *val = output; } else if(QStringLiteral("qint32").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ qint32 val; - setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("qint64").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ qint64 val; - setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("bool").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ bool val; - setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("float").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ float val; - setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("double").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ double val; - setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QString").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QString * val = new QString(); - setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QDate").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QDate * val = new QDate(); - setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); (*output)->push_back(val); } } else if(QStringLiteral("QDateTime").compare(complexType) == 0) { - QList **output = reinterpret_cast **> (value); + auto output = reinterpret_cast **> (value); for (auto item : **output) { - delete item; + if(item != nullptr) delete item; } (*output)->clear(); QJsonArray arr = obj.toArray(); for (const QJsonValue & jval : arr){ QDateTime * val = new QDateTime(); - setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); + ::Swagger::setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); (*output)->push_back(val); } } } + else if(type.startsWith("QMap") && QString("").compare(complexType) != 0 && obj.isObject()) { + // list of values + if(complexType.startsWith("SWG")) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + auto val = (SWGObject*)::Swagger::create(complexType); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, complexType, complexType); + (*output)->insert(itemkey, val); + } + } + } + else if(QStringLiteral("qint32").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + qint32 val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("qint32"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("qint64").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + qint64 val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("qint64"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("bool").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + bool val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("bool"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("float").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + float val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("float"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("double").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + double val; + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("double"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QString").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QString * val = new QString(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("QString"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QDate").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QDate * val = new QDate(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("QDate"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + else if(QStringLiteral("QDateTime").compare(complexType) == 0) { + auto output = reinterpret_cast **> (value); + for (auto item : **output) { + if(item != nullptr) delete item; + } + (*output)->clear(); + auto varmap = obj.toObject().toVariantMap(); + if(varmap.count() > 0){ + for(auto itemkey : varmap.keys() ){ + QDateTime * val = new QDateTime(); + auto jsonval = QJsonValue::fromVariant(varmap.value(itemkey)); + ::Swagger::setValue(&val, jsonval, QStringLiteral("QDateTime"), QStringLiteral("")); + (*output)->insert( itemkey, val); + } + } + } + } } void @@ -262,7 +390,7 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { QJsonObject* o = (*SWGobject).asJsonObject(); if(name != nullptr) { output->insert(name, *o); - delete o; + if(o != nullptr) delete o; } else { output->empty(); @@ -311,54 +439,133 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { } void -toJsonArray(QList* value, QJsonArray* output, QString innerName, QString innerType) { +toJsonArray(QList* value, QJsonObject* output, QString innerName, QString innerType) { + if((value == nullptr) || (output == nullptr)) { + return; + } + QJsonArray outputarray; if(innerType.startsWith("SWG")){ for(void* obj : *value) { SWGObject *SWGobject = reinterpret_cast(obj); if(SWGobject != nullptr) { - output->append(*(SWGobject->asJsonObject())); + outputarray.append(*(SWGobject->asJsonObject())); } } } else if(QStringLiteral("QString").compare(innerType) == 0) { for(QString* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(*obj)); + outputarray.append(QJsonValue(*obj)); } } else if(QStringLiteral("QDate").compare(innerType) == 0) { for(QDate* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(obj->toString(Qt::ISODate))); + outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); } } else if(QStringLiteral("QDateTime").compare(innerType) == 0) { for(QDateTime* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(obj->toString(Qt::ISODate))); } + outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); } } else if(QStringLiteral("QByteArray").compare(innerType) == 0) { for(QByteArray* obj : *(reinterpret_cast*>(value))){ - output->append(QJsonValue(QString(obj->toBase64()))); + outputarray.append(QJsonValue(QString(obj->toBase64()))); } } else if(QStringLiteral("qint32").compare(innerType) == 0) { for(qint32 obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("qint64").compare(innerType) == 0) { for(qint64 obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("bool").compare(innerType) == 0) { for(bool obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("float").compare(innerType) == 0) { for(float obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); } else if(QStringLiteral("double").compare(innerType) == 0) { for(double obj : *(reinterpret_cast*>(value))) - output->append(QJsonValue(obj)); + outputarray.append(QJsonValue(obj)); + } + output->insert(innerName, outputarray); +} + +void +toJsonMap(QMap* value, QJsonObject* output, QString innerName, QString innerType) { + if((value == nullptr) || (output == 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } + } + 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); + } } + output->insert(innerName, mapobj); } QString diff --git a/samples/client/petstore/qt5cpp/client/SWGHelpers.h b/samples/client/petstore/qt5cpp/client/SWGHelpers.h index 13a33c9c3383..bf721a6a1b9f 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.h +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.h @@ -18,8 +18,9 @@ namespace Swagger { void setValue(void* value, QJsonValue obj, QString type, QString complexType); - void toJsonArray(QList* value, QJsonArray* 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/SWGOrder.cpp b/samples/client/petstore/qt5cpp/client/SWGOrder.cpp index af011bd0e607..42e8891a9bf2 100644 --- a/samples/client/petstore/qt5cpp/client/SWGOrder.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGOrder.cpp @@ -56,10 +56,10 @@ SWGOrder::cleanup() { - if(ship_date != nullptr) { + if(ship_date != nullptr) { delete ship_date; } - if(status != nullptr) { + if(status != nullptr) { delete status; } @@ -77,11 +77,17 @@ SWGOrder::fromJson(QString &json) { void SWGOrder::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); + ::Swagger::setValue(&pet_id, pJson["petId"], "qint64", ""); + ::Swagger::setValue(&quantity, pJson["quantity"], "qint32", ""); + ::Swagger::setValue(&ship_date, pJson["shipDate"], "QDateTime", "QDateTime"); + ::Swagger::setValue(&status, pJson["status"], "QString", "QString"); + ::Swagger::setValue(&complete, pJson["complete"], "bool", ""); + } QString @@ -97,18 +103,27 @@ SWGOrder::asJson () QJsonObject* SWGOrder::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_id_isSet){ obj->insert("id", QJsonValue(id)); } + if(m_pet_id_isSet){ obj->insert("petId", QJsonValue(pet_id)); } + if(m_quantity_isSet){ obj->insert("quantity", QJsonValue(quantity)); } + + if(ship_date != nullptr) { + toJsonValue(QString("shipDate"), ship_date, obj, QString("QDateTime")); + } + if(status != nullptr && *status != QString("")){ toJsonValue(QString("status"), status, obj, QString("QString")); } + if(m_complete_isSet){ obj->insert("complete", QJsonValue(complete)); } diff --git a/samples/client/petstore/qt5cpp/client/SWGPet.cpp b/samples/client/petstore/qt5cpp/client/SWGPet.cpp index c4c7a72fda3a..a57cfdbc8d39 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPet.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGPet.cpp @@ -54,27 +54,27 @@ SWGPet::init() { void SWGPet::cleanup() { - if(category != nullptr) { + if(category != nullptr) { delete category; } - if(name != nullptr) { + if(name != nullptr) { delete name; } - if(photo_urls != nullptr) { - QList* arr = photo_urls; - foreach(QString* o, *arr) { + if(photo_urls != nullptr) { + auto arr = photo_urls; + for(auto o: *arr) { delete o; } delete photo_urls; } - if(tags != nullptr) { - QList* arr = tags; - foreach(SWGTag* o, *arr) { + if(tags != nullptr) { + auto arr = tags; + for(auto o: *arr) { delete o; } delete tags; } - if(status != nullptr) { + if(status != nullptr) { delete status; } } @@ -91,11 +91,17 @@ SWGPet::fromJson(QString &json) { void SWGPet::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); + ::Swagger::setValue(&category, pJson["category"], "SWGCategory", "SWGCategory"); + ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); + + ::Swagger::setValue(&photo_urls, pJson["photoUrls"], "QList", "QString"); + ::Swagger::setValue(&tags, pJson["tags"], "QList", "SWGTag"); ::Swagger::setValue(&status, pJson["status"], "QString", "QString"); + } QString @@ -111,25 +117,27 @@ SWGPet::asJson () QJsonObject* SWGPet::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_id_isSet){ obj->insert("id", QJsonValue(id)); } + if(category->isSet()){ toJsonValue(QString("category"), category, obj, QString("SWGCategory")); } + if(name != nullptr && *name != QString("")){ toJsonValue(QString("name"), name, obj, QString("QString")); } + if(photo_urls->size() > 0){ - QJsonArray photo_urlsJsonArray; - toJsonArray((QList*)photo_urls, &photo_urlsJsonArray, "photo_urls", "QString"); - obj->insert("photoUrls", photo_urlsJsonArray); + toJsonArray((QList*)photo_urls, obj, "photoUrls", "QString"); } + if(tags->size() > 0){ - QJsonArray tagsJsonArray; - toJsonArray((QList*)tags, &tagsJsonArray, "tags", "SWGTag"); - obj->insert("tags", tagsJsonArray); + toJsonArray((QList*)tags, obj, "tags", "SWGTag"); } + if(status != nullptr && *status != QString("")){ toJsonValue(QString("status"), status, obj, QString("QString")); } diff --git a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp index dc2afc379191..ece4311aa086 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp @@ -29,7 +29,7 @@ SWGPetApi::SWGPetApi(QString host, QString basePath) { } void -SWGPetApi::addPet(SWGPet body) { +SWGPetApi::addPet(SWGPet& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/pet"); @@ -401,7 +401,7 @@ SWGPetApi::getPetByIdCallback(SWGHttpRequestWorker * worker) { } void -SWGPetApi::updatePet(SWGPet body) { +SWGPetApi::updatePet(SWGPet& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/pet"); diff --git a/samples/client/petstore/qt5cpp/client/SWGPetApi.h b/samples/client/petstore/qt5cpp/client/SWGPetApi.h index 33c7ce0aff2f..ad40b90a8794 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPetApi.h +++ b/samples/client/petstore/qt5cpp/client/SWGPetApi.h @@ -36,12 +36,12 @@ class SWGPetApi: public QObject { QString basePath; QMap defaultHeaders; - void addPet(SWGPet body); + void addPet(SWGPet& body); void deletePet(qint64 pet_id, QString* api_key); void findPetsByStatus(QList* status); void findPetsByTags(QList* tags); void getPetById(qint64 pet_id); - void updatePet(SWGPet body); + void updatePet(SWGPet& body); void updatePetWithForm(qint64 pet_id, QString* name, QString* status); void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file); diff --git a/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp b/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp index 94b9f2292c3b..15b13dc26a43 100644 --- a/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGStoreApi.cpp @@ -198,7 +198,7 @@ SWGStoreApi::getOrderByIdCallback(SWGHttpRequestWorker * worker) { } void -SWGStoreApi::placeOrder(SWGOrder body) { +SWGStoreApi::placeOrder(SWGOrder& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/store/order"); diff --git a/samples/client/petstore/qt5cpp/client/SWGStoreApi.h b/samples/client/petstore/qt5cpp/client/SWGStoreApi.h index 8984eb6ceae8..c6d9acc5a26e 100644 --- a/samples/client/petstore/qt5cpp/client/SWGStoreApi.h +++ b/samples/client/petstore/qt5cpp/client/SWGStoreApi.h @@ -38,7 +38,7 @@ class SWGStoreApi: public QObject { void deleteOrder(QString* order_id); void getInventory(); void getOrderById(qint64 order_id); - void placeOrder(SWGOrder body); + void placeOrder(SWGOrder& body); private: void deleteOrderCallback (SWGHttpRequestWorker * worker); diff --git a/samples/client/petstore/qt5cpp/client/SWGTag.cpp b/samples/client/petstore/qt5cpp/client/SWGTag.cpp index 2d11260cd605..36cf43fd3454 100644 --- a/samples/client/petstore/qt5cpp/client/SWGTag.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGTag.cpp @@ -46,7 +46,7 @@ SWGTag::init() { void SWGTag::cleanup() { - if(name != nullptr) { + if(name != nullptr) { delete name; } } @@ -63,7 +63,9 @@ SWGTag::fromJson(QString &json) { void SWGTag::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); + ::Swagger::setValue(&name, pJson["name"], "QString", "QString"); + } QString @@ -79,9 +81,11 @@ SWGTag::asJson () QJsonObject* SWGTag::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_id_isSet){ 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/SWGUser.cpp b/samples/client/petstore/qt5cpp/client/SWGUser.cpp index 4031a959b686..e3781b931722 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUser.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGUser.cpp @@ -58,22 +58,22 @@ SWGUser::init() { void SWGUser::cleanup() { - if(username != nullptr) { + if(username != nullptr) { delete username; } - if(first_name != nullptr) { + if(first_name != nullptr) { delete first_name; } - if(last_name != nullptr) { + if(last_name != nullptr) { delete last_name; } - if(email != nullptr) { + if(email != nullptr) { delete email; } - if(password != nullptr) { + if(password != nullptr) { delete password; } - if(phone != nullptr) { + if(phone != nullptr) { delete phone; } @@ -91,13 +91,21 @@ SWGUser::fromJson(QString &json) { void SWGUser::fromJsonObject(QJsonObject &pJson) { ::Swagger::setValue(&id, pJson["id"], "qint64", ""); + ::Swagger::setValue(&username, pJson["username"], "QString", "QString"); + ::Swagger::setValue(&first_name, pJson["firstName"], "QString", "QString"); + ::Swagger::setValue(&last_name, pJson["lastName"], "QString", "QString"); + ::Swagger::setValue(&email, pJson["email"], "QString", "QString"); + ::Swagger::setValue(&password, pJson["password"], "QString", "QString"); + ::Swagger::setValue(&phone, pJson["phone"], "QString", "QString"); + ::Swagger::setValue(&user_status, pJson["userStatus"], "qint32", ""); + } QString @@ -113,27 +121,35 @@ SWGUser::asJson () QJsonObject* SWGUser::asJsonObject() { QJsonObject* obj = new QJsonObject(); + if(m_id_isSet){ obj->insert("id", QJsonValue(id)); } + if(username != nullptr && *username != QString("")){ toJsonValue(QString("username"), username, obj, QString("QString")); } + if(first_name != nullptr && *first_name != QString("")){ toJsonValue(QString("firstName"), first_name, obj, QString("QString")); } + if(last_name != nullptr && *last_name != QString("")){ toJsonValue(QString("lastName"), last_name, obj, QString("QString")); } + if(email != nullptr && *email != QString("")){ toJsonValue(QString("email"), email, obj, QString("QString")); } + if(password != nullptr && *password != QString("")){ toJsonValue(QString("password"), password, obj, QString("QString")); } + if(phone != nullptr && *phone != QString("")){ toJsonValue(QString("phone"), phone, obj, QString("QString")); } + if(m_user_status_isSet){ obj->insert("userStatus", QJsonValue(user_status)); } diff --git a/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp b/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp index bface16c256a..a990b898dbb0 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGUserApi.cpp @@ -29,7 +29,7 @@ SWGUserApi::SWGUserApi(QString host, QString basePath) { } void -SWGUserApi::createUser(SWGUser body) { +SWGUserApi::createUser(SWGUser& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/user"); @@ -81,7 +81,7 @@ SWGUserApi::createUserCallback(SWGHttpRequestWorker * worker) { } void -SWGUserApi::createUsersWithArrayInput(QList* body) { +SWGUserApi::createUsersWithArrayInput(QList*& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/user/createWithArray"); @@ -91,10 +91,10 @@ SWGUserApi::createUsersWithArrayInput(QList* body) { SWGHttpRequestInput input(fullPath, "POST"); - QJsonArray* bodyArray = new QJsonArray(); - toJsonArray((QList*)body, bodyArray, QString("body"), QString("SWGUser*")); + auto body_jobj = new QJsonObject(); + toJsonArray((QList*)body, body_jobj, QString("body"), QString("SWGUser*")); - QJsonDocument doc(*bodyArray); + QJsonDocument doc(*body_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -137,7 +137,7 @@ SWGUserApi::createUsersWithArrayInputCallback(SWGHttpRequestWorker * worker) { } void -SWGUserApi::createUsersWithListInput(QList* body) { +SWGUserApi::createUsersWithListInput(QList*& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/user/createWithList"); @@ -147,10 +147,10 @@ SWGUserApi::createUsersWithListInput(QList* body) { SWGHttpRequestInput input(fullPath, "POST"); - QJsonArray* bodyArray = new QJsonArray(); - toJsonArray((QList*)body, bodyArray, QString("body"), QString("SWGUser*")); + auto body_jobj = new QJsonObject(); + toJsonArray((QList*)body, body_jobj, QString("body"), QString("SWGUser*")); - QJsonDocument doc(*bodyArray); + QJsonDocument doc(*body_jobj); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -419,7 +419,7 @@ SWGUserApi::logoutUserCallback(SWGHttpRequestWorker * worker) { } void -SWGUserApi::updateUser(QString* username, SWGUser body) { +SWGUserApi::updateUser(QString* username, SWGUser& body) { QString fullPath; fullPath.append(this->host).append(this->basePath).append("/user/{username}"); diff --git a/samples/client/petstore/qt5cpp/client/SWGUserApi.h b/samples/client/petstore/qt5cpp/client/SWGUserApi.h index c24d062361b4..a667e85dee74 100644 --- a/samples/client/petstore/qt5cpp/client/SWGUserApi.h +++ b/samples/client/petstore/qt5cpp/client/SWGUserApi.h @@ -35,14 +35,14 @@ class SWGUserApi: public QObject { QString basePath; QMap defaultHeaders; - void createUser(SWGUser body); - void createUsersWithArrayInput(QList* body); - void createUsersWithListInput(QList* body); + void createUser(SWGUser& body); + void createUsersWithArrayInput(QList*& body); + void createUsersWithListInput(QList*& body); void deleteUser(QString* username); void getUserByName(QString* username); void loginUser(QString* username, QString* password); void logoutUser(); - void updateUser(QString* username, SWGUser body); + void updateUser(QString* username, SWGUser& body); private: void createUserCallback (SWGHttpRequestWorker * worker);