added qt5 samples, script

This commit is contained in:
Tony Tam 2015-05-12 06:04:10 -04:00
parent c2ee64e669
commit 037a00720f
23 changed files with 2976 additions and 0 deletions

31
bin/qt5-petstore.sh Executable file
View File

@ -0,0 +1,31 @@
#!/bin/sh
SCRIPT="$0"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/swagger-codegen-cli/target/swagger-codegen-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -i modules/swagger-codegen/src/test/resources/2_0/petstore.json -l qt5cpp -o samples/client/petstore/qt5cpp"
java $JAVA_OPTS -jar $executable $ags

View File

@ -0,0 +1,105 @@
#include "SWGCategory.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGCategory::SWGCategory(QString* json) {
init();
this->fromJson(*json);
}
SWGCategory::SWGCategory() {
init();
}
SWGCategory::~SWGCategory() {
this->cleanup();
}
void
SWGCategory::init() {
id = 0L;
name = new QString("");
}
void
SWGCategory::cleanup() {
if(name != NULL) {
delete name;
}
}
SWGCategory*
SWGCategory::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGCategory::fromJsonObject(QJsonObject &pJson) {
setValue(&id, pJson["id"], "qint64", "");
setValue(&name, pJson["name"], "QString", "QString");
}
QString
SWGCategory::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGCategory::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("id", QJsonValue(id));
toJsonValue(QString("name"), name, obj, QString("QString"));
return obj;
}
qint64
SWGCategory::getId() {
return id;
}
void
SWGCategory::setId(qint64 id) {
this->id = id;
}
QString*
SWGCategory::getName() {
return name;
}
void
SWGCategory::setName(QString* name) {
this->name = name;
}
} /* namespace Swagger */

View File

@ -0,0 +1,47 @@
/*
* SWGCategory.h
*
*
*/
#ifndef SWGCategory_H_
#define SWGCategory_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGCategory: public SWGObject {
public:
SWGCategory();
SWGCategory(QString* json);
virtual ~SWGCategory();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGCategory* fromJson(QString &jsonString);
qint64 getId();
void setId(qint64 id);
QString* getName();
void setName(QString* name);
private:
qint64 id;
QString* name;
};
} /* namespace Swagger */
#endif /* SWGCategory_H_ */

View File

@ -0,0 +1,161 @@
#include "SWGHelpers.h"
#include "SWGModelFactory.h"
#include "SWGObject.h"
#import <QDebug>
#import <QJsonArray>
#import <QJsonValue>
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);
if(val != NULL) {
if(!obj.isNull()) {
// create a new value and return
delete *val;
*val = new QString(obj.toString());
return;
}
else {
// set target to NULL
delete *val;
*val = NULL;
}
}
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) {
so->fromJsonObject(jsonObj);
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) {
if(complexType.startsWith("SWG")) {
// it's an object
SWGObject * val = (SWGObject*)create(complexType);
QJsonObject t = jval.toObject();
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;
}
}
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 {
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));
}
}
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);
}
}
QString
stringValue(QString* value) {
QString* str = static_cast<QString*>(value);
return QString(*str);
}
QString
stringValue(qint32 value) {
return QString::number(value);
}
QString
stringValue(bool value) {
return QString(value ? "true" : "false");
}
} /* namespace Swagger */

View File

@ -0,0 +1,16 @@
#ifndef SWGHELPERS_H
#define SWGHELPERS_H
#include <QJsonValue>
namespace Swagger {
void setValue(void* value, QJsonValue obj, QString type, QString complexType);
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(bool value);
}
#endif // SWGHELPERS_H

View File

