From 6253bbff3dd3cccd893fc8ddb236e7cf6fc371d3 Mon Sep 17 00:00:00 2001 From: wing328 Date: Tue, 9 Jun 2015 12:42:07 +0800 Subject: [PATCH] roll back qt5cpp template --- .../main/resources/qt5cpp/api-body.mustache | 314 +++++++++--------- .../main/resources/qt5cpp/api-header.mustache | 22 +- .../resources/qt5cpp/helpers-body.mustache | 305 ++++++++--------- .../resources/qt5cpp/helpers-header.mustache | 13 +- .../main/resources/qt5cpp/model-body.mustache | 155 +++++---- .../resources/qt5cpp/model-header.mustache | 41 ++- .../src/main/resources/qt5cpp/model.mustache | 56 ++-- .../resources/qt5cpp/modelFactory.mustache | 39 ++- .../src/main/resources/qt5cpp/object.mustache | 21 +- 9 files changed, 454 insertions(+), 512 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache index 88d1bce3563..b6341104188 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache @@ -2,186 +2,180 @@ #include "{{prefix}}Helpers.h" #include "{{prefix}}ModelFactory.h" -#include - - #include - +#include +#include - namespace Swagger { - {{classname}}::{{classname}}() {} +namespace Swagger { +{{classname}}::{{classname}}() {} - {{classname}}::~{{classname}}() {} +{{classname}}::~{{classname}}() {} - {{classname}}::{{classname}}(QString host, QString basePath) { - this->host = host; - this->basePath = basePath; +{{classname}}::{{classname}}(QString host, QString basePath) { + this->host = host; + this->basePath = basePath; +} + +{{#operations}} +{{#operation}} +void +{{classname}}::{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { + QString fullPath; + fullPath.append(this->host).append(this->basePath).append("{{path}}"); + + {{#pathParams}} + QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{paramName}}").append("}"); + fullPath.replace({{paramName}}PathParam, stringValue({{paramName}})); + {{/pathParams}} + + {{#queryParams}} + {{^collectionFormat}} + if(fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append(QUrl::toPercentEncoding("{{paramName}}")) + .append("=") + .append(QUrl::toPercentEncoding(stringValue({{paramName}}))); + {{/collectionFormat}} + + {{#collectionFormat}} + + if({{{paramName}}}->size() > 0) { + if(QString("{{collectionFormat}}").indexOf("multi") == 0) { + foreach({{{baseType}}} t, *{{paramName}}) { + if(fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{{paramName}}}=").append(stringValue(t)); } + } + else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) { + if(fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{paramName}}="); + qint32 count = 0; + foreach({{{baseType}}} t, *{{paramName}}) { + if(count > 0) { + fullPath.append(" "); + } + fullPath.append(stringValue(t)); + } + } + else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) { + if(fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{paramName}}="); + qint32 count = 0; + foreach({{{baseType}}} t, *{{paramName}}) { + if(count > 0) { + fullPath.append("\t"); + } + fullPath.append(stringValue(t)); + } + } + } - {{#operations}} - {{#operation}} - void - {{classname}}::{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}} - , {{/hasMore}}{{/allParams}}) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("{{path}}"); + {{/collectionFormat}} + {{/queryParams}} - {{#pathParams}} - QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{paramName}}").append("}"); - fullPath.replace({{paramName}}PathParam, stringValue({{paramName}})); - {{/pathParams}} + HttpRequestWorker *worker = new HttpRequestWorker(); + HttpRequestInput input(fullPath, "{{httpMethod}}"); - {{#queryParams}} - {{^collectionFormat}} - if(fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?"); - fullPath.append(QUrl::toPercentEncoding("{{paramName}}")) - .append("=") - .append(QUrl::toPercentEncoding(stringValue({{paramName}}))); - {{/collectionFormat}} + {{#formParams}}{{^isFile}} + if({{paramName}} != NULL) { + input.add_var("{{paramName}}", *{{paramName}}); + } + {{/isFile}}{{/formParams}} - {{#collectionFormat}} + {{#bodyParams}} + {{#isContainer}} + QJsonArray* {{paramName}}Array = new QJsonArray(); + toJsonArray((QList*){{paramName}}, {{paramName}}Array, QString("body"), QString("SWGUser*")); - if({{{paramName}}}->size() > 0) { - if(QString("{{collectionFormat}}").indexOf("multi") == 0) { - foreach({{{baseType}}} t, *{{paramName}}) { - if(fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?"); - fullPath.append("{{{paramName}}}=").append(stringValue(t)); - } - } - else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) { - if(fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?"); - fullPath.append("{{paramName}}="); - qint32 count = 0; - foreach({{{baseType}}} t, *{{paramName}}) { - if(count > 0) { - fullPath.append(" "); - } - fullPath.append(stringValue(t)); - } - } - else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) { - if(fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?"); - fullPath.append("{{paramName}}="); - qint32 count = 0; - foreach({{{baseType}}} t, *{{paramName}}) { - if(count > 0) { - fullPath.append("\t"); - } - fullPath.append(stringValue(t)); - } - } - } + QJsonDocument doc(*{{paramName}}Array); + QByteArray bytes = doc.toJson(); - {{/collectionFormat}} - {{/queryParams}} + input.request_body.append(bytes); + {{/isContainer}} + {{^isContainer}} + QString output = {{paramName}}.asJson(); + input.request_body.append(output); + {{/isContainer}}{{/bodyParams}} - HttpRequestWorker *worker = new HttpRequestWorker(); - HttpRequestInput input(fullPath, "{{httpMethod}}"); + {{#headerParams}} + // TODO: add header support + {{/headerParams}} - {{#formParams}}{{^isFile}} - if({{paramName}} != NULL) { - input.add_var("{{paramName}}", *{{paramName}}); - } - {{/isFile}}{{/formParams}} + connect(worker, + &HttpRequestWorker::on_execution_finished, + this, + &{{classname}}::{{nickname}}Callback); - {{#bodyParams}} - {{#isContainer}} - QJsonArray* {{paramName}}Array = new QJsonArray(); - toJsonArray((QList - *){{paramName}}, {{paramName}}Array, QString("body"), QString("SWGUser*")); + worker->execute(&input); +} - QJsonDocument doc(*{{paramName}}Array); - QByteArray bytes = doc.toJson(); +void +{{classname}}::{{nickname}}Callback(HttpRequestWorker * worker) { + QString msg; + if (worker->error_type == QNetworkReply::NoError) { + msg = QString("Success! %1 bytes").arg(worker->response.length()); + } + else { + msg = "Error: " + worker->error_str; + } - input.request_body.append(bytes); - {{/isContainer}} - {{^isContainer}} - QString output = {{paramName}}.asJson(); - input.request_body.append(output); - {{/isContainer}}{{/bodyParams}} + {{#returnType}}{{#isListContainer}} + {{{returnType}}} output = {{{defaultResponse}}}; + QString json(worker->response); + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonArray jsonArray = doc.array(); - {{#headerParams}} - // TODO: add header support - {{/headerParams}} + foreach(QJsonValue obj, jsonArray) { + {{{returnBaseType}}}* o = new {{returnBaseType}}(); + QJsonObject jv = obj.toObject(); + QJsonObject * ptr = (QJsonObject*)&jv; + o->fromJsonObject(*ptr); + output->append(o); + } + {{/isListContainer}} - connect(worker, - &HttpRequestWorker::on_execution_finished, - this, - &{{classname}}::{{nickname}}Callback); + {{^isListContainer}}{{#returnTypeIsPrimitive}} + {{{returnType}}} output; // TODO add primitive output support + {{/returnTypeIsPrimitive}} + {{#isMapContainer}} + {{{returnType}}} output = {{{defaultResponse}}}; - worker->execute(&input); - } + QString json(worker->response); + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject obj = doc.object(); - void - {{classname}}::{{nickname}}Callback(HttpRequestWorker * worker) { - QString msg; - if (worker->error_type == QNetworkReply::NoError) { - msg = QString("Success! %1 bytes").arg(worker->response.length()); - } - else { - msg = "Error: " + worker->error_str; - } - - {{#returnType}}{{#isListContainer}} - {{{returnType}}} output = {{{defaultResponse}}}; - QString json(worker->response); - QByteArray array (json.toStdString().c_str()); - QJsonDocument doc = QJsonDocument::fromJson(array); - QJsonArray jsonArray = doc.array(); - - foreach(QJsonValue obj, jsonArray) { - {{{returnBaseType}}}* o = new {{returnBaseType}}(); - QJsonObject jv = obj.toObject(); - QJsonObject * ptr = (QJsonObject*)&jv; - o->fromJsonObject(*ptr); - output->append(o); - } - {{/isListContainer}} - - {{^isListContainer}}{{#returnTypeIsPrimitive}} - {{{returnType}}} output; // TODO add primitive output support - {{/returnTypeIsPrimitive}} - {{#isMapContainer}} - {{{returnType}}} output = {{{defaultResponse}}}; - - QString json(worker->response); - QByteArray array (json.toStdString().c_str()); - QJsonDocument doc = QJsonDocument::fromJson(array); - QJsonObject obj = doc.object(); - - foreach(QString key, obj.keys()) { - qint32* val; - setValue(&val, obj[key], "{{returnBaseType}}", ""); - output->insert(key, *val); - } + foreach(QString key, obj.keys()) { + qint32* val; + setValue(&val, obj[key], "{{returnBaseType}}", ""); + output->insert(key, *val); + } - {{/isMapContainer}} - {{^isMapContainer}} - {{^returnTypeIsPrimitive}}QString json(worker->response); - {{{returnType}}} output = static_cast<{{{returnType}}}>(create(json, - QString("{{{returnBaseType}}}"))); - {{/returnTypeIsPrimitive}} - {{/isMapContainer}} - {{/isListContainer}}{{/returnType}} + {{/isMapContainer}} + {{^isMapContainer}} + {{^returnTypeIsPrimitive}}QString json(worker->response); + {{{returnType}}} output = static_cast<{{{returnType}}}>(create(json, QString("{{{returnBaseType}}}"))); + {{/returnTypeIsPrimitive}} + {{/isMapContainer}} + {{/isListContainer}}{{/returnType}} - worker->deleteLater(); + worker->deleteLater(); - {{#returnType}}emit {{nickname}}Signal(output);{{/returnType}} - {{^returnType}}emit {{nickname}}Signal();{{/returnType}} - } - {{/operation}} - {{/operations}} - } /* namespace Swagger */ + {{#returnType}}emit {{nickname}}Signal(output);{{/returnType}} + {{^returnType}}emit {{nickname}}Signal();{{/returnType}} +} +{{/operation}} +{{/operations}} +} /* namespace Swagger */ diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache index ffee582a4fc..4260ba6ff86 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-header.mustache @@ -6,15 +6,14 @@ {{#imports}}{{{import}}} {{/imports}} -#include - +#include - namespace Swagger { +namespace Swagger { - class {{classname}}: public QObject { +class {{classname}}: public QObject { Q_OBJECT - public: +public: {{classname}}(); {{classname}}(QString host, QString basePath); ~{{classname}}(); @@ -22,15 +21,14 @@ QString host; QString basePath; - {{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}} - , {{/hasMore}}{{/allParams}}); + {{#operations}}{{#operation}}void {{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); {{/operation}}{{/operations}} - private: +private: {{#operations}}{{#operation}}void {{nickname}}Callback (HttpRequestWorker * worker); {{/operation}}{{/operations}} - signals: +signals: {{#operations}}{{#operation}}void {{nickname}}Signal({{#returnType}}{{{returnType}}} summary{{/returnType}}); {{/operation}}{{/operations}} - }; - } - #endif \ No newline at end of file +}; +} +#endif \ No newline at end of file diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache index 0cc60d91b90..7f4d748c2dc 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -1,201 +1,166 @@ #include "SWGHelpers.h" #include "SWGModelFactory.h" #include "SWGObject.h" -#import - - #import - - #import - +#import +#import +#import - namespace Swagger { +namespace Swagger { - void - setValue(void* value, QJsonValue obj, QString type, QString complexType) { - if(value == NULL) { - // can't set value with a null pointer - return; - } - if(QStringLiteral("bool").compare(type) == 0) { - bool * val = static_cast - (value); - *val = obj.toBool(); - } - else if(QStringLiteral("qint32").compare(type) == 0) { - qint32 *val = static_cast - (value); - *val = obj.toInt(); - } - else if(QStringLiteral("qint64").compare(type) == 0) { - qint64 *val = static_cast - (value); - *val = obj.toVariant().toLongLong(); - } - else if (QStringLiteral("QString").compare(type) == 0) { - QString **val = static_cast - (value); +void +setValue(void* value, QJsonValue obj, QString type, QString complexType) { + if(value == NULL) { + // can't set value with a null pointer + return; + } + if(QStringLiteral("bool").compare(type) == 0) { + bool * val = static_cast(value); + *val = obj.toBool(); + } + else if(QStringLiteral("qint32").compare(type) == 0) { + qint32 *val = static_cast(value); + *val = obj.toInt(); + } + else if(QStringLiteral("qint64").compare(type) == 0) { + qint64 *val = static_cast(value); + *val = obj.toVariant().toLongLong(); + } + else if (QStringLiteral("QString").compare(type) == 0) { + QString **val = static_cast(value); - if(val != NULL) { + if(val != NULL) { if(!obj.isNull()) { - // create a new value and return - delete *val; - *val = new QString(obj.toString()); - return; + // create a new value and return + delete *val; + *val = new QString(obj.toString()); + return; } else { - // set target to NULL - delete *val; - *val = NULL; + // set target to NULL + delete *val; + *val = NULL; } - } - else { + } + else { qDebug() << "Can't set value because the target pointer is NULL"; - } - } - else if(type.startsWith("SWG") && obj.isObject()) { - // complex type - QJsonObject jsonObj = obj.toObject(); - SWGObject * so = (SWGObject*)Swagger::create(type); - if(so != NULL) { + } + } + else if(type.startsWith("SWG") && obj.isObject()) { + // complex type + QJsonObject jsonObj = obj.toObject(); + SWGObject * so = (SWGObject*)Swagger::create(type); + if(so != NULL) { so->fromJsonObject(jsonObj); - SWGObject **val = static_cast - (value); + SWGObject **val = static_cast(value); delete *val; *val = so; - } - } - else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { - // list of values - QList - * output = new QList - (); - QJsonArray arr = obj.toArray(); - foreach (const QJsonValue & jval, arr) { + } + } + else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) { + // list of values + QList* output = new QList(); + QJsonArray arr = obj.toArray(); + foreach (const QJsonValue & jval, arr) { if(complexType.startsWith("SWG")) { - // it's an object - SWGObject * val = (SWGObject*)create(complexType); - QJsonObject t = jval.toObject(); + // it's an object + SWGObject * val = (SWGObject*)create(complexType); + QJsonObject t = jval.toObject(); - val->fromJsonObject(t); - output->append(val); + val->fromJsonObject(t); + output->append(val); } else { - // primitives - if(QStringLiteral("qint32").compare(complexType) == 0) { - qint32 val; - setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); - output->append((void*)&val); - } - else if(QStringLiteral("qint64").compare(complexType) == 0) { - qint64 val; - setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); - output->append((void*)&val); - } - else if(QStringLiteral("bool").compare(complexType) == 0) { - bool val; - setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); - output->append((void*)&val); - } - } - } - QList - **val = static_cast - **>(value); - delete *val; - *val = output; - } + // primitives + if(QStringLiteral("qint32").compare(complexType) == 0) { + qint32 val; + setValue(&val, jval, QStringLiteral("qint32"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("qint64").compare(complexType) == 0) { + qint64 val; + setValue(&val, jval, QStringLiteral("qint64"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("bool").compare(complexType) == 0) { + bool val; + setValue(&val, jval, QStringLiteral("bool"), QStringLiteral("")); + output->append((void*)&val); + } } + } + QList **val = static_cast**>(value); + delete *val; + *val = output; + } +} - void - toJsonValue(QString name, void* value, QJsonObject* output, QString type) { - if(value == NULL) { - return; - } - if(type.startsWith("SWG")) { - SWGObject *swgObject = reinterpret_cast - (value); - if(swgObject != NULL) { - QJsonObject* o = (*swgObject).asJsonObject(); - if(name != NULL) { +void +toJsonValue(QString name, void* value, QJsonObject* output, QString type) { + if(value == NULL) { + return; + } + if(type.startsWith("SWG")) { + SWGObject *swgObject = reinterpret_cast(value); + if(swgObject != NULL) { + QJsonObject* o = (*swgObject).asJsonObject(); + if(name != NULL) { output->insert(name, *o); delete o; - } - else { + } + else { output->empty(); foreach(QString key, o->keys()) { - output->insert(key, o->value(key)); - } - } - } - } - else if(QStringLiteral("QString").compare(type) == 0) { - QString* str = static_cast - (value); - output->insert(name, QJsonValue(*str)); - } - else if(QStringLiteral("qint32").compare(type) == 0) { - qint32* str = static_cast - (value); - output->insert(name, QJsonValue(*str)); - } - else if(QStringLiteral("qint64").compare(type) == 0) { - qint64* str = static_cast - (value); - output->insert(name, QJsonValue(*str)); - } - else if(QStringLiteral("bool").compare(type) == 0) { - bool* str = static_cast - (value); - output->insert(name, QJsonValue(*str)); - } + output->insert(key, o->value(key)); } + } + } + } + else if(QStringLiteral("QString").compare(type) == 0) { + QString* str = static_cast(value); + output->insert(name, QJsonValue(*str)); + } + else if(QStringLiteral("qint32").compare(type) == 0) { + qint32* str = static_cast(value); + output->insert(name, QJsonValue(*str)); + } + else if(QStringLiteral("qint64").compare(type) == 0) { + qint64* str = static_cast(value); + output->insert(name, QJsonValue(*str)); + } + else if(QStringLiteral("bool").compare(type) == 0) { + bool* str = static_cast(value); + output->insert(name, QJsonValue(*str)); + } +} - void - toJsonArray(QList - * value, QJsonArray* output, QString innerName, QString innerType) { - foreach(void* obj, *value) { - QJsonObject element; +void +toJsonArray(QList* value, QJsonArray* output, QString innerName, QString innerType) { + foreach(void* obj, *value) { + QJsonObject element; - toJsonValue(NULL, obj, &element, innerType); - output->append(element); - } - } + toJsonValue(NULL, obj, &element, innerType); + output->append(element); + } +} - QString - stringValue(QString* value) { - QString* str = static_cast - (value); - return QString(*str); - } +QString +stringValue(QString* value) { + QString* str = static_cast(value); + return QString(*str); +} - QString - stringValue(qint32 value) { - return QString::number(value); - } +QString +stringValue(qint32 value) { + return QString::number(value); +} - QString - stringValue(qint64 value) { - return QString::number(value); - } +QString +stringValue(qint64 value) { + return QString::number(value); +} - QString - stringValue(bool value) { - return QString(value ? "true" : "false"); - } - } /* namespace Swagger */ +QString +stringValue(bool value) { + return QString(value ? "true" : "false"); +} +} /* namespace Swagger */ diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache index 52bba0455bc..3a02c0952d5 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-header.mustache @@ -1,20 +1,17 @@ #ifndef SWGHELPERS_H #define SWGHELPERS_H -#include - +#include - namespace Swagger { +namespace Swagger { void setValue(void* value, QJsonValue obj, QString type, QString complexType); - void toJsonArray(QList - * value, QJsonArray* output, QString innerName, QString innerType); + void toJsonArray(QList* value, QJsonArray* output, QString innerName, QString innerType); void toJsonValue(QString name, void* value, QJsonObject* output, QString type); bool isCompatibleJsonValue(QString type); QString stringValue(QString* value); QString stringValue(qint32 value); QString stringValue(qint64 value); QString stringValue(bool value); - } +} - #endif // SWGHELPERS_H +#endif // SWGHELPERS_H diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache index 641457082c3..705cb852108 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model-body.mustache @@ -1,114 +1,109 @@ {{#models}}{{#model}} - #include "{{classname}}.h" +#include "{{classname}}.h" - #include "SWGHelpers.h" +#include "SWGHelpers.h" - #include - - #include - - #include - - #include - +#include +#include +#include +#include - namespace Swagger { +namespace Swagger { - {{classname}}::{{classname}}(QString* json) { - init(); - this->fromJson(*json); - } +{{classname}}::{{classname}}(QString* json) { + init(); + this->fromJson(*json); +} - {{classname}}::{{classname}}() { - init(); - } +{{classname}}::{{classname}}() { + init(); +} - {{classname}}::~{{classname}}() { - this->cleanup(); - } +{{classname}}::~{{classname}}() { + this->cleanup(); +} - void - {{classname}}::init() { +void +{{classname}}::init() { {{#vars}}{{name}} = {{{defaultValue}}}; {{/vars}} - } +} - void - {{classname}}::cleanup() { +void +{{classname}}::cleanup() { {{#vars}}{{#complexType}}if({{name}} != NULL) { - {{#isContainer}}QList<{{complexType}}*>* arr = {{name}}; + {{#isContainer}}QList<{{complexType}}*>* arr = {{name}}; foreach({{complexType}}* o, *arr) { - delete o; + delete o; } - {{/isContainer}}delete {{name}}; - }{{/complexType}} + {{/isContainer}}delete {{name}}; + }{{/complexType}} {{/vars}} - } +} - {{classname}}* - {{classname}}::fromJson(QString &json) { - QByteArray array (json.toStdString().c_str()); - QJsonDocument doc = QJsonDocument::fromJson(array); - QJsonObject jsonObject = doc.object(); - this->fromJsonObject(jsonObject); - return this; - } +{{classname}}* +{{classname}}::fromJson(QString &json) { + QByteArray array (json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonObject jsonObject = doc.object(); + this->fromJsonObject(jsonObject); + return this; +} - void - {{classname}}::fromJsonObject(QJsonObject &pJson) { +void +{{classname}}::fromJsonObject(QJsonObject &pJson) { {{#vars}}setValue(&{{name}}, pJson["{{name}}"], "{{baseType}}", "{{complexType}}"); {{/vars}} - } +} - QString - {{classname}}::asJson () - { - QJsonObject* obj = this->asJsonObject(); +QString +{{classname}}::asJson () +{ + QJsonObject* obj = this->asJsonObject(); + + QJsonDocument doc(*obj); + QByteArray bytes = doc.toJson(); + return QString(bytes); +} - QJsonDocument doc(*obj); - QByteArray bytes = doc.toJson(); - return QString(bytes); - } - - QJsonObject* - {{classname}}::asJsonObject() { - QJsonObject* obj = new QJsonObject(); +QJsonObject* +{{classname}}::asJsonObject() { + QJsonObject* obj = new QJsonObject(); {{#vars}}{{#complexType}} - {{^isContainer}}{{#complexType}} - toJsonValue(QString("{{name}}"), {{name}}, obj, QString("{{complexType}}")); - {{/complexType}}{{^complexType}} - else if({{name}} != NULL && *{{name}} != NULL) { - obj->insert("{{name}}", QJsonValue(*{{name}})); - }{{/complexType}} - {{/isContainer}}{{#isContainer}} - QList<{{complexType}}*>* {{name}}List = {{name}}; - QJsonArray {{name}}JsonArray; - toJsonArray((QList - *){{name}}, &{{name}}JsonArray, "{{name}}", "{{complexType}}"); + {{^isContainer}}{{#complexType}} + toJsonValue(QString("{{name}}"), {{name}}, obj, QString("{{complexType}}")); + {{/complexType}}{{^complexType}} + else if({{name}} != NULL && *{{name}} != NULL) { + obj->insert("{{name}}", QJsonValue(*{{name}})); + }{{/complexType}} + {{/isContainer}}{{#isContainer}} + QList<{{complexType}}*>* {{name}}List = {{name}}; + QJsonArray {{name}}JsonArray; + toJsonArray((QList*){{name}}, &{{name}}JsonArray, "{{name}}", "{{complexType}}"); - obj->insert("{{name}}", {{name}}JsonArray); - {{/isContainer}} + obj->insert("{{name}}", {{name}}JsonArray); + {{/isContainer}} {{/complexType}}{{^complexType}}obj->insert("{{name}}", QJsonValue({{name}}));{{/complexType}} {{/vars}} - return obj; - } + return obj; +} - {{#vars}} - {{{datatype}}} - {{classname}}::{{getter}}() { - return {{name}}; - } - void - {{classname}}::{{setter}}({{{datatype}}} {{name}}) { - this->{{name}} = {{name}}; - } +{{#vars}} +{{{datatype}}} +{{classname}}::{{getter}}() { + return {{name}}; +} +void +{{classname}}::{{setter}}({{{datatype}}} {{name}}) { + this->{{name}} = {{name}}; +} - {{/vars}} +{{/vars}} - } /* namespace Swagger */ +} /* namespace Swagger */ {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache index 7a63ce9564a..7b0b6cdcc1b 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model-header.mustache @@ -1,48 +1,47 @@ {{#models}}{{#model}}/* -* {{classname}}.h -* -* {{description}} -*/ + * {{classname}}.h + * + * {{description}} + */ #ifndef {{classname}}_H_ #define {{classname}}_H_ -#include - +#include {{/model}}{{/models}} {{#imports}}{{{import}}} {{/imports}} - #include "SWGObject.h" +#include "SWGObject.h" {{#models}}{{#model}} - namespace Swagger { +namespace Swagger { - class {{classname}}: public SWGObject { - public: +class {{classname}}: public SWGObject { +public: {{classname}}(); {{classname}}(QString* json); - virtual ~{{classname}}(); - void init(); - void cleanup(); + virtual ~{{classname}}(); + void init(); + void cleanup(); - QString asJson (); - QJsonObject* asJsonObject(); - void fromJsonObject(QJsonObject &json); + QString asJson (); + QJsonObject* asJsonObject(); + void fromJsonObject(QJsonObject &json); {{classname}}* fromJson(QString &jsonString); {{#vars}}{{{datatype}}} {{getter}}(); - void {{setter}}({{{datatype}}} {{name}}); + void {{setter}}({{{datatype}}} {{name}}); {{/vars}} - private: +private: {{#vars}}{{{datatype}}} {{name}}; {{/vars}} - }; +}; - } /* namespace Swagger */ +} /* namespace Swagger */ - #endif /* {{classname}}_H_ */ +#endif /* {{classname}}_H_ */ {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/model.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/model.mustache index de2eb05066a..1a2a831f5ac 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/model.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/model.mustache @@ -1,62 +1,58 @@ {{#models}}{{#model}}/* -* {{classname}}.h -* -* {{description}} -*/ + * {{classname}}.h + * + * {{description}} + */ #ifndef {{classname}}_H_ #define {{classname}}_H_ -#include - - #include - - #include - - #include - - #include "{{prefix}}Helpers.h" - #include "{{prefix}}Object.h" +#include +#include +#include +#include +#include "{{prefix}}Helpers.h" +#include "{{prefix}}Object.h" - using namespace Tizen::Web::Json; +using namespace Tizen::Web::Json; {{/model}}{{/models}} {{#imports}}{{{import}}} {{/imports}} {{#models}}{{#model}} - namespace Swagger { +namespace Swagger { - class {{classname}}: public {{prefix}}Object { - public: +class {{classname}}: public {{prefix}}Object { +public: {{classname}}(); {{classname}}(String* json); - virtual ~{{classname}}(); + virtual ~{{classname}}(); - void init(); + void init(); - void cleanup(); + void cleanup(); - String asJson (); + String asJson (); - JsonObject* asJsonObject(); + JsonObject* asJsonObject(); - void fromJsonObject(IJsonValue* json); + void fromJsonObject(IJsonValue* json); {{classname}}* fromJson(String* obj); {{#vars}} - {{datatype}} {{getter}}(); - void {{setter}}({{datatype}} {{name}}); + {{datatype}} {{getter}}(); + void {{setter}}({{datatype}} {{name}}); {{/vars}} - private: +private: {{#vars}}{{datatype}} {{name}}; {{/vars}} - }; +}; - } /* namespace Swagger */ +} /* namespace Swagger */ - #endif /* {{classname}}_H_ */ +#endif /* {{classname}}_H_ */ {{/model}} {{/models}} diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache index 3a29a7ad1f5..4ec9e6f7411 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/modelFactory.mustache @@ -2,29 +2,28 @@ #define ModelFactory_H_ {{#models}}{{#model}} - #include "{{classname}}.h"{{/model}}{{/models}} +#include "{{classname}}.h"{{/model}}{{/models}} namespace Swagger { -inline void* create(QString type) { -{{#models}}{{#model}}if(QString("{{classname}}").compare(type) == 0) { -return new {{classname}}(); -} -{{/model}}{{/models}} -return NULL; -} + inline void* create(QString type) { + {{#models}}{{#model}}if(QString("{{classname}}").compare(type) == 0) { + return new {{classname}}(); + } + {{/model}}{{/models}} + return NULL; + } -inline void* create(QString json, QString type) { -void* val = create(type); -if(val != NULL) { -SWGObject* obj = static_cast -(val); -return obj->fromJson(json); -} -if(type.startsWith("QString")) { -return new QString(); -} -return NULL; -} + inline void* create(QString json, QString type) { + void* val = create(type); + if(val != NULL) { + SWGObject* obj = static_cast(val); + return obj->fromJson(json); + } + if(type.startsWith("QString")) { + return new QString(); + } + return NULL; + } } /* namespace Swagger */ #endif /* ModelFactory_H_ */ diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache index f4194b68578..62914cb5162 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/object.mustache @@ -1,25 +1,24 @@ #ifndef _{{prefix}}_OBJECT_H_ #define _{{prefix}}_OBJECT_H_ -#include - +#include - class {{prefix}}Object { - public: +class {{prefix}}Object { + public: virtual QJsonObject* asJsonObject() { - return NULL; + return NULL; } virtual ~SWGObject() {} virtual SWGObject* fromJson(QString &jsonString) { - Q_UNUSED(jsonString); - return NULL; + Q_UNUSED(jsonString); + return NULL; } virtual void fromJsonObject(QJsonObject &json) { - Q_UNUSED(json); + Q_UNUSED(json); } virtual QString asJson() { - return QString(""); + return QString(""); } - }; +}; - #endif /* _{{prefix}}_OBJECT_H_ */ +#endif /* _{{prefix}}_OBJECT_H_ */