forked from loafle/openapi-generator-original
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:
parent
809e1f4c93
commit
0bf430a803
@ -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<void*>*){{paramName}}, {{paramName}}Array, QString("body"), QString("{{prefix}}User*"));
|
||||
auto {{paramName}}_jobj = new QJsonObject();
|
||||
toJsonArray((QList<void*>*){{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}}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public:
|
||||
QString basePath;
|
||||
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}}
|
||||
private:
|
||||
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);
|
||||
|
@ -40,17 +40,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
|
||||
}
|
||||
else if (QStringLiteral("QString").compare(type) == 0) {
|
||||
QString **val = static_cast<QString**>(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<QList<{{prefix}}Object *> **> (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);
|
||||
(*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) {
|
||||
QList<qint32> **output = reinterpret_cast<QList<qint32> **> (value);
|
||||
auto output = reinterpret_cast<QList<qint32> **> (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<qint64> **output = reinterpret_cast<QList<qint64> **> (value);
|
||||
auto output = reinterpret_cast<QList<qint64> **> (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<bool> **output = reinterpret_cast<QList<bool> **> (value);
|
||||
auto output = reinterpret_cast<QList<bool> **> (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<float> **output = reinterpret_cast<QList<float> **> (value);
|
||||
auto output = reinterpret_cast<QList<float> **> (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<double> **output = reinterpret_cast<QList<double> **> (value);
|
||||
auto output = reinterpret_cast<QList<double> **> (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<QString*> **output = reinterpret_cast<QList<QString*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QString*> **> (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<QDate*> **output = reinterpret_cast<QList<QDate*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QDate*> **> (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<QDateTime*> **output = reinterpret_cast<QList<QDateTime*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QDateTime*> **> (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<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
|
||||
@ -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<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}}")){
|
||||
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<QList<QString*>*>(value))){
|
||||
output->append(QJsonValue(*obj));
|
||||
outputarray.append(QJsonValue(*obj));
|
||||
}
|
||||
}
|
||||
else if(QStringLiteral("QDate").compare(innerType) == 0) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("qint64").compare(innerType) == 0) {
|
||||
for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("bool").compare(innerType) == 0) {
|
||||
for(bool obj : *(reinterpret_cast<QList<bool>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("float").compare(innerType) == 0) {
|
||||
for(float obj : *(reinterpret_cast<QList<float>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("double").compare(innerType) == 0) {
|
||||
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
|
||||
|
@ -9,8 +9,9 @@ namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
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 toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType);
|
||||
bool isCompatibleJsonValue(QString type);
|
||||
QString stringValue(QString* value);
|
||||
QString stringValue(qint32 value);
|
||||
|
@ -38,12 +38,15 @@ void
|
||||
{{classname}}::cleanup() {
|
||||
{{#vars}}
|
||||
{{#complexType}}
|
||||
if({{name}} != nullptr) {
|
||||
{{#isContainer}}{{#isListContainer}}QList<{{complexType}}*>* arr = {{name}};{{/isListContainer}}{{#isMapContainer}}QMap<QString, {{complexType}}*>* 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<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 = 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<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.value(val));
|
||||
::{{cppNamespace}}::setValue((QMap<QString, void *>*)&{{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<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}}
|
||||
}{{/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<void*>*){{name}}, &{{name}}JsonArray, "{{name}}", "{{items.baseType}}");
|
||||
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, "{{items.baseType}}");
|
||||
{{^items.isContainer}}toJsonArray((QList<void*>*){{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}}
|
||||
QJsonArray jarray;
|
||||
for(auto items : *{{name}}){
|
||||
QJsonObject jobj;
|
||||
{{#items.isListContainer}}toJsonArray((QList<void*>*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}");{{/items.isListContainer}}
|
||||
{{#items.isMapContainer}}toJsonMap((QMap<QString, void*>*)items, &jobj, "{{baseName}}", "{{items.items.baseType}}");{{/items.isMapContainer}}
|
||||
jarray.append(jobj.value("{{baseName}}"));
|
||||
}
|
||||
obj->insert("{{baseName}}", {{name}}_jobj);
|
||||
}
|
||||
{{/isMapContainer}}
|
||||
{{/complexType}}
|
||||
obj->insert("{{baseName}}", jarray);{{/items.isContainer}}
|
||||
}{{/isListContainer}}{{#isMapContainer}}
|
||||
if({{name}}->size() > 0){
|
||||
{{^items.isContainer}}toJsonMap((QMap<QString, void*>*) {{name}}, obj, "{{baseName}}", "{{complexType}}");{{/items.isContainer}}{{#items.isContainer}}
|
||||
QJsonObject mapobj;
|
||||
for(auto itemkey : {{name}}->keys()){
|
||||
QJsonObject 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}}
|
||||
mapobj.insert(itemkey, jobj);
|
||||
}
|
||||
obj->insert("{{baseName}}", mapobj);{{/items.isContainer}}
|
||||
}{{/isMapContainer}}{{/isContainer}}
|
||||
{{/vars}}
|
||||
|
||||
return obj;
|
||||
|
@ -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
|
||||
|
@ -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"));
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
|
@ -49,17 +49,16 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) {
|
||||
}
|
||||
else if (QStringLiteral("QString").compare(type) == 0) {
|
||||
QString **val = static_cast<QString**>(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<SWGObject**>(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<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();
|
||||
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);
|
||||
(*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) {
|
||||
QList<qint32> **output = reinterpret_cast<QList<qint32> **> (value);
|
||||
auto output = reinterpret_cast<QList<qint32> **> (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<qint64> **output = reinterpret_cast<QList<qint64> **> (value);
|
||||
auto output = reinterpret_cast<QList<qint64> **> (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<bool> **output = reinterpret_cast<QList<bool> **> (value);
|
||||
auto output = reinterpret_cast<QList<bool> **> (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<float> **output = reinterpret_cast<QList<float> **> (value);
|
||||
auto output = reinterpret_cast<QList<float> **> (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<double> **output = reinterpret_cast<QList<double> **> (value);
|
||||
auto output = reinterpret_cast<QList<double> **> (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<QString*> **output = reinterpret_cast<QList<QString*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QString*> **> (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<QDate*> **output = reinterpret_cast<QList<QDate*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QDate*> **> (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<QDateTime*> **output = reinterpret_cast<QList<QDateTime*> **> (value);
|
||||
auto output = reinterpret_cast<QList<QDateTime*> **> (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<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
|
||||
@ -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<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")){
|
||||
for(void* obj : *value) {
|
||||
SWGObject *SWGobject = reinterpret_cast<SWGObject *>(obj);
|
||||
if(SWGobject != nullptr) {
|
||||
output->append(*(SWGobject->asJsonObject()));
|
||||
outputarray.append(*(SWGobject->asJsonObject()));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(QStringLiteral("QString").compare(innerType) == 0) {
|
||||
for(QString* obj : *(reinterpret_cast<QList<QString*>*>(value))){
|
||||
output->append(QJsonValue(*obj));
|
||||
outputarray.append(QJsonValue(*obj));
|
||||
}
|
||||
}
|
||||
else if(QStringLiteral("QDate").compare(innerType) == 0) {
|
||||
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) {
|
||||
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) {
|
||||
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) {
|
||||
for(qint32 obj : *(reinterpret_cast<QList<qint32>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("qint64").compare(innerType) == 0) {
|
||||
for(qint64 obj : *(reinterpret_cast<QList<qint64>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("bool").compare(innerType) == 0) {
|
||||
for(bool obj : *(reinterpret_cast<QList<bool>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("float").compare(innerType) == 0) {
|
||||
for(float obj : *(reinterpret_cast<QList<float>*>(value)))
|
||||
output->append(QJsonValue(obj));
|
||||
outputarray.append(QJsonValue(obj));
|
||||
}
|
||||
else if(QStringLiteral("double").compare(innerType) == 0) {
|
||||
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
|
||||
|
@ -18,8 +18,9 @@
|
||||
namespace Swagger {
|
||||
|
||||
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 toJsonMap(QMap<QString, void*>* value, QJsonObject* output, QString innerName, QString innerType);
|
||||
bool isCompatibleJsonValue(QString type);
|
||||
QString stringValue(QString* value);
|
||||
QString stringValue(qint32 value);
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -61,15 +61,15 @@ SWGPet::cleanup() {
|
||||
delete name;
|
||||
}
|
||||
if(photo_urls != nullptr) {
|
||||
QList<QString*>* arr = photo_urls;
|
||||
foreach(QString* o, *arr) {
|
||||
auto arr = photo_urls;
|
||||
for(auto o: *arr) {
|
||||
delete o;
|
||||
}
|
||||
delete photo_urls;
|
||||
}
|
||||
if(tags != nullptr) {
|
||||
QList<SWGTag*>* arr = tags;
|
||||
foreach(SWGTag* o, *arr) {
|
||||
auto arr = tags;
|
||||
for(auto o: *arr) {
|
||||
delete o;
|
||||
}
|
||||
delete tags;
|
||||
@ -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<void*>*)photo_urls, &photo_urlsJsonArray, "photo_urls", "QString");
|
||||
obj->insert("photoUrls", photo_urlsJsonArray);
|
||||
toJsonArray((QList<void*>*)photo_urls, obj, "photoUrls", "QString");
|
||||
}
|
||||
|
||||
if(tags->size() > 0){
|
||||
QJsonArray tagsJsonArray;
|
||||
toJsonArray((QList<void*>*)tags, &tagsJsonArray, "tags", "SWGTag");
|
||||
obj->insert("tags", tagsJsonArray);
|
||||
toJsonArray((QList<void*>*)tags, obj, "tags", "SWGTag");
|
||||
}
|
||||
|
||||
if(status != nullptr && *status != QString("")){
|
||||
toJsonValue(QString("status"), status, obj, QString("QString"));
|
||||
}
|
||||
|
@ -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");
|
||||
|
||||
|
@ -36,12 +36,12 @@ public:
|
||||
QString basePath;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
|
||||
void addPet(SWGPet body);
|
||||
void addPet(SWGPet& body);
|
||||
void deletePet(qint64 pet_id, QString* api_key);
|
||||
void findPetsByStatus(QList<QString*>* status);
|
||||
void findPetsByTags(QList<QString*>* 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);
|
||||
|
||||
|
@ -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");
|
||||
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
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);
|
||||
|
@ -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"));
|
||||
}
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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<SWGUser*>* body) {
|
||||
SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>*& body) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/user/createWithArray");
|
||||
|
||||
@ -91,10 +91,10 @@ SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>* body) {
|
||||
SWGHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
QJsonArray* bodyArray = new QJsonArray();
|
||||
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*"));
|
||||
auto body_jobj = new QJsonObject();
|
||||
toJsonArray((QList<void*>*)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<SWGUser*>* body) {
|
||||
SWGUserApi::createUsersWithListInput(QList<SWGUser*>*& body) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/user/createWithList");
|
||||
|
||||
@ -147,10 +147,10 @@ SWGUserApi::createUsersWithListInput(QList<SWGUser*>* body) {
|
||||
SWGHttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
QJsonArray* bodyArray = new QJsonArray();
|
||||
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*"));
|
||||
auto body_jobj = new QJsonObject();
|
||||
toJsonArray((QList<void*>*)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}");
|
||||
|
||||
|
@ -35,14 +35,14 @@ public:
|
||||
QString basePath;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
|
||||
void createUser(SWGUser body);
|
||||
void createUsersWithArrayInput(QList<SWGUser*>* body);
|
||||
void createUsersWithListInput(QList<SWGUser*>* body);
|
||||
void createUser(SWGUser& body);
|
||||
void createUsersWithArrayInput(QList<SWGUser*>*& body);
|
||||
void createUsersWithListInput(QList<SWGUser*>*& 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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user