@ -0,0 +1,297 @@
#include "SWGHttpRequest.h"
#include <QDateTime>
#include <QUrl>
#include <QFileInfo>
#include <QBuffer>
HttpRequestInput::HttpRequestInput() {
initialize();
}
HttpRequestInput::HttpRequestInput(QString v_url_str, QString v_http_method) {
initialize();
url_str = v_url_str;
http_method = v_http_method;
}
void HttpRequestInput::initialize() {
var_layout = NOT_SET;
url_str = "";
http_method = "GET";
}
void HttpRequestInput::add_var(QString key, QString value) {
vars[key] = value;
}
void HttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
HttpRequestInputFileElement file;
file.variable_name = variable_name;
file.local_filename = local_filename;
file.request_filename = request_filename;
file.mime_type = mime_type;
files.append(file);
}
HttpRequestWorker::HttpRequestWorker(QObject *parent)
: QObject(parent), manager(NULL)
{
qsrand(QDateTime::currentDateTime().toTime_t());
manager = new QNetworkAccessManager(this);
connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(on_manager_finished(QNetworkReply*)));
}
HttpRequestWorker::~HttpRequestWorker() {
}
QString HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
// result structure follows RFC 5987
bool need_utf_encoding = false;
QString result = "";
QByteArray input_c = input.toLocal8Bit();
char c;
for (int i = 0; i < input_c.length(); i++) {
c = input_c.at(i);
if (c == '\\' || c == '/' || c == '\0' || c < ' ' || c > '~') {
// ignore and request utf-8 version
need_utf_encoding = true;
}
else if (c == '"') {
result += "\\\"";
}
else {
result += c;
}
}
if (result.length() == 0) {
need_utf_encoding = true;
}
if (!need_utf_encoding) {
// return simple version
return QString("%1=\"%2\"").arg(attribute_name, result);
}
QString result_utf8 = "";
for (int i = 0; i < input_c.length(); i++) {
c = input_c.at(i);
if (
(c >= '0' && c <= '9')
|| (c >= 'A' && c <= 'Z')
|| (c >= 'a' && c <= 'z')
) {
result_utf8 += c;
}
else {
result_utf8 += "%" + QString::number(static_cast<unsigned char>(input_c.at(i)), 16).toUpper();
}
}
// return enhanced version with UTF-8 support
return QString("%1=\"%2\"; %1*=utf-8''%3").arg(attribute_name, result, result_utf8);
}
void HttpRequestWorker::execute(HttpRequestInput *input) {
// reset variables
QByteArray request_content = "";
response = "";
error_type = QNetworkReply::NoError;
error_str = "";
// decide on the variable layout
if (input->files.length() > 0) {
input->var_layout = MULTIPART;
}
if (input->var_layout == NOT_SET) {
input->var_layout = input->http_method == "GET" || input->http_method == "HEAD" ? ADDRESS : URL_ENCODED;
}
// prepare request content
QString boundary = "";
if (input->var_layout == ADDRESS || input->var_layout == URL_ENCODED) {
// variable layout is ADDRESS or URL_ENCODED
if (input->vars.count() > 0) {
bool first = true;
foreach (QString key, input->vars.keys()) {
if (!first) {
request_content.append("&");
}
first = false;
request_content.append(QUrl::toPercentEncoding(key));
request_content.append("=");
request_content.append(QUrl::toPercentEncoding(input->vars.value(key)));
}
if (input->var_layout == ADDRESS) {
input->url_str += "?" + request_content;
request_content = "";
}
}
}
else {
// variable layout is MULTIPART
boundary = "__-----------------------"
+ QString::number(QDateTime::currentDateTime().toTime_t())
+ QString::number(qrand());
QString boundary_delimiter = "--";
QString new_line = "\r\n";
// add variables
foreach (QString key, input->vars.keys()) {
// add boundary
request_content.append(boundary_delimiter);
request_content.append(boundary);
request_content.append(new_line);
// add header
request_content.append("Content-Disposition: form-data; ");
request_content.append(http_attribute_encode("name", key));
request_content.append(new_line);
request_content.append("Content-Type: text/plain");
request_content.append(new_line);
// add header to body splitter
request_content.append(new_line);
// add variable content
request_content.append(input->vars.value(key));
request_content.append(new_line);
}
// add files
for (QList<HttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
QFileInfo fi(file_info->local_filename);
// ensure necessary variables are available
if (
file_info->local_filename == NULL || file_info->local_filename.isEmpty()
|| file_info->variable_name == NULL || file_info->variable_name.isEmpty()
|| !fi.exists() || !fi.isFile() || !fi.isReadable()
) {
// silent abort for the current file
continue;
}
QFile file(file_info->local_filename);
if (!file.open(QIODevice::ReadOnly)) {
// silent abort for the current file
continue;
}
// ensure filename for the request
if (file_info->request_filename == NULL || file_info->request_filename.isEmpty()) {
file_info->request_filename = fi.fileName();
if (file_info->request_filename.isEmpty()) {
file_info->request_filename = "file";
}
}
// add boundary
request_content.append(boundary_delimiter);
request_content.append(boundary);
request_content.append(new_line);
// add header
request_content.append(QString("Content-Disposition: form-data; %1; %2").arg(
http_attribute_encode("name", file_info->variable_name),
http_attribute_encode("filename", file_info->request_filename)
));
request_content.append(new_line);
if (file_info->mime_type != NULL && !file_info->mime_type.isEmpty()) {
request_content.append("Content-Type: ");
request_content.append(file_info->mime_type);
request_content.append(new_line);
}
request_content.append("Content-Transfer-Encoding: binary");
request_content.append(new_line);
// add header to body splitter
request_content.append(new_line);
// add file content
request_content.append(file.readAll());
request_content.append(new_line);
file.close();
}
// add end of body
request_content.append(boundary_delimiter);
request_content.append(boundary);
request_content.append(boundary_delimiter);
}
if(input->request_body.size() > 0) {
qDebug() << "got a request body";
request_content.clear();
request_content.append(input->request_body);
}
// prepare connection
QNetworkRequest request = QNetworkRequest(QUrl(input->url_str));
request.setRawHeader("User-Agent", "Swagger-Client");
foreach(QString key, input->headers.keys()) {
request.setRawHeader(key.toStdString().c_str(), input->headers.value(key).toStdString().c_str());
}
if (request_content.size() > 0) {
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/json");
}
else if (input->var_layout == URL_ENCODED) {
request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded");
}
else if (input->var_layout == MULTIPART) {
request.setHeader(QNetworkRequest::ContentTypeHeader, "multipart/form-data; boundary=" + boundary);
}
if (input->http_method == "GET") {
manager->get(request);
}
else if (input->http_method == "POST") {
manager->post(request, request_content);
}
else if (input->http_method == "PUT") {
manager->put(request, request_content);
}
else if (input->http_method == "HEAD") {
manager->head(request);
}
else if (input->http_method == "DELETE") {
manager->deleteResource(request);
}
else {
QBuffer buff(&request_content);
manager->sendCustomRequest(request, input->http_method.toLatin1(), &buff);
}
}
void HttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
error_type = reply->error();
if (error_type == QNetworkReply::NoError) {
response = reply->readAll();
}
else {
error_str = reply->errorString();
}
reply->deleteLater();
emit on_execution_finished(this);
}

