Qt5cpp Add support for nested containers (#7340)

* Disable creation of empty json fields and fields for primitives which were not set, but using default values
modelnamePrefix will be the one passed from command line or SWG if none

* Updates after review
Also common http files are splitted
Update Petstore examples

* Small Fixes for cleaning up arrays of arrays/maps

* Changes
- Api Body pass by Reference, avoid seg fault due to deletion of auto constructed object passed as parameter.
- Support Maps and Arrays upto a depth of 2
- Refactor Helpers to handle Maps and simplify code

* Remove size check due to possible incorrect type

* Update PetStore Examples for Qt5 C++ and small fixes for QDate/QDateTime

* Updates after review. Fixes typo and remove usage of auto keyword.

* Restored usage of auto keyword.
This commit is contained in:
etherealjoy 2018-01-14 10:47:54 +01:00 committed by William Cheng
parent 809e1f4c93
commit 0bf430a803
20 changed files with 701 additions and 262 deletions

View File

@ -22,7 +22,7 @@ namespace {{this}} {
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
void void
{{classname}}::{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { {{classname}}::{{nickname}}({{#allParams}}{{{dataType}}}{{#isBodyParam}}&{{/isBodyParam}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("{{{path}}}"); fullPath.append(this->host).append(this->basePath).append("{{{path}}}");
@ -98,17 +98,17 @@ void
{{#bodyParams}} {{#bodyParams}}
{{#isContainer}} {{#isContainer}}
QJsonArray* {{paramName}}Array = new QJsonArray(); auto {{paramName}}_jobj = new QJsonObject();
toJsonArray((QList<void*>*){{paramName}}, {{paramName}}Array, QString("body"), QString("{{prefix}}User*")); toJsonArray((QList<void*>*){{paramName}}, {{paramName}}_jobj, QString("body"), QString("{{prefix}}User*"));
QJsonDocument doc(*{{paramName}}Array); QJsonDocument doc(*{{paramName}}_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
{{/isContainer}} {{/isContainer}}
{{^isContainer}}{{#isString}} {{^isContainer}}{{#isString}}
QString output(*{{paramName}});{{/isString}}{{^isString}} QString output(*{{paramName}});{{/isString}}{{#isByteArray}}QString output(*{{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}}
QString output = {{paramName}}.asJson();{{/isString}} QString output = {{paramName}}.asJson();{{/isByteArray}}{{/isString}}
input.request_body.append(output); input.request_body.append(output);
{{/isContainer}}{{/bodyParams}} {{/isContainer}}{{/bodyParams}}

View File

@ -25,7 +25,7 @@ public:
QString basePath; QString basePath;
QMap<QString, QString> defaultHeaders; QMap<QString, QString> 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}} {{/operation}}{{/operations}}
private: private:
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker); {{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);

View File

@ -40,17 +40,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
else if (QStringLiteral("QString").compare(type) == 0) { else if (QStringLiteral("QString").compare(type) == 0) {
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 // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QString(obj.toString()); *val = new QString(obj.toString());
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -64,13 +63,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -84,13 +83,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -104,14 +103,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString()))); *val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString())));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -122,124 +121,253 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
else if(type.startsWith("{{prefix}}") && obj.isObject()) { else if(type.startsWith("{{prefix}}") && obj.isObject()) {
// complex type // complex type
QJsonObject jsonObj = obj.toObject(); QJsonObject jsonObj = obj.toObject();
{{prefix}}Object * so = ({{prefix}}Object*)::{{cppNamespace}}::create(type); {{prefix}}Object * so = ({{prefix}}Object*)::{{cppNamespace}}::create(complexType);
if(so != nullptr) { if(so != nullptr) {
so->fromJsonObject(jsonObj); so->fromJsonObject(jsonObj);
{{prefix}}Object **val = static_cast<{{prefix}}Object**>(value); {{prefix}}Object **val = static_cast<{{prefix}}Object**>(value);
delete *val; if(*val != nullptr) delete *val;
*val = so; *val = so;
} }
} }
else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) {
// list of values // list of values
if(complexType.startsWith("{{prefix}}")) { if(complexType.startsWith("{{prefix}}")) {
QList<{{prefix}}Object*>* output = new QList<{{prefix}}Object*>(); auto output = reinterpret_cast<QList<{{prefix}}Object *> **> (value);
for (auto item : **output) {
if(item != nullptr) delete item;
}
(*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr) { for (const QJsonValue & jval : arr) {
// it's an object // it's an object
{{prefix}}Object * val = ({{prefix}}Object*)create(complexType); {{prefix}}Object * val = ({{prefix}}Object*)::{{cppNamespace}}::create(complexType);
QJsonObject t = jval.toObject(); QJsonObject t = jval.toObject();
val->fromJsonObject(t); val->fromJsonObject(t);
output->append(val); (*output)->append(val);
} }
QList<{{prefix}}Object*> **val = static_cast<QList<{{prefix}}Object*>**>(value);
for (auto item : **val) {
delete item;
}
delete *val;
*val = output;
} }
else if(QStringLiteral("qint32").compare(complexType) == 0) { else if(QStringLiteral("qint32").compare(complexType) == 0) {
QList<qint32> **output = reinterpret_cast<QList<qint32> **> (value); auto output = reinterpret_cast<QList<qint32> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
qint32 val; qint32 val;
setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("qint64").compare(complexType) == 0) { else if(QStringLiteral("qint64").compare(complexType) == 0) {
QList<qint64> **output = reinterpret_cast<QList<qint64> **> (value); auto output = reinterpret_cast<QList<qint64> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
qint64 val; qint64 val;
setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("bool").compare(complexType) == 0) { else if(QStringLiteral("bool").compare(complexType) == 0) {
QList<bool> **output = reinterpret_cast<QList<bool> **> (value); auto output = reinterpret_cast<QList<bool> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
bool val; bool val;
setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("bool"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("float").compare(complexType) == 0) { else if(QStringLiteral("float").compare(complexType) == 0) {
QList<float> **output = reinterpret_cast<QList<float> **> (value); auto output = reinterpret_cast<QList<float> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
float val; float val;
setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("float"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("double").compare(complexType) == 0) { else if(QStringLiteral("double").compare(complexType) == 0) {
QList<double> **output = reinterpret_cast<QList<double> **> (value); auto output = reinterpret_cast<QList<double> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
double val; double val;
setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("double"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QString").compare(complexType) == 0) { else if(QStringLiteral("QString").compare(complexType) == 0) {
QList<QString*> **output = reinterpret_cast<QList<QString*> **> (value); auto output = reinterpret_cast<QList<QString*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QString * val = new QString(); QString * val = new QString();
setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QString"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QDate").compare(complexType) == 0) { else if(QStringLiteral("QDate").compare(complexType) == 0) {
QList<QDate*> **output = reinterpret_cast<QList<QDate*> **> (value); auto output = reinterpret_cast<QList<QDate*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QDate * val = new QDate(); QDate * val = new QDate();
setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QDateTime").compare(complexType) == 0) { else if(QStringLiteral("QDateTime").compare(complexType) == 0) {
QList<QDateTime*> **output = reinterpret_cast<QList<QDateTime*> **> (value); auto output = reinterpret_cast<QList<QDateTime*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QDateTime * val = new QDateTime(); QDateTime * val = new QDateTime();
setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); ::{{cppNamespace}}::setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral(""));
(*output)->push_back(val); (*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<QMap<QString, {{prefix}}Object*> **> (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<QMap<QString, qint32> **> (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<QMap<QString, qint64> **> (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<QMap<QString, bool> **> (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<QMap<QString, float> **> (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<QMap<QString, double> **> (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<QMap<QString, QString*> **> (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<QMap<QString, QDate*> **> (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<QMap<QString, QDateTime*> **> (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 void
@ -253,7 +381,7 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) {
QJsonObject* o = (*{{prefix}}object).asJsonObject(); QJsonObject* o = (*{{prefix}}object).asJsonObject();
if(name != nullptr) { if(name != nullptr) {
output->insert(name, *o); output->insert(name, *o);
delete o; if(o != nullptr) delete o;
} }
else { else {
output->empty(); output->empty();
@ -302,54 +430,133 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) {
} }
void void
toJsonArray(QList<void*>* value, QJsonArray* output, QString innerName, QString innerType) { toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) {
return;
}
QJsonArray outputarray;
if(innerType.startsWith("{{prefix}}")){ if(innerType.startsWith("{{prefix}}")){
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) {
output->append(*({{prefix}}object->asJsonObject())); outputarray.append(*({{prefix}}object->asJsonObject()));
} }
} }
} }
else if(QStringLiteral("QString").compare(innerType) == 0) { else if(QStringLiteral("QString").compare(innerType) == 0) {
for(QString* obj : *(reinterpret_cast<QList<QString*>*>(value))){ for(QString* obj : *(reinterpret_cast<QList<QString*>*>(value))){
output->append(QJsonValue(*obj)); outputarray.append(QJsonValue(*obj));
} }
} }
else if(QStringLiteral("QDate").compare(innerType) == 0) { else if(QStringLiteral("QDate").compare(innerType) == 0) {
for(QDate* obj : *(reinterpret_cast<QList<QDate*>*>(value))){ for(QDate* obj : *(reinterpret_cast<QList<QDate*>*>(value))){
output->append(QJsonValue(obj->toString(Qt::ISODate))); outputarray.append(QJsonValue(obj->toString(Qt::ISODate)));
} }
} }
else if(QStringLiteral("QDateTime").compare(innerType) == 0) { else if(QStringLiteral("QDateTime").compare(innerType) == 0) {
for(QDateTime* obj : *(reinterpret_cast<QList<QDateTime*>*>(value))){ for(QDateTime* obj : *(reinterpret_cast<QList<QDateTime*>*>(value))){
output->append(QJsonValue(obj->toString(Qt::ISODate))); } outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); }
} }
else if(QStringLiteral("QByteArray").compare(innerType) == 0) { else if(QStringLiteral("QByteArray").compare(innerType) == 0) {
for(QByteArray* obj : *(reinterpret_cast<QList<QByteArray*>*>(value))){ for(QByteArray* obj : *(reinterpret_cast<QList<QByteArray*>*>(value))){
output->append(QJsonValue(QString(obj->toBase64()))); outputarray.append(QJsonValue(QString(obj->toBase64())));
} }
} }
else if(QStringLiteral("qint32").compare(innerType) == 0) { else if(QStringLiteral("qint32").compare(innerType) == 0) {
for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value))) for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("qint64").compare(innerType) == 0) { else if(QStringLiteral("qint64").compare(innerType) == 0) {
for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value))) for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("bool").compare(innerType) == 0) { else if(QStringLiteral("bool").compare(innerType) == 0) {
for(bool obj : *(reinterpret_cast<QList<bool>*>(value))) for(bool obj : *(reinterpret_cast<QList<bool>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("float").compare(innerType) == 0) { else if(QStringLiteral("float").compare(innerType) == 0) {
for(float obj : *(reinterpret_cast<QList<float>*>(value))) for(float obj : *(reinterpret_cast<QList<float>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("double").compare(innerType) == 0) { else if(QStringLiteral("double").compare(innerType) == 0) {
for(double obj : *(reinterpret_cast<QList<double>*>(value))) for(double obj : *(reinterpret_cast<QList<double>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
output->insert(innerName, outputarray);
}
void
toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) {
return;
}
QJsonObject mapobj;
if(innerType.startsWith("{{prefix}}")){
auto items = reinterpret_cast< QMap<QString, {{prefix}}Object*> *>(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<QString, QString*> *>(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<QString, QDate*> *>(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<QString, QDateTime*> *>(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<QString, QByteArray*> *>(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<QString, qint32> *>(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<QString, qint64> *>(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<QString, bool> *>(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<QString, float> *>(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<QString, double> *>(value);
for(auto itemkey: items->keys() ) {
auto val = items->value(itemkey);
::{{cppNamespace}}::toJsonValue(itemkey, &val, &mapobj, innerType);
}
}
output->insert(innerName, mapobj);
} }
QString QString

View File

@ -9,8 +9,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, QJsonArray* 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);
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

@ -38,12 +38,15 @@ void
{{classname}}::cleanup() { {{classname}}::cleanup() {
{{#vars}} {{#vars}}
{{#complexType}} {{#complexType}}
if({{name}} != nullptr) { if({{name}} != nullptr) { {{#isContainer}}
{{#isContainer}}{{#isListContainer}}QList<{{complexType}}*>* arr = {{name}};{{/isListContainer}}{{#isMapContainer}}QMap<QString, {{complexType}}*>* arr = {{name}};{{/isMapContainer}} auto arr = {{name}};
foreach({{complexType}}* o, *arr) { for(auto o: *arr) { {{#items.isContainer}}
for(auto o1: *o) {
delete o1;
}{{/items.isContainer}}
delete o; delete o;
} }{{/isContainer}}
{{/isContainer}}delete {{name}}; delete {{name}};
}{{/complexType}} }{{/complexType}}
{{/vars}} {{/vars}}
} }
@ -60,33 +63,30 @@ void
void void
{{classname}}::fromJsonObject(QJsonObject &pJson) { {{classname}}::fromJsonObject(QJsonObject &pJson) {
{{#vars}} {{#vars}}
{{^isContainer}} {{^isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}");{{/isContainer}}
::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}"); {{#isContainer}}{{^items.isContainer}}::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}");{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
{{/isContainer}} if(pJson["{{baseName}}"].isArray()){
{{#isListContainer}} auto arr = pJson["{{baseName}}"].toArray();
{{#complexType}} for (const QJsonValue & jval : arr) {
::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{complexType}}"); {{#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}}
{{/complexType}} {{#items.isMapContainer}}auto {{name}}_item = new QMap<QString, {{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.isMapContainer}}
{{^complexType}} auto jsonval = jval.toObject();
::{{cppNamespace}}::setValue(&{{name}}, pJson["{{baseName}}"], "{{baseType}}", "{{items.baseType}}"); ::{{cppNamespace}}::setValue({{name}}_item, jsonval, "{{items.baseType}}", "{{items.items.baseType}}");
{{/complexType}} {{name}}->push_back({{name}}_item);
{{/isListContainer}} }
{{#isMapContainer}} }{{/isListContainer}}{{#isMapContainer}}
if( pJson["{{baseName}}"].isObject()){ if(pJson["{{baseName}}"].isObject()){
auto varmap = pJson["{{baseName}}"].toObject().toVariantMap(); auto varmap = pJson["{{baseName}}"].toObject().toVariantMap();
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto val : varmap.keys() ){ 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.baseType}} *{{name}}_item = new {{items.baseType}}(); {{#items.isMapContainer}}auto {{name}}_item = new QMap<QString, {{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.isMapContainer}}
auto jsonval = QJsonValue::fromVariant(varmap[val]); auto jsonval = QJsonValue::fromVariant(varmap.value(val));
::{{cppNamespace}}::setValue(&{{name}}_item, jsonval, "{{items.baseType}}", "{{items.baseType}}"); ::{{cppNamespace}}::setValue((QMap<QString, void *>*)&{{name}}_item, jsonval, "{{items.baseType}}", "{{items.items.baseType}}");
{{name}}->insert({{name}}->end(), val, {{name}}_item); {{name}}->insert({{name}}->end(), val, {{name}}_item);
}
} }
} }
} }{{/isMapContainer}}{{/items.isContainer}}{{/isContainer}}
{{/isMapContainer}}
{{/vars}} {{/vars}}
} }
@ -104,77 +104,47 @@ QJsonObject*
{{classname}}::asJsonObject() { {{classname}}::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
{{#vars}} {{#vars}}
{{#complexType}} {{^isContainer}}{{#complexType}}{{^isString}}{{^isDate}}{{^isDateTime}}{{^isByteArray}}
{{^isContainer}}
{{#complexType}}
{{^isString}}
{{^isDateTime}}
if({{name}}->isSet()){ if({{name}}->isSet()){
toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
} }{{/isByteArray}}{{/isDateTime}}{{/isDate}}{{/isString}}{{#isString}}
{{/isDateTime}}
{{/isString}}
{{#isString}}
if({{name}} != nullptr && *{{name}} != QString("")){ if({{name}} != nullptr && *{{name}} != QString("")){
toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}")); toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
} }{{/isString}}{{/complexType}}{{#isPrimitiveType}}{{^isDateTime}}{{^isDate}}{{^isByteArray}}
{{/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<void*>*){{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}}
if(m_{{name}}_isSet){ if(m_{{name}}_isSet){
obj->insert("{{baseName}}", QJsonValue({{name}})); obj->insert("{{baseName}}", QJsonValue({{name}}));
} }{{/isByteArray}}{{/isDate}}{{/isDateTime}}{{/isPrimitiveType}}{{#isDate}}
{{/isDateTime}} if({{name}} != nullptr) {
{{/isString}} toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
{{#isString}} }{{/isDate}}{{#isByteArray}}
if({{name}} != nullptr && *{{name}} != QString("")) { if({{name}} != nullptr) {
obj->insert("{{name}}", QJsonValue(*{{name}})); obj->insert("{{name}}", QJsonValue(*{{name}}));
} }{{/isByteArray}}{{#isDateTime}}
{{/isString}} if({{name}} != nullptr) {
{{/isContainer}} toJsonValue(QString("{{baseName}}"), {{name}}, obj, QString("{{complexType}}"));
{{#isListContainer}} }{{/isDateTime}}{{/isContainer}}{{#isContainer}}{{#isListContainer}}
if({{name}}->size() > 0){ if({{name}}->size() > 0){
QJsonArray {{name}}JsonArray; {{^items.isContainer}}toJsonArray((QList<void*>*){{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}}
toJsonArray((QList<void*>*){{name}}, &{{name}}JsonArray, "{{name}}", "{{items.baseType}}"); QJsonArray jarray;
obj->insert("{{baseName}}", {{name}}JsonArray); for(auto items : *{{name}}){
} QJsonObject jobj;
{{/isListContainer}} {{#items.isListContainer}}toJsonArray((QList<void*>*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}");{{/items.isListContainer}}
{{#isMapContainer}} {{#items.isMapContainer}}toJsonMap((QMap<QString, void*>*)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){ if({{name}}->size() > 0){
QJsonObject {{name}}_jobj; {{^items.isContainer}}toJsonMap((QMap<QString, void*>*) {{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}}
for(auto keyval : {{name}}->keys()){ QJsonObject mapobj;
toJsonValue(keyval, ((*{{name}})[keyval]), &{{name}}_jobj, "{{items.baseType}}"); for(auto itemkey : {{name}}->keys()){
} QJsonObject jobj;
obj->insert("{{baseName}}", {{name}}_jobj); {{#items.isListContainer}}toJsonArray((QList<void*>*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}");{{/items.isListContainer}}
} {{#items.isMapContainer}}toJsonMap((QMap<QString, void*>*){{name}}->value(itemkey), &jobj, itemkey, "{{items.items.baseType}}");{{/items.isMapContainer}}
{{/isMapContainer}} mapobj.insert(itemkey, jobj);
{{/complexType}} }
obj->insert("{{baseName}}", mapobj);{{/items.isContainer}}
}{{/isMapContainer}}{{/isContainer}}
{{/vars}} {{/vars}}
return obj; return obj;

View File

@ -18,31 +18,31 @@ TEMPLATE = app
SOURCES += main.cpp \ SOURCES += main.cpp \
../client/Category.cpp \ ../client/SWGCategory.cpp \
../client/SWGHelpers.cpp \ ../client/SWGHelpers.cpp \
../client/SWGHttpRequest.cpp \ ../client/SWGHttpRequest.cpp \
../client/Order.cpp \ ../client/SWGOrder.cpp \
../client/Pet.cpp \ ../client/SWGPet.cpp \
../client/SWGPetApi.cpp \ ../client/SWGPetApi.cpp \
../client/SWGStoreApi.cpp \ ../client/SWGStoreApi.cpp \
../client/Tag.cpp \ ../client/SWGTag.cpp \
../client/User.cpp \ ../client/SWGUser.cpp \
../client/SWGUserApi.cpp \ ../client/SWGUserApi.cpp \
../client/ApiResponse.cpp \ ../client/SWGApiResponse.cpp \
PetApiTests.cpp PetApiTests.cpp
HEADERS += \ HEADERS += \
../client/Category.h \ ../client/SWGCategory.h \
../client/SWGHelpers.h \ ../client/SWGHelpers.h \
../client/SWGHttpRequest.h \ ../client/SWGHttpRequest.h \
../client/SWGObject.h \ ../client/SWGObject.h \
../client/Order.h \ ../client/SWGOrder.h \
../client/Pet.h \ ../client/SWGPet.h \
../client/SWGPetApi.h \ ../client/SWGPetApi.h \
../client/SWGStoreApi.h \ ../client/SWGStoreApi.h \
../client/Tag.h \ ../client/SWGTag.h \
../client/User.h \ ../client/SWGUser.h \
../client/SWGUserApi.h \ ../client/SWGUserApi.h \
PetApiTests.h \ PetApiTests.h \
../client/ApiResponse.h \ ../client/SWGApiResponse.h \
../client/SWGModelFactory.h ../client/SWGModelFactory.h

View File

@ -48,10 +48,10 @@ SWGApiResponse::init() {
void void
SWGApiResponse::cleanup() { SWGApiResponse::cleanup() {
if(type != nullptr) { if(type != nullptr) {
delete type; delete type;
} }
if(message != nullptr) { if(message != nullptr) {
delete message; delete message;
} }
} }
@ -68,8 +68,11 @@ 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");
::Swagger::setValue(&message, pJson["message"], "QString", "QString"); ::Swagger::setValue(&message, pJson["message"], "QString", "QString");
} }
QString QString
@ -85,12 +88,15 @@ SWGApiResponse::asJson ()
QJsonObject* QJsonObject*
SWGApiResponse::asJsonObject() { SWGApiResponse::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
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"));
} }
if(message != nullptr && *message != QString("")){ if(message != nullptr && *message != QString("")){
toJsonValue(QString("message"), message, obj, QString("QString")); toJsonValue(QString("message"), message, obj, QString("QString"));
} }

View File

@ -46,7 +46,7 @@ SWGCategory::init() {
void void
SWGCategory::cleanup() { SWGCategory::cleanup() {
if(name != nullptr) { if(name != nullptr) {
delete name; delete name;
} }
} }
@ -63,7 +63,9 @@ 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");
} }
QString QString
@ -79,9 +81,11 @@ SWGCategory::asJson ()
QJsonObject* QJsonObject*
SWGCategory::asJsonObject() { SWGCategory::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
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

@ -49,17 +49,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
} }
else if (QStringLiteral("QString").compare(type) == 0) { else if (QStringLiteral("QString").compare(type) == 0) {
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 // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QString(obj.toString()); *val = new QString(obj.toString());
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -73,13 +72,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -93,13 +92,13 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -113,14 +112,14 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
if(val != nullptr) { if(val != nullptr) {
if(!obj.isNull()) { if(!obj.isNull()) {
// create a new value and return // create a new value and return
delete *val; if(*val != nullptr) delete *val;
*val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString()))); *val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString())));
return; return;
} }
else { else {
// set target to nullptr // set target to nullptr
delete *val; if(*val != nullptr) delete *val;
*val = nullptr; *val = nullptr;
} }
} }
@ -131,124 +130,253 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
else if(type.startsWith("SWG") && obj.isObject()) { else if(type.startsWith("SWG") && obj.isObject()) {
// complex type // complex type
QJsonObject jsonObj = obj.toObject(); QJsonObject jsonObj = obj.toObject();
SWGObject * so = (SWGObject*)::Swagger::create(type); SWGObject * so = (SWGObject*)::Swagger::create(complexType);
if(so != nullptr) { if(so != nullptr) {
so->fromJsonObject(jsonObj); so->fromJsonObject(jsonObj);
SWGObject **val = static_cast<SWGObject**>(value); SWGObject **val = static_cast<SWGObject**>(value);
delete *val; if(*val != nullptr) delete *val;
*val = so; *val = so;
} }
} }
else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) {
// list of values // list of values
if(complexType.startsWith("SWG")) { if(complexType.startsWith("SWG")) {
QList<SWGObject*>* output = new QList<SWGObject*>(); auto output = reinterpret_cast<QList<SWGObject *> **> (value);
for (auto item : **output) {
if(item != nullptr) delete item;
}
(*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr) { for (const QJsonValue & jval : arr) {
// it's an object // it's an object
SWGObject * val = (SWGObject*)create(complexType); SWGObject * val = (SWGObject*)::Swagger::create(complexType);
QJsonObject t = jval.toObject(); QJsonObject t = jval.toObject();
val->fromJsonObject(t); val->fromJsonObject(t);
output->append(val); (*output)->append(val);
} }
QList<SWGObject*> **val = static_cast<QList<SWGObject*>**>(value);
for (auto item : **val) {
delete item;
}
delete *val;
*val = output;
} }
else if(QStringLiteral("qint32").compare(complexType) == 0) { else if(QStringLiteral("qint32").compare(complexType) == 0) {
QList<qint32> **output = reinterpret_cast<QList<qint32> **> (value); auto output = reinterpret_cast<QList<qint32> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
qint32 val; qint32 val;
setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("qint64").compare(complexType) == 0) { else if(QStringLiteral("qint64").compare(complexType) == 0) {
QList<qint64> **output = reinterpret_cast<QList<qint64> **> (value); auto output = reinterpret_cast<QList<qint64> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
qint64 val; qint64 val;
setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("bool").compare(complexType) == 0) { else if(QStringLiteral("bool").compare(complexType) == 0) {
QList<bool> **output = reinterpret_cast<QList<bool> **> (value); auto output = reinterpret_cast<QList<bool> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
bool val; bool val;
setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("bool"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("float").compare(complexType) == 0) { else if(QStringLiteral("float").compare(complexType) == 0) {
QList<float> **output = reinterpret_cast<QList<float> **> (value); auto output = reinterpret_cast<QList<float> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
float val; float val;
setValue(&val, jval, QStringLiteral("float"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("float"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("double").compare(complexType) == 0) { else if(QStringLiteral("double").compare(complexType) == 0) {
QList<double> **output = reinterpret_cast<QList<double> **> (value); auto output = reinterpret_cast<QList<double> **> (value);
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
double val; double val;
setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("double"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QString").compare(complexType) == 0) { else if(QStringLiteral("QString").compare(complexType) == 0) {
QList<QString*> **output = reinterpret_cast<QList<QString*> **> (value); auto output = reinterpret_cast<QList<QString*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QString * val = new QString(); QString * val = new QString();
setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("QString"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QDate").compare(complexType) == 0) { else if(QStringLiteral("QDate").compare(complexType) == 0) {
QList<QDate*> **output = reinterpret_cast<QList<QDate*> **> (value); auto output = reinterpret_cast<QList<QDate*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QDate * val = new QDate(); QDate * val = new QDate();
setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral(""));
(*output)->push_back(val); (*output)->push_back(val);
} }
} }
else if(QStringLiteral("QDateTime").compare(complexType) == 0) { else if(QStringLiteral("QDateTime").compare(complexType) == 0) {
QList<QDateTime*> **output = reinterpret_cast<QList<QDateTime*> **> (value); auto output = reinterpret_cast<QList<QDateTime*> **> (value);
for (auto item : **output) { for (auto item : **output) {
delete item; if(item != nullptr) delete item;
} }
(*output)->clear(); (*output)->clear();
QJsonArray arr = obj.toArray(); QJsonArray arr = obj.toArray();
for (const QJsonValue & jval : arr){ for (const QJsonValue & jval : arr){
QDateTime * val = new QDateTime(); QDateTime * val = new QDateTime();
setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); ::Swagger::setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral(""));
(*output)->push_back(val); (*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<QMap<QString, SWGObject*> **> (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<QMap<QString, qint32> **> (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<QMap<QString, qint64> **> (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<QMap<QString, bool> **> (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<QMap<QString, float> **> (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<QMap<QString, double> **> (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<QMap<QString, QString*> **> (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<QMap<QString, QDate*> **> (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<QMap<QString, QDateTime*> **> (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 void
@ -262,7 +390,7 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) {
QJsonObject* o = (*SWGobject).asJsonObject(); QJsonObject* o = (*SWGobject).asJsonObject();
if(name != nullptr) { if(name != nullptr) {
output->insert(name, *o); output->insert(name, *o);
delete o; if(o != nullptr) delete o;
} }
else { else {
output->empty(); output->empty();
@ -311,54 +439,133 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) {
} }
void void
toJsonArray(QList<void*>* value, QJsonArray* output, QString innerName, QString innerType) { toJsonArray(QList<void*>* value, QJsonObject* output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) {
return;
}
QJsonArray outputarray;
if(innerType.startsWith("SWG")){ if(innerType.startsWith("SWG")){
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) {
output->append(*(SWGobject->asJsonObject())); outputarray.append(*(SWGobject->asJsonObject()));
} }
} }
} }
else if(QStringLiteral("QString").compare(innerType) == 0) { else if(QStringLiteral("QString").compare(innerType) == 0) {
for(QString* obj : *(reinterpret_cast<QList<QString*>*>(value))){ for(QString* obj : *(reinterpret_cast<QList<QString*>*>(value))){
output->append(QJsonValue(*obj)); outputarray.append(QJsonValue(*obj));
} }
} }
else if(QStringLiteral("QDate").compare(innerType) == 0) { else if(QStringLiteral("QDate").compare(innerType) == 0) {
for(QDate* obj : *(reinterpret_cast<QList<QDate*>*>(value))){ for(QDate* obj : *(reinterpret_cast<QList<QDate*>*>(value))){
output->append(QJsonValue(obj->toString(Qt::ISODate))); outputarray.append(QJsonValue(obj->toString(Qt::ISODate)));
} }
} }
else if(QStringLiteral("QDateTime").compare(innerType) == 0) { else if(QStringLiteral("QDateTime").compare(innerType) == 0) {
for(QDateTime* obj : *(reinterpret_cast<QList<QDateTime*>*>(value))){ for(QDateTime* obj : *(reinterpret_cast<QList<QDateTime*>*>(value))){
output->append(QJsonValue(obj->toString(Qt::ISODate))); } outputarray.append(QJsonValue(obj->toString(Qt::ISODate))); }
} }
else if(QStringLiteral("QByteArray").compare(innerType) == 0) { else if(QStringLiteral("QByteArray").compare(innerType) == 0) {
for(QByteArray* obj : *(reinterpret_cast<QList<QByteArray*>*>(value))){ for(QByteArray* obj : *(reinterpret_cast<QList<QByteArray*>*>(value))){
output->append(QJsonValue(QString(obj->toBase64()))); outputarray.append(QJsonValue(QString(obj->toBase64())));
} }
} }
else if(QStringLiteral("qint32").compare(innerType) == 0) { else if(QStringLiteral("qint32").compare(innerType) == 0) {
for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value))) for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("qint64").compare(innerType) == 0) { else if(QStringLiteral("qint64").compare(innerType) == 0) {
for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value))) for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("bool").compare(innerType) == 0) { else if(QStringLiteral("bool").compare(innerType) == 0) {
for(bool obj : *(reinterpret_cast<QList<bool>*>(value))) for(bool obj : *(reinterpret_cast<QList<bool>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("float").compare(innerType) == 0) { else if(QStringLiteral("float").compare(innerType) == 0) {
for(float obj : *(reinterpret_cast<QList<float>*>(value))) for(float obj : *(reinterpret_cast<QList<float>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
else if(QStringLiteral("double").compare(innerType) == 0) { else if(QStringLiteral("double").compare(innerType) == 0) {
for(double obj : *(reinterpret_cast<QList<double>*>(value))) for(double obj : *(reinterpret_cast<QList<double>*>(value)))
output->append(QJsonValue(obj)); outputarray.append(QJsonValue(obj));
} }
output->insert(innerName, outputarray);
}
void
toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType) {
if((value == nullptr) || (output == nullptr)) {
return;
}
QJsonObject mapobj;
if(innerType.startsWith("SWG")){
auto items = reinterpret_cast< QMap<QString, SWGObject*> *>(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<QString, QString*> *>(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<QString, QDate*> *>(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<QString, QDateTime*> *>(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<QString, QByteArray*> *>(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<QString, qint32> *>(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<QString, qint64> *>(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<QString, bool> *>(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<QString, float> *>(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<QString, double> *>(value);
for(auto itemkey: items->keys() ) {
auto val = items->value(itemkey);
::Swagger::toJsonValue(itemkey, &val, &mapobj, innerType);
}
}
output->insert(innerName, mapobj);
} }
QString QString

View File

@ -18,8 +18,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, QJsonArray* 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);
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,10 +56,10 @@ SWGOrder::cleanup() {
if(ship_date != nullptr) { if(ship_date != nullptr) {
delete ship_date; delete ship_date;
} }
if(status != nullptr) { if(status != nullptr) {
delete status; delete status;
} }
@ -77,11 +77,17 @@ 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", "");
::Swagger::setValue(&quantity, pJson["quantity"], "qint32", ""); ::Swagger::setValue(&quantity, pJson["quantity"], "qint32", "");
::Swagger::setValue(&ship_date, pJson["shipDate"], "QDateTime", "QDateTime"); ::Swagger::setValue(&ship_date, pJson["shipDate"], "QDateTime", "QDateTime");
::Swagger::setValue(&status, pJson["status"], "QString", "QString"); ::Swagger::setValue(&status, pJson["status"], "QString", "QString");
::Swagger::setValue(&complete, pJson["complete"], "bool", ""); ::Swagger::setValue(&complete, pJson["complete"], "bool", "");
} }
QString QString
@ -97,18 +103,27 @@ SWGOrder::asJson ()
QJsonObject* QJsonObject*
SWGOrder::asJsonObject() { SWGOrder::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
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) {
toJsonValue(QString("shipDate"), ship_date, obj, QString("QDateTime"));
}
if(status != nullptr && *status != QString("")){ if(status != nullptr && *status != QString("")){
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));
} }

View File

@ -54,27 +54,27 @@ SWGPet::init() {
void void
SWGPet::cleanup() { SWGPet::cleanup() {
if(category != nullptr) { if(category != nullptr) {
delete category; delete category;
} }
if(name != nullptr) { if(name != nullptr) {
delete name; delete name;
} }
if(photo_urls != nullptr) { if(photo_urls != nullptr) {
QList<QString*>* arr = photo_urls; auto arr = photo_urls;
foreach(QString* o, *arr) { for(auto o: *arr) {
delete o; delete o;
} }
delete photo_urls; delete photo_urls;
} }
if(tags != nullptr) { if(tags != nullptr) {
QList<SWGTag*>* arr = tags; auto arr = tags;
foreach(SWGTag* o, *arr) { for(auto o: *arr) {
delete o; delete o;
} }
delete tags; delete tags;
} }
if(status != nullptr) { if(status != nullptr) {
delete status; delete status;
} }
} }
@ -91,11 +91,17 @@ 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");
::Swagger::setValue(&name, pJson["name"], "QString", "QString"); ::Swagger::setValue(&name, pJson["name"], "QString", "QString");
::Swagger::setValue(&photo_urls, pJson["photoUrls"], "QList", "QString"); ::Swagger::setValue(&photo_urls, pJson["photoUrls"], "QList", "QString");
::Swagger::setValue(&tags, pJson["tags"], "QList", "SWGTag"); ::Swagger::setValue(&tags, pJson["tags"], "QList", "SWGTag");
::Swagger::setValue(&status, pJson["status"], "QString", "QString"); ::Swagger::setValue(&status, pJson["status"], "QString", "QString");
} }
QString QString
@ -111,25 +117,27 @@ SWGPet::asJson ()
QJsonObject* QJsonObject*
SWGPet::asJsonObject() { SWGPet::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
if(m_id_isSet){ if(m_id_isSet){
obj->insert("id", QJsonValue(id)); obj->insert("id", QJsonValue(id));
} }
if(category->isSet()){ if(category->isSet()){
toJsonValue(QString("category"), category, obj, QString("SWGCategory")); toJsonValue(QString("category"), category, obj, QString("SWGCategory"));
} }
if(name != nullptr && *name != QString("")){ if(name != nullptr && *name != QString("")){
toJsonValue(QString("name"), name, obj, QString("QString")); toJsonValue(QString("name"), name, obj, QString("QString"));
} }
if(photo_urls->size() > 0){ if(photo_urls->size() > 0){
QJsonArray photo_urlsJsonArray; toJsonArray((QList<void*>*)photo_urls, obj, "photoUrls", "QString");
toJsonArray((QList<void*>*)photo_urls, &photo_urlsJsonArray, "photo_urls", "QString");
obj->insert("photoUrls", photo_urlsJsonArray);
} }
if(tags->size() > 0){ if(tags->size() > 0){
QJsonArray tagsJsonArray; toJsonArray((QList<void*>*)tags, obj, "tags", "SWGTag");
toJsonArray((QList<void*>*)tags, &tagsJsonArray, "tags", "SWGTag");
obj->insert("tags", tagsJsonArray);
} }
if(status != nullptr && *status != QString("")){ if(status != nullptr && *status != QString("")){
toJsonValue(QString("status"), status, obj, QString("QString")); toJsonValue(QString("status"), status, obj, QString("QString"));
} }

View File

@ -29,7 +29,7 @@ SWGPetApi::SWGPetApi(QString host, QString basePath) {
} }
void void
SWGPetApi::addPet(SWGPet body) { SWGPetApi::addPet(SWGPet& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet"); fullPath.append(this->host).append(this->basePath).append("/pet");
@ -401,7 +401,7 @@ SWGPetApi::getPetByIdCallback(SWGHttpRequestWorker * worker) {
} }
void void
SWGPetApi::updatePet(SWGPet body) { SWGPetApi::updatePet(SWGPet& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet"); fullPath.append(this->host).append(this->basePath).append("/pet");

View File

@ -36,12 +36,12 @@ public:
QString basePath; QString basePath;
QMap<QString, QString> defaultHeaders; QMap<QString, QString> defaultHeaders;
void addPet(SWGPet body); void addPet(SWGPet& body);
void deletePet(qint64 pet_id, QString* api_key); void deletePet(qint64 pet_id, QString* api_key);
void findPetsByStatus(QList<QString*>* status); void findPetsByStatus(QList<QString*>* status);
void findPetsByTags(QList<QString*>* tags); void findPetsByTags(QList<QString*>* tags);
void getPetById(qint64 pet_id); void getPetById(qint64 pet_id);
void updatePet(SWGPet body); void updatePet(SWGPet& body);
void updatePetWithForm(qint64 pet_id, QString* name, QString* status); void updatePetWithForm(qint64 pet_id, QString* name, QString* status);
void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file); void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file);

View File

@ -198,7 +198,7 @@ SWGStoreApi::getOrderByIdCallback(SWGHttpRequestWorker * worker) {
} }
void void
SWGStoreApi::placeOrder(SWGOrder body) { SWGStoreApi::placeOrder(SWGOrder& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order"); fullPath.append(this->host).append(this->basePath).append("/store/order");

View File

@ -38,7 +38,7 @@ public:
void deleteOrder(QString* order_id); void deleteOrder(QString* order_id);
void getInventory(); void getInventory();
void getOrderById(qint64 order_id); void getOrderById(qint64 order_id);
void placeOrder(SWGOrder body); void placeOrder(SWGOrder& body);
private: private:
void deleteOrderCallback (SWGHttpRequestWorker * worker); void deleteOrderCallback (SWGHttpRequestWorker * worker);

View File

@ -46,7 +46,7 @@ SWGTag::init() {
void void
SWGTag::cleanup() { SWGTag::cleanup() {
if(name != nullptr) { if(name != nullptr) {
delete name; delete name;
} }
} }
@ -63,7 +63,9 @@ 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");
} }
QString QString
@ -79,9 +81,11 @@ SWGTag::asJson ()
QJsonObject* QJsonObject*
SWGTag::asJsonObject() { SWGTag::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
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

@ -58,22 +58,22 @@ SWGUser::init() {
void void
SWGUser::cleanup() { SWGUser::cleanup() {
if(username != nullptr) { if(username != nullptr) {
delete username; delete username;
} }
if(first_name != nullptr) { if(first_name != nullptr) {
delete first_name; delete first_name;
} }
if(last_name != nullptr) { if(last_name != nullptr) {
delete last_name; delete last_name;
} }
if(email != nullptr) { if(email != nullptr) {
delete email; delete email;
} }
if(password != nullptr) { if(password != nullptr) {
delete password; delete password;
} }
if(phone != nullptr) { if(phone != nullptr) {
delete phone; delete phone;
} }
@ -91,13 +91,21 @@ 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");
::Swagger::setValue(&first_name, pJson["firstName"], "QString", "QString"); ::Swagger::setValue(&first_name, pJson["firstName"], "QString", "QString");
::Swagger::setValue(&last_name, pJson["lastName"], "QString", "QString"); ::Swagger::setValue(&last_name, pJson["lastName"], "QString", "QString");
::Swagger::setValue(&email, pJson["email"], "QString", "QString"); ::Swagger::setValue(&email, pJson["email"], "QString", "QString");
::Swagger::setValue(&password, pJson["password"], "QString", "QString"); ::Swagger::setValue(&password, pJson["password"], "QString", "QString");
::Swagger::setValue(&phone, pJson["phone"], "QString", "QString"); ::Swagger::setValue(&phone, pJson["phone"], "QString", "QString");
::Swagger::setValue(&user_status, pJson["userStatus"], "qint32", ""); ::Swagger::setValue(&user_status, pJson["userStatus"], "qint32", "");
} }
QString QString
@ -113,27 +121,35 @@ SWGUser::asJson ()
QJsonObject* QJsonObject*
SWGUser::asJsonObject() { SWGUser::asJsonObject() {
QJsonObject* obj = new QJsonObject(); QJsonObject* obj = new QJsonObject();
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"));
} }
if(first_name != nullptr && *first_name != QString("")){ if(first_name != nullptr && *first_name != QString("")){
toJsonValue(QString("firstName"), first_name, obj, QString("QString")); toJsonValue(QString("firstName"), first_name, obj, QString("QString"));
} }
if(last_name != nullptr && *last_name != QString("")){ if(last_name != nullptr && *last_name != QString("")){
toJsonValue(QString("lastName"), last_name, obj, QString("QString")); toJsonValue(QString("lastName"), last_name, obj, QString("QString"));
} }
if(email != nullptr && *email != QString("")){ if(email != nullptr && *email != QString("")){
toJsonValue(QString("email"), email, obj, QString("QString")); toJsonValue(QString("email"), email, obj, QString("QString"));
} }
if(password != nullptr && *password != QString("")){ if(password != nullptr && *password != QString("")){
toJsonValue(QString("password"), password, obj, QString("QString")); toJsonValue(QString("password"), password, obj, QString("QString"));
} }
if(phone != nullptr && *phone != QString("")){ if(phone != nullptr && *phone != QString("")){
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));
} }

View File

@ -29,7 +29,7 @@ SWGUserApi::SWGUserApi(QString host, QString basePath) {
} }
void void
SWGUserApi::createUser(SWGUser body) { SWGUserApi::createUser(SWGUser& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user"); fullPath.append(this->host).append(this->basePath).append("/user");
@ -81,7 +81,7 @@ SWGUserApi::createUserCallback(SWGHttpRequestWorker * worker) {
} }
void void
SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>* body) { SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>*& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithArray"); fullPath.append(this->host).append(this->basePath).append("/user/createWithArray");
@ -91,10 +91,10 @@ SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>* body) {
SWGHttpRequestInput input(fullPath, "POST"); SWGHttpRequestInput input(fullPath, "POST");
QJsonArray* bodyArray = new QJsonArray(); auto body_jobj = new QJsonObject();
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*")); toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*bodyArray); QJsonDocument doc(*body_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -137,7 +137,7 @@ SWGUserApi::createUsersWithArrayInputCallback(SWGHttpRequestWorker * worker) {
} }
void void
SWGUserApi::createUsersWithListInput(QList<SWGUser*>* body) { SWGUserApi::createUsersWithListInput(QList<SWGUser*>*& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithList"); fullPath.append(this->host).append(this->basePath).append("/user/createWithList");
@ -147,10 +147,10 @@ SWGUserApi::createUsersWithListInput(QList<SWGUser*>* body) {
SWGHttpRequestInput input(fullPath, "POST"); SWGHttpRequestInput input(fullPath, "POST");
QJsonArray* bodyArray = new QJsonArray(); auto body_jobj = new QJsonObject();
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*")); toJsonArray((QList<void*>*)body, body_jobj, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*bodyArray); QJsonDocument doc(*body_jobj);
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -419,7 +419,7 @@ SWGUserApi::logoutUserCallback(SWGHttpRequestWorker * worker) {
} }
void void
SWGUserApi::updateUser(QString* username, SWGUser body) { SWGUserApi::updateUser(QString* username, SWGUser& body) {
QString fullPath; QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}"); fullPath.append(this->host).append(this->basePath).append("/user/{username}");

View File

@ -35,14 +35,14 @@ public:
QString basePath; QString basePath;
QMap<QString, QString> defaultHeaders; QMap<QString, QString> defaultHeaders;
void createUser(SWGUser body); void createUser(SWGUser& body);
void createUsersWithArrayInput(QList<SWGUser*>* body); void createUsersWithArrayInput(QList<SWGUser*>*& body);
void createUsersWithListInput(QList<SWGUser*>* body); void createUsersWithListInput(QList<SWGUser*>*& body);
void deleteUser(QString* username); void deleteUser(QString* username);
void getUserByName(QString* username); void getUserByName(QString* username);
void loginUser(QString* username, QString* password); void loginUser(QString* username, QString* password);
void logoutUser(); void logoutUser();
void updateUser(QString* username, SWGUser body); void updateUser(QString* username, SWGUser& body);
private: private:
void createUserCallback (SWGHttpRequestWorker * worker); void createUserCallback (SWGHttpRequestWorker * worker);