roll back qt5cpp template

This commit is contained in:
wing328 2015-06-09 12:42:07 +08:00
parent 263b4080ee
commit 6253bbff3d
9 changed files with 454 additions and 512 deletions

View File

@ -2,186 +2,180 @@
#include "{{prefix}}Helpers.h"
#include "{{prefix}}ModelFactory.h"
#include
<QJsonArray>
#include
<QJsonDocument>
#include <QJsonArray>
#include <QJsonDocument>
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<void*>*){{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
<void
*>*){{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 */

View File

@ -6,15 +6,14 @@
{{#imports}}{{{import}}}
{{/imports}}
#include
<QObject>
#include <QObject>
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
};
}
#endif

View File

@ -1,201 +1,166 @@
#include "SWGHelpers.h"
#include "SWGModelFactory.h"
#include "SWGObject.h"
#import
<QDebug>
#import
<QJsonArray>
#import
<QJsonValue>
#import <QDebug>
#import <QJsonArray>
#import <QJsonValue>
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
<bool
*>(value);
*val = obj.toBool();
}
else if(QStringLiteral("qint32").compare(type) == 0) {
qint32 *val = static_cast
<qint32
*>(value);
*val = obj.toInt();
}
else if(QStringLiteral("qint64").compare(type) == 0) {
qint64 *val = static_cast
<qint64
*>(value);
*val = obj.toVariant().toLongLong();
}
else if (QStringLiteral("QString").compare(type) == 0) {
QString **val = static_cast
<QString
**>(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<bool*>(value);
*val = obj.toBool();
}
else if(QStringLiteral("qint32").compare(type) == 0) {
qint32 *val = static_cast<qint32*>(value);
*val = obj.toInt();
}
else if(QStringLiteral("qint64").compare(type) == 0) {
qint64 *val = static_cast<qint64*>(value);
*val = obj.toVariant().toLongLong();
}
else if (QStringLiteral("QString").compare(type) == 0) {
QString **val = static_cast<QString**>(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
<SWGObject
**>(value);
SWGObject **val = static_cast<SWGObject**>(value);
delete *val;
*val = so;
}
}
else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) {
// list of values
QList
<void
*>* output = new QList
<void
*>();
QJsonArray arr = obj.toArray();
foreach (const QJsonValue & jval, arr) {
}
}
else if(type.startsWith("QList") && QString("").compare(complexType) != 0 && obj.isArray()) {
// list of values
QList<void*>* output = new QList<void*>();
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
<void
*> **val = static_cast
<QList
<void
*>**>(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<void*> **val = static_cast<QList<void*>**>(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
<SWGObject *>(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<SWGObject *>(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
<QString
*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("qint32").compare(type) == 0) {
qint32* str = static_cast
<qint32
*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("qint64").compare(type) == 0) {
qint64* str = static_cast
<qint64
*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("bool").compare(type) == 0) {
bool* str = static_cast
<bool
*>(value);
output->insert(name, QJsonValue(*str));
}
output->insert(key, o->value(key));
}
}
}
}
else if(QStringLiteral("QString").compare(type) == 0) {
QString* str = static_cast<QString*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("qint32").compare(type) == 0) {
qint32* str = static_cast<qint32*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("qint64").compare(type) == 0) {
qint64* str = static_cast<qint64*>(value);
output->insert(name, QJsonValue(*str));
}
else if(QStringLiteral("bool").compare(type) == 0) {
bool* str = static_cast<bool*>(value);
output->insert(name, QJsonValue(*str));
}
}
void
toJsonArray(QList
<void
*>* value, QJsonArray* output, QString innerName, QString innerType) {
foreach(void* obj, *value) {
QJsonObject element;
void
toJsonArray(QList<void*>* 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
<QString
*>(value);
return QString(*str);
}
QString
stringValue(QString* value) {
QString* str = static_cast<QString*>(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 */

View File

@ -1,20 +1,17 @@
#ifndef SWGHELPERS_H
#define SWGHELPERS_H
#include
<QJsonValue>
#include <QJsonValue>
namespace Swagger {
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, 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

View File

@ -1,114 +1,109 @@
{{#models}}{{#model}}
#include "{{classname}}.h"
#include "{{classname}}.h"
#include "SWGHelpers.h"
#include "SWGHelpers.h"
#include
<QJsonDocument>
#include
<QJsonArray>
#include
<QObject>
#include
<QDebug>
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
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
<void*>*){{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<void*>*){{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}}

View File

@ -1,48 +1,47 @@
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
#include
<QJsonObject>
#include <QJsonObject>
{{/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}}

View File

@ -1,62 +1,58 @@
{{#models}}{{#model}}/*
* {{classname}}.h
*
* {{description}}
*/
* {{classname}}.h
*
* {{description}}
*/
#ifndef {{classname}}_H_
#define {{classname}}_H_
#include
<FApp.h>
#include
<FBase.h>
#include
<FSystem.h>
#include
<FWebJson.h>
#include "{{prefix}}Helpers.h"
#include "{{prefix}}Object.h"
#include <FApp.h>
#include <FBase.h>
#include <FSystem.h>
#include <FWebJson.h>
#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}}

View File

@ -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
<SWGObject*>(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<SWGObject*>(val);
return obj->fromJson(json);
}
if(type.startsWith("QString")) {
return new QString();
}
return NULL;
}
} /* namespace Swagger */
#endif /* ModelFactory_H_ */

View File

@ -1,25 +1,24 @@
#ifndef _{{prefix}}_OBJECT_H_
#define _{{prefix}}_OBJECT_H_
#include
<QJsonValue>
#include <QJsonValue>
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_ */