View File

@ -0,0 +1,76 @@
/**
* Based on http://www.creativepulse.gr/en/blog/2014/restful-api-requests-using-qt-cpp-for-linux-mac-osx-ms-windows
* By Alex Stylianos
*
**/
#ifndef HTTPREQUESTWORKER_H
#define HTTPREQUESTWORKER_H
#include <QObject>
#include <QString>
#include <QMap>
#include <QNetworkAccessManager>
#include <QNetworkReply>
enum HttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
class HttpRequestInputFileElement {
public:
QString variable_name;
QString local_filename;
QString request_filename;
QString mime_type;
};
class HttpRequestInput {
public:
QString url_str;
QString http_method;
HttpRequestVarLayout var_layout;
QMap<QString, QString> vars;
QMap<QString, QString> headers;
QList<HttpRequestInputFileElement> files;
QByteArray request_body;
HttpRequestInput();
HttpRequestInput(QString v_url_str, QString v_http_method);
void initialize();
void add_var(QString key, QString value);
void add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type);
};
class HttpRequestWorker : public QObject {
Q_OBJECT
public:
QByteArray response;
QNetworkReply::NetworkError error_type;
QString error_str;
explicit HttpRequestWorker(QObject *parent = 0);
virtual ~HttpRequestWorker();
QString http_attribute_encode(QString attribute_name, QString input);
void execute(HttpRequestInput *input);
signals:
void on_execution_finished(HttpRequestWorker *worker);
private:
QNetworkAccessManager *manager;
private slots:
void on_manager_finished(QNetworkReply *reply);
};
#endif // HTTPREQUESTWORKER_H

View File

@ -0,0 +1,34 @@
#ifndef ModelFactory_H_
#define ModelFactory_H_
#include "SWGUser.h"
#include "SWGCategory.h"
#include "SWGPet.h"
#include "SWGTag.h"
#include "SWGOrder.h"
namespace Swagger {
void*
create(QString type) {
if(QString("SWGUser").compare(type) == 0) {
return new SWGUser();
}
if(QString("SWGCategory").compare(type) == 0) {
return new SWGCategory();
}
if(QString("SWGPet").compare(type) == 0) {
return new SWGPet();
}
if(QString("SWGTag").compare(type) == 0) {
return new SWGTag();
}
if(QString("SWGOrder").compare(type) == 0) {
return new SWGOrder();
}
return NULL;
}
} /* namespace Swagger */
#endif /* ModelFactory_H_ */

View File

@ -0,0 +1,24 @@
#ifndef _SWG_OBJECT_H_
#define _SWG_OBJECT_H_
#include <QJsonValue>
class SWGObject {
public:
virtual QJsonObject* asJsonObject() {
return NULL;
}
virtual ~SWGObject() {}
virtual SWGObject* fromJson(QString &jsonString) {
Q_UNUSED(jsonString);
return NULL;
}
virtual void fromJsonObject(QJsonObject &json) {
Q_UNUSED(json);
}
virtual QString asJson() {
return QString("");
}
};
#endif /* _SWG_OBJECT_H_ */

View File

@ -0,0 +1,164 @@
#include "SWGOrder.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGOrder::SWGOrder(QString* json) {
init();
this->fromJson(*json);
}
SWGOrder::SWGOrder() {
init();
}
SWGOrder::~SWGOrder() {
this->cleanup();
}
void
SWGOrder::init() {
id = 0L;
petId = 0L;
quantity = 0;
shipDate = NULL;
status = new QString("");
complete = false;
}
void
SWGOrder::cleanup() {
if(shipDate != NULL) {
delete shipDate;
}
if(status != NULL) {
delete status;
}
}
SWGOrder*
SWGOrder::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGOrder::fromJsonObject(QJsonObject &pJson) {
setValue(&id, pJson["id"], "qint64", "");
setValue(&petId, pJson["petId"], "qint64", "");
setValue(&quantity, pJson["quantity"], "qint32", "");
setValue(&shipDate, pJson["shipDate"], "QDateTime", "QDateTime");
setValue(&status, pJson["status"], "QString", "QString");
setValue(&complete, pJson["complete"], "bool", "");
}
QString
SWGOrder::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGOrder::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("id", QJsonValue(id));
obj->insert("petId", QJsonValue(petId));
obj->insert("quantity", QJsonValue(quantity));
toJsonValue(QString("shipDate"), shipDate, obj, QString("QDateTime"));
toJsonValue(QString("status"), status, obj, QString("QString"));
obj->insert("complete", QJsonValue(complete));
return obj;
}
qint64
SWGOrder::getId() {
return id;
}
void
SWGOrder::setId(qint64 id) {
this->id = id;
}
qint64
SWGOrder::getPetId() {
return petId;
}
void
SWGOrder::setPetId(qint64 petId) {
this->petId = petId;
}
qint32
SWGOrder::getQuantity() {
return quantity;
}
void
SWGOrder::setQuantity(qint32 quantity) {
this->quantity = quantity;
}
QDateTime*
SWGOrder::getShipDate() {
return shipDate;
}
void
SWGOrder::setShipDate(QDateTime* shipDate) {
this->shipDate = shipDate;
}
QString*
SWGOrder::getStatus() {
return status;
}
void
SWGOrder::setStatus(QString* status) {
this->status = status;
}
bool
SWGOrder::getComplete() {
return complete;
}
void
SWGOrder::setComplete(bool complete) {
this->complete = complete;
}
} /* namespace Swagger */

View File

@ -0,0 +1,60 @@
/*
* SWGOrder.h
*
*
*/
#ifndef SWGOrder_H_
#define SWGOrder_H_
#include <QJsonObject>
#include "QDateTime.h"
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGOrder: public SWGObject {
public:
SWGOrder();
SWGOrder(QString* json);
virtual ~SWGOrder();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGOrder* fromJson(QString &jsonString);
qint64 getId();
void setId(qint64 id);
qint64 getPetId();
void setPetId(qint64 petId);
qint32 getQuantity();
void setQuantity(qint32 quantity);
QDateTime* getShipDate();
void setShipDate(QDateTime* shipDate);
QString* getStatus();
void setStatus(QString* status);
bool getComplete();
void setComplete(bool complete);
private:
qint64 id;
qint64 petId;
qint32 quantity;
QDateTime* shipDate;
QString* status;
bool complete;
};
} /* namespace Swagger */
#endif /* SWGOrder_H_ */

View File

@ -0,0 +1,199 @@
#include "SWGPet.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGPet::SWGPet(QString* json) {
init();
this->fromJson(*json);
}
SWGPet::SWGPet() {
init();
}
SWGPet::~SWGPet() {
this->cleanup();
}
void
SWGPet::init() {
id = 0L;
category = new SWGCategory();
name = new QString("");
photoUrls = new QList<QString*>();
tags = new QList<SWGTag*>();
status = new QString("");
}
void
SWGPet::cleanup() {
if(category != NULL) {
delete category;
}
if(name != NULL) {
delete name;
}
if(photoUrls != NULL) {
QList<QString*>* arr = photoUrls;
foreach(QString* o, *arr) {
delete o;
}
delete photoUrls;
}
if(tags != NULL) {
QList<SWGTag*>* arr = tags;
foreach(SWGTag* o, *arr) {
delete o;
}
delete tags;
}
if(status != NULL) {
delete status;
}
}
SWGPet*
SWGPet::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGPet::fromJsonObject(QJsonObject &pJson) {
setValue(&id, pJson["id"], "qint64", "");
setValue(&category, pJson["category"], "SWGCategory", "SWGCategory");
setValue(&name, pJson["name"], "QString", "QString");
setValue(&photoUrls, pJson["photoUrls"], "QList", "QString");
setValue(&tags, pJson["tags"], "QList", "SWGTag");
setValue(&status, pJson["status"], "QString", "QString");
}
QString
SWGPet::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGPet::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("id", QJsonValue(id));
toJsonValue(QString("category"), category, obj, QString("SWGCategory"));
toJsonValue(QString("name"), name, obj, QString("QString"));
QList<QString*>* photoUrlsList = photoUrls;
QJsonArray photoUrlsJsonArray;
toJsonArray((QList<void*>*)photoUrls, &photoUrlsJsonArray, "photoUrls", "QString");
obj->insert("photoUrls", photoUrlsJsonArray);
QList<SWGTag*>* tagsList = tags;
QJsonArray tagsJsonArray;
toJsonArray((QList<void*>*)tags, &tagsJsonArray, "tags", "SWGTag");
obj->insert("tags", tagsJsonArray);
toJsonValue(QString("status"), status, obj, QString("QString"));
return obj;
}
qint64
SWGPet::getId() {
return id;
}
void
SWGPet::setId(qint64 id) {
this->id = id;
}
SWGCategory*
SWGPet::getCategory() {
return category;
}
void
SWGPet::setCategory(SWGCategory* category) {
this->category = category;
}
QString*
SWGPet::getName() {
return name;
}
void
SWGPet::setName(QString* name) {
this->name = name;
}
QList<QString*>*
SWGPet::getPhotoUrls() {
return photoUrls;
}
void
SWGPet::setPhotoUrls(QList<QString*>* photoUrls) {
this->photoUrls = photoUrls;
}
QList<SWGTag*>*
SWGPet::getTags() {
return tags;
}
void
SWGPet::setTags(QList<SWGTag*>* tags) {
this->tags = tags;
}
QString*
SWGPet::getStatus() {
return status;
}
void
SWGPet::setStatus(QString* status) {
this->status = status;
}
} /* namespace Swagger */

View File

@ -0,0 +1,62 @@
/*
* SWGPet.h
*
*
*/
#ifndef SWGPet_H_
#define SWGPet_H_
#include <QJsonObject>
#include "SWGTag.h"
#include <QList>
#include "SWGCategory.h"
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGPet: public SWGObject {
public:
SWGPet();
SWGPet(QString* json);
virtual ~SWGPet();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGPet* fromJson(QString &jsonString);
qint64 getId();
void setId(qint64 id);
SWGCategory* getCategory();
void setCategory(SWGCategory* category);
QString* getName();
void setName(QString* name);
QList<QString*>* getPhotoUrls();
void setPhotoUrls(QList<QString*>* photoUrls);
QList<SWGTag*>* getTags();
void setTags(QList<SWGTag*>* tags);
QString* getStatus();
void setStatus(QString* status);
private:
qint64 id;
SWGCategory* category;
QString* name;
QList<QString*>* photoUrls;
QList<SWGTag*>* tags;
QString* status;
};
} /* namespace Swagger */
#endif /* SWGPet_H_ */

View File

@ -0,0 +1,455 @@
#include "SWGPetApi.h"
#include "SWGHelpers.h"
#include <QJsonArray>
#include <QJsonDocument>
namespace Swagger {
SWGPetApi::SWGPetApi() {}
SWGPetApi::~SWGPetApi() {}
SWGPetApi::SWGPetApi(QString host, QString basePath) {
this->host = host;
this->basePath = basePath;
}
void
SWGPetApi::updatePet(SWGPet body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "PUT");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::updatePetCallback);
worker->execute(&input);
}
void
SWGPetApi::updatePetCallback(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;
}
// return type:
worker->deleteLater();
emit updatePetSignal();
}
void
SWGPetApi::addPet(SWGPet body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::addPetCallback);
worker->execute(&input);
}
void
SWGPetApi::addPetCallback(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;
}
// return type:
worker->deleteLater();
emit addPetSignal();
}
void
SWGPetApi::findPetsByStatus(QList&lt;QString*&gt;* status) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/findByStatus");
if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
fullPath.append(QUrl::toPercentEncoding("status"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(status)));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::findPetsByStatusCallback);
worker->execute(&input);
}
void
SWGPetApi::findPetsByStatusCallback(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;
}
// return type: QList<SWGPet*>*
QList<SWGPet*>* output = new QList<SWGPet*>();
QString json(worker->response);
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonArray jsonArray = doc.array();
foreach(QJsonValue obj, jsonArray) {
SWGPet* o = new SWGPet();
QJsonObject jv = obj.toObject();
QJsonObject * ptr = (QJsonObject*)&jv;
o->fromJsonObject(*ptr);
output->append(o);
}
// void toJsonArray(QList<void*>* value, QJsonArray* output, QString innerName, QString innerType);
worker->deleteLater();
emit findPetsByStatusSignal(output);
}
void
SWGPetApi::findPetsByTags(QList&lt;QString*&gt;* tags) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/findByTags");
if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
fullPath.append(QUrl::toPercentEncoding("tags"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(tags)));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::findPetsByTagsCallback);
worker->execute(&input);
}
void
SWGPetApi::findPetsByTagsCallback(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;
}
// return type: QList<SWGPet*>*
QList<SWGPet*>* output = new QList<SWGPet*>();
QString json(worker->response);
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonArray jsonArray = doc.array();
foreach(QJsonValue obj, jsonArray) {
SWGPet* o = new SWGPet();
QJsonObject jv = obj.toObject();
QJsonObject * ptr = (QJsonObject*)&jv;
o->fromJsonObject(*ptr);
output->append(o);
}
// void toJsonArray(QList<void*>* value, QJsonArray* output, QString innerName, QString innerType);
worker->deleteLater();
emit findPetsByTagsSignal(output);
}
void
SWGPetApi::getPetById(qint64 petId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::getPetByIdCallback);
worker->execute(&input);
}
void
SWGPetApi::getPetByIdCallback(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;
}
// return type: SWGPet*
QString json(worker->response);
SWGPet* output = new SWGPet(&json);
worker->deleteLater();
emit getPetByIdSignal(output);
}
void
SWGPetApi::updatePetWithForm(QString* petId, QString* name, QString* status) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::updatePetWithFormCallback);
worker->execute(&input);
}
void
SWGPetApi::updatePetWithFormCallback(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;
}
// return type:
worker->deleteLater();
emit updatePetWithFormSignal();
}
void
SWGPetApi::deletePet(QString* api_key, qint64 petId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
input.headers
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::deletePetCallback);
worker->execute(&input);
}
void
SWGPetApi::deletePetCallback(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;
}
// return type:
worker->deleteLater();
emit deletePetSignal();
}
void
SWGPetApi::uploadFile(qint64 petId, QString* additionalMetadata, SWGFile* file) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGPetApi::uploadFileCallback);
worker->execute(&input);
}
void
SWGPetApi::uploadFileCallback(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;
}
// return type:
worker->deleteLater();
emit uploadFileSignal();
}
} /* namespace Swagger */

View File

@ -0,0 +1,56 @@
#ifndef _SWG_SWGPetApi_H_
#define _SWG_SWGPetApi_H_
#include "SWGHttpRequest.h"
#include "SWGPet.h"
#include <QString>
#include "SWGFile.h"
#include <QObject>
namespace Swagger {
class SWGPetApi: public QObject {
Q_OBJECT
public:
SWGPetApi();
SWGPetApi(QString host, QString basePath);
~SWGPetApi();
QString host;
QString basePath;
void updatePet(SWGPet body);
void addPet(SWGPet body);
void findPetsByStatus(QList&lt;QString*&gt;* status);
void findPetsByTags(QList&lt;QString*&gt;* tags);
void getPetById(qint64 petId);
void updatePetWithForm(QString* petId, QString* name, QString* status);
void deletePet(QString* api_key, qint64 petId);
void uploadFile(qint64 petId, QString* additionalMetadata, SWGFile* file);
private:
void updatePetCallback (HttpRequestWorker * worker);
void addPetCallback (HttpRequestWorker * worker);
void findPetsByStatusCallback (HttpRequestWorker * worker);
void findPetsByTagsCallback (HttpRequestWorker * worker);
void getPetByIdCallback (HttpRequestWorker * worker);
void updatePetWithFormCallback (HttpRequestWorker * worker);
void deletePetCallback (HttpRequestWorker * worker);
void uploadFileCallback (HttpRequestWorker * worker);
signals:
void updatePetSignal();
void addPetSignal();
void findPetsByStatusSignal(QList<SWGPet*>* summary);
void findPetsByTagsSignal(QList<SWGPet*>* summary);
void getPetByIdSignal(SWGPet* summary);
void updatePetWithFormSignal();
void deletePetSignal();
void uploadFileSignal();
};
}
#endif

View File

@ -0,0 +1,230 @@
#include "SWGStoreApi.h"
#include "SWGHelpers.h"
#include <QJsonArray>
#include <QJsonDocument>
namespace Swagger {
SWGStoreApi::SWGStoreApi() {}
SWGStoreApi::~SWGStoreApi() {}
SWGStoreApi::SWGStoreApi(QString host, QString basePath) {
this->host = host;
this->basePath = basePath;
}
void
SWGStoreApi::getInventory() {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/inventory");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGStoreApi::getInventoryCallback);
worker->execute(&input);
}
void
SWGStoreApi::getInventoryCallback(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;
}
// return type: QMap<String, qint32>*
QString json(worker->response);
QMap&lt;String, qint32&gt;* output = new QMap(&json);
worker->deleteLater();
emit getInventorySignal(output);
}
void
SWGStoreApi::placeOrder(SWGOrder body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGStoreApi::placeOrderCallback);
worker->execute(&input);
}
void
SWGStoreApi::placeOrderCallback(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;
}
// return type: SWGOrder*
QString json(worker->response);
SWGOrder* output = new SWGOrder(&json);
worker->deleteLater();
emit placeOrderSignal(output);
}
void
SWGStoreApi::getOrderById(QString* orderId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}");
QString orderIdPathParam("{"); orderIdPathParam.append("orderId").append("}");
fullPath.replace(orderIdPathParam, stringValue(orderId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGStoreApi::getOrderByIdCallback);
worker->execute(&input);
}
void
SWGStoreApi::getOrderByIdCallback(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;
}
// return type: SWGOrder*
QString json(worker->response);
SWGOrder* output = new SWGOrder(&json);
worker->deleteLater();
emit getOrderByIdSignal(output);
}
void
SWGStoreApi::deleteOrder(QString* orderId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}");
QString orderIdPathParam("{"); orderIdPathParam.append("orderId").append("}");
fullPath.replace(orderIdPathParam, stringValue(orderId));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGStoreApi::deleteOrderCallback);
worker->execute(&input);
}
void
SWGStoreApi::deleteOrderCallback(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;
}
// return type:
worker->deleteLater();
emit deleteOrderSignal();
}
} /* namespace Swagger */

View File

@ -0,0 +1,44 @@
#ifndef _SWG_SWGStoreApi_H_
#define _SWG_SWGStoreApi_H_
#include "SWGHttpRequest.h"
#include "QMap.h"
#include "SWGOrder.h"
#include <QString>
#include <QObject>
namespace Swagger {
class SWGStoreApi: public QObject {
Q_OBJECT
public:
SWGStoreApi();
SWGStoreApi(QString host, QString basePath);
~SWGStoreApi();
QString host;
QString basePath;
void getInventory();
void placeOrder(SWGOrder body);
void getOrderById(QString* orderId);
void deleteOrder(QString* orderId);
private:
void getInventoryCallback (HttpRequestWorker * worker);
void placeOrderCallback (HttpRequestWorker * worker);
void getOrderByIdCallback (HttpRequestWorker * worker);
void deleteOrderCallback (HttpRequestWorker * worker);
signals:
void getInventorySignal(QMap<String, qint32>* summary);
void placeOrderSignal(SWGOrder* summary);
void getOrderByIdSignal(SWGOrder* summary);
void deleteOrderSignal();
};
}
#endif

View File

@ -0,0 +1,105 @@
#include "SWGTag.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGTag::SWGTag(QString* json) {
init();
this->fromJson(*json);
}
SWGTag::SWGTag() {
init();
}
SWGTag::~SWGTag() {
this->cleanup();
}
void
SWGTag::init() {
id = 0L;
name = new QString("");
}
void
SWGTag::cleanup() {
if(name != NULL) {
delete name;
}
}
SWGTag*
SWGTag::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGTag::fromJsonObject(QJsonObject &pJson) {
setValue(&id, pJson["id"], "qint64", "");
setValue(&name, pJson["name"], "QString", "QString");
}
QString
SWGTag::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGTag::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("id", QJsonValue(id));
toJsonValue(QString("name"), name, obj, QString("QString"));
return obj;
}
qint64
SWGTag::getId() {
return id;
}
void
SWGTag::setId(qint64 id) {
this->id = id;
}
QString*
SWGTag::getName() {
return name;
}
void
SWGTag::setName(QString* name) {
this->name = name;
}
} /* namespace Swagger */

View File

@ -0,0 +1,47 @@
/*
* SWGTag.h
*
*
*/
#ifndef SWGTag_H_
#define SWGTag_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGTag: public SWGObject {
public:
SWGTag();
SWGTag(QString* json);
virtual ~SWGTag();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGTag* fromJson(QString &jsonString);
qint64 getId();
void setId(qint64 id);
QString* getName();
void setName(QString* name);
private:
qint64 id;
QString* name;
};
} /* namespace Swagger */
#endif /* SWGTag_H_ */

View File

@ -0,0 +1,218 @@
#include "SWGUser.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGUser::SWGUser(QString* json) {
init();
this->fromJson(*json);
}
SWGUser::SWGUser() {
init();
}
SWGUser::~SWGUser() {
this->cleanup();
}
void
SWGUser::init() {
id = 0L;
username = new QString("");
firstName = new QString("");
lastName = new QString("");
email = new QString("");
password = new QString("");
phone = new QString("");
userStatus = 0;
}
void
SWGUser::cleanup() {
if(username != NULL) {
delete username;
}
if(firstName != NULL) {
delete firstName;
}
if(lastName != NULL) {
delete lastName;
}
if(email != NULL) {
delete email;
}
if(password != NULL) {
delete password;
}
if(phone != NULL) {
delete phone;
}
}
SWGUser*
SWGUser::fromJson(QString &json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGUser::fromJsonObject(QJsonObject &pJson) {
setValue(&id, pJson["id"], "qint64", "");
setValue(&username, pJson["username"], "QString", "QString");
setValue(&firstName, pJson["firstName"], "QString", "QString");
setValue(&lastName, pJson["lastName"], "QString", "QString");
setValue(&email, pJson["email"], "QString", "QString");
setValue(&password, pJson["password"], "QString", "QString");
setValue(&phone, pJson["phone"], "QString", "QString");
setValue(&userStatus, pJson["userStatus"], "qint32", "");
}
QString
SWGUser::asJson ()
{
QJsonObject* obj = this->asJsonObject();
QJsonDocument doc(*obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject*
SWGUser::asJsonObject() {
QJsonObject* obj = new QJsonObject();
obj->insert("id", QJsonValue(id));
toJsonValue(QString("username"), username, obj, QString("QString"));
toJsonValue(QString("firstName"), firstName, obj, QString("QString"));
toJsonValue(QString("lastName"), lastName, obj, QString("QString"));
toJsonValue(QString("email"), email, obj, QString("QString"));
toJsonValue(QString("password"), password, obj, QString("QString"));
toJsonValue(QString("phone"), phone, obj, QString("QString"));
obj->insert("userStatus", QJsonValue(userStatus));
return obj;
}
qint64
SWGUser::getId() {
return id;
}
void
SWGUser::setId(qint64 id) {
this->id = id;
}
QString*
SWGUser::getUsername() {
return username;
}
void
SWGUser::setUsername(QString* username) {
this->username = username;
}
QString*
SWGUser::getFirstName() {
return firstName;
}
void
SWGUser::setFirstName(QString* firstName) {
this->firstName = firstName;
}
QString*
SWGUser::getLastName() {
return lastName;
}
void
SWGUser::setLastName(QString* lastName) {
this->lastName = lastName;
}
QString*
SWGUser::getEmail() {
return email;
}
void
SWGUser::setEmail(QString* email) {
this->email = email;
}
QString*
SWGUser::getPassword() {
return password;
}
void
SWGUser::setPassword(QString* password) {
this->password = password;
}
QString*
SWGUser::getPhone() {
return phone;
}
void
SWGUser::setPhone(QString* phone) {
this->phone = phone;
}
qint32
SWGUser::getUserStatus() {
return userStatus;
}
void
SWGUser::setUserStatus(qint32 userStatus) {
this->userStatus = userStatus;
}
} /* namespace Swagger */

View File

@ -0,0 +1,65 @@
/*
* SWGUser.h
*
*
*/
#ifndef SWGUser_H_
#define SWGUser_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGUser: public SWGObject {
public:
SWGUser();
SWGUser(QString* json);
virtual ~SWGUser();
void init();
void cleanup();
QString asJson ();
QJsonObject* asJsonObject();
void fromJsonObject(QJsonObject &json);
SWGUser* fromJson(QString &jsonString);
qint64 getId();
void setId(qint64 id);
QString* getUsername();
void setUsername(QString* username);
QString* getFirstName();
void setFirstName(QString* firstName);
QString* getLastName();
void setLastName(QString* lastName);
QString* getEmail();
void setEmail(QString* email);
QString* getPassword();
void setPassword(QString* password);
QString* getPhone();
void setPhone(QString* phone);
qint32 getUserStatus();
void setUserStatus(qint32 userStatus);
private:
qint64 id;
QString* username;
QString* firstName;
QString* lastName;
QString* email;
QString* password;
QString* phone;
qint32 userStatus;
};
} /* namespace Swagger */
#endif /* SWGUser_H_ */

View File

@ -0,0 +1,424 @@
#include "SWGUserApi.h"
#include "SWGHelpers.h"
#include <QJsonArray>
#include <QJsonDocument>
namespace Swagger {
SWGUserApi::SWGUserApi() {}
SWGUserApi::~SWGUserApi() {}
SWGUserApi::SWGUserApi(QString host, QString basePath) {
this->host = host;
this->basePath = basePath;
}
void
SWGUserApi::createUser(SWGUser body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::createUserCallback);
worker->execute(&input);
}
void
SWGUserApi::createUserCallback(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;
}
// return type:
worker->deleteLater();
emit createUserSignal();
}
void
SWGUserApi::createUsersWithArrayInput(QList&lt;SWGUser*&gt;* body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithArray");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::createUsersWithArrayInputCallback);
worker->execute(&input);
}
void
SWGUserApi::createUsersWithArrayInputCallback(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;
}
// return type:
worker->deleteLater();
emit createUsersWithArrayInputSignal();
}
void
SWGUserApi::createUsersWithListInput(QList&lt;SWGUser*&gt;* body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithList");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::createUsersWithListInputCallback);
worker->execute(&input);
}
void
SWGUserApi::createUsersWithListInputCallback(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;
}
// return type:
worker->deleteLater();
emit createUsersWithListInputSignal();
}
void
SWGUserApi::loginUser(QString* username, QString* password) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/login");
if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
fullPath.append(QUrl::toPercentEncoding("username"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(username)));
if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
fullPath.append(QUrl::toPercentEncoding("password"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(password)));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::loginUserCallback);
worker->execute(&input);
}
void
SWGUserApi::loginUserCallback(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;
}
// return type: QString*
QString json(worker->response);
QString* output = new QString(&json);
worker->deleteLater();
emit loginUserSignal(output);
}
void
SWGUserApi::logoutUser() {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/logout");
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::logoutUserCallback);
worker->execute(&input);
}
void
SWGUserApi::logoutUserCallback(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;
}
// return type:
worker->deleteLater();
emit logoutUserSignal();
}
void
SWGUserApi::getUserByName(QString* username) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::getUserByNameCallback);
worker->execute(&input);
}
void
SWGUserApi::getUserByNameCallback(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;
}
// return type: SWGUser*
QString json(worker->response);
SWGUser* output = new SWGUser(&json);
worker->deleteLater();
emit getUserByNameSignal(output);
}
void
SWGUserApi::updateUser(QString* username, SWGUser body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "PUT");
// body
input.request_body.append(body.asJson());
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::updateUserCallback);
worker->execute(&input);
}
void
SWGUserApi::updateUserCallback(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;
}
// return type:
worker->deleteLater();
emit updateUserSignal();
}
void
SWGUserApi::deleteUser(QString* username) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
// qDebug() << fullPath;
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
&SWGUserApi::deleteUserCallback);
worker->execute(&input);
}
void
SWGUserApi::deleteUserCallback(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;
}
// return type:
worker->deleteLater();
emit deleteUserSignal();
}
} /* namespace Swagger */

View File

@ -0,0 +1,56 @@
#ifndef _SWG_SWGUserApi_H_
#define _SWG_SWGUserApi_H_
#include "SWGHttpRequest.h"
#include "SWGUser.h"
#include <QList>
#include <QString>
#include <QObject>
namespace Swagger {
class SWGUserApi: public QObject {
Q_OBJECT
public:
SWGUserApi();
SWGUserApi(QString host, QString basePath);
~SWGUserApi();
QString host;
QString basePath;
void createUser(SWGUser body);
void createUsersWithArrayInput(QList&lt;SWGUser*&gt;* body);
void createUsersWithListInput(QList&lt;SWGUser*&gt;* body);
void loginUser(QString* username, QString* password);
void logoutUser();
void getUserByName(QString* username);
void updateUser(QString* username, SWGUser body);
void deleteUser(QString* username);
private:
void createUserCallback (HttpRequestWorker * worker);
void createUsersWithArrayInputCallback (HttpRequestWorker * worker);
void createUsersWithListInputCallback (HttpRequestWorker * worker);
void loginUserCallback (HttpRequestWorker * worker);
void logoutUserCallback (HttpRequestWorker * worker);
void getUserByNameCallback (HttpRequestWorker * worker);
void updateUserCallback (HttpRequestWorker * worker);
void deleteUserCallback (HttpRequestWorker * worker);
signals:
void createUserSignal();
void createUsersWithArrayInputSignal();
void createUsersWithListInputSignal();
void loginUserSignal(QString* summary);
void logoutUserSignal();
void getUserByNameSignal(SWGUser* summary);
void updateUserSignal();
void deleteUserSignal();
};
}
#endif