template updates, tests

This commit is contained in:
Tony Tam 2015-05-15 11:27:03 -07:00
parent 622d883344
commit b4674d6fc5
23 changed files with 1088 additions and 153 deletions

View File

@ -26,6 +26,6 @@ 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"
ags="$@ generate -t modules/swagger-codegen/src/main/resources/qt5cpp -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

@ -130,11 +130,13 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
typeMapping.put("boolean", "bool");
typeMapping.put("array", "QList");
typeMapping.put("map", "QMap");
// typeMapping.put("number", "Long");
typeMapping.put("file", "SWGHttpRequestInputFileElement");
typeMapping.put("object", PREFIX + "Object");
importMapping = new HashMap<String, String>();
importMapping.put("SWGHttpRequestInputFileElement", "#include \"" + PREFIX + "HttpRequest.h\"");
namespaces = new HashMap<String, String> ();
foundationClasses.add("QString");
@ -210,7 +212,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
else if (p instanceof MapProperty) {
MapProperty mp = (MapProperty) p;
Property inner = mp.getAdditionalProperties();
return getSwaggerType(p) + "<String, " + getTypeDeclaration(inner) + ">*";
return getSwaggerType(p) + "<QString, " + getTypeDeclaration(inner) + ">*";
}
if(foundationClasses.contains(swaggerType))
return swaggerType + "*";
@ -243,7 +245,7 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig {
else if (p instanceof MapProperty) {
MapProperty ap = (MapProperty) p;
String inner = getSwaggerType(ap.getAdditionalProperties());
return "NULL";
return "new QMap<QString, " + inner + ">()";
}
else if (p instanceof ArrayProperty) {
ArrayProperty ap = (ArrayProperty) p;

View File

@ -26,7 +26,7 @@ void HttpRequestInput::add_var(QString key, QString value) {
}
void HttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
HttpRequestInputFileElement file;
SWGHttpRequestInputFileElement file;
file.variable_name = variable_name;
file.local_filename = local_filename;
file.request_filename = request_filename;
@ -173,7 +173,7 @@ void HttpRequestWorker::execute(HttpRequestInput *input) {
}
// add files
for (QList<HttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
for (QList<SWGHttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
QFileInfo fi(file_info->local_filename);
// ensure necessary variables are available

View File

@ -13,11 +13,10 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
enum HttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
class HttpRequestInputFileElement {
class SWGHttpRequestInputFileElement {
public:
QString variable_name;
@ -36,7 +35,7 @@ public:
HttpRequestVarLayout var_layout;
QMap<QString, QString> vars;
QMap<QString, QString> headers;
QList<HttpRequestInputFileElement> files;
QList<SWGHttpRequestInputFileElement> files;
QByteArray request_body;
HttpRequestInput();

View File

@ -1,5 +1,6 @@
#include "{{classname}}.h"
#include "{{prefix}}Helpers.h"
#include "{{prefix}}ModelFactory.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -17,32 +18,97 @@ namespace Swagger {
{{#operations}}
{{#operation}}
void
{{classname}}::{{nickname}}({{#allParams}}{{dataType}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
{{classname}}::{{nickname}}({{#allParams}}{{{dataType}}} {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("{{path}}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "{{httpMethod}}");
{{#pathParams}}
QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{paramName}}").append("}");
fullPath.replace({{paramName}}PathParam, stringValue({{paramName}}));
{{/pathParams}}
{{#queryParams}}if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
{{#formParams}}{{^isFile}}
if({{paramName}} != NULL) {
input.add_var("{{paramName}}", *{{paramName}});
}
{{/isFile}}{{/formParams}}
{{#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));
}
}
}
{{/collectionFormat}}
{{/queryParams}}
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "{{httpMethod}}");
{{#bodyParams}}
// body
input.request_body.append({{paramName}}.asJson());
{{/bodyParams}}
{{#isContainer}}
QJsonArray* {{paramName}}Array = new QJsonArray();
toJsonArray((QList<void*>*){{paramName}}, {{paramName}}Array, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*{{paramName}}Array);
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
{{/isContainer}}
{{^isContainer}}
QString output = {{paramName}}.asJson();
input.request_body.append(output);
{{/isContainer}}{{/bodyParams}}
{{#headerParams}}
input.headers
// TODO: add header support
{{/headerParams}}
connect(worker,
@ -71,7 +137,7 @@ void
QJsonArray jsonArray = doc.array();
foreach(QJsonValue obj, jsonArray) {
{{returnBaseType}}* o = new {{returnBaseType}}();
{{{returnBaseType}}}* o = new {{returnBaseType}}();
QJsonObject jv = obj.toObject();
QJsonObject * ptr = (QJsonObject*)&jv;
o->fromJsonObject(*ptr);
@ -80,13 +146,29 @@ void
{{/isListContainer}}
{{^isListContainer}}{{#returnTypeIsPrimitive}}
{{returnType}} output; // TODO
{{{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);
}
{{/isMapContainer}}
{{^isMapContainer}}
{{^returnTypeIsPrimitive}}QString json(worker->response);
{{returnType}} output = new {{returnBaseType}}(&json);
{{{returnType}}} output = static_cast<{{{returnType}}}>(create(json, QString("{{{returnBaseType}}}")));
{{/returnTypeIsPrimitive}}
{{/isMapContainer}}
{{/isListContainer}}{{/returnType}}
worker->deleteLater();

View File

@ -154,6 +154,11 @@ stringValue(qint32 value) {
return QString::number(value);
}
QString
stringValue(qint64 value) {
return QString::number(value);
}
QString
stringValue(bool value) {
return QString(value ? "true" : "false");

View File

@ -10,6 +10,7 @@ namespace Swagger {
bool isCompatibleJsonValue(QString type);
QString stringValue(QString* value);
QString stringValue(qint32 value);
QString stringValue(qint64 value);
QString stringValue(bool value);
}

View File

@ -5,14 +5,25 @@
#include "{{classname}}.h"{{/model}}{{/models}}
namespace Swagger {
void*
create(QString type) {
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;
}
} /* namespace Swagger */
#endif /* ModelFactory_H_ */

View File

@ -0,0 +1,274 @@
#include "PetApiTests.h"
#include <QJsonDocument>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDebug>
PetApiTests::PetApiTests () {}
PetApiTests::~PetApiTests () {
exit(1);
}
SWGPetApi* PetApiTests::getApi() {
SWGPetApi* api = new SWGPetApi();
api->host = "http://petstore.swagger.io";
api->basePath = "/v2";
return api;
}
SWGPet* PetApiTests::createRandomPet() {
SWGPet* pet = new SWGPet();
qint64 id = QDateTime::currentMSecsSinceEpoch();
pet->setName(new QString("monster"));
pet->setId(id);
pet->setStatus(new QString("freaky"));
return pet;
}
void PetApiTests::runTests() {
PetApiTests* tests = new PetApiTests();
QTest::qExec(tests);
delete tests;
}
void PetApiTests::getPetByIdTest() {
SWGPetApi* api = getApi();
static QEventLoop loop;
QTimer timer;
timer.setInterval(1000);
timer.setSingleShot(true);
auto validator = [](SWGPet* pet) {
qDebug() << pet->asJson();
QVERIFY(pet->getId() == 3);
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->getPetById(3);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
delete api;
}
void PetApiTests::findPetsByStatusTest() {
SWGPetApi* api = getApi();
static QEventLoop loop;
QTimer timer;
timer.setInterval(1000);
timer.setSingleShot(true);
auto validator = [](QList<SWGPet*>* pets) {
foreach(SWGPet* pet, *pets) {
QVERIFY(pet->getStatus()->startsWith("available") || pet->getStatus()->startsWith("sold"));
}
loop.quit();
};
connect(api, &SWGPetApi::findPetsByStatusSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
QList<QString*>* status = new QList<QString*>();
status->append(new QString("available"));
status->append(new QString("sold"));
api->findPetsByStatus(status);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
delete api;
}
void PetApiTests::createAndGetPetTest() {
SWGPetApi* api = getApi();
static QEventLoop loop;
QTimer timer;
timer.setInterval(1000);
timer.setSingleShot(true);
auto validator = []() {
// pet created
loop.quit();
};
connect(api, &SWGPetApi::addPetSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
SWGPet* pet = createRandomPet();
qint64 id = pet->getId();
api->addPet(*pet);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
timer.setInterval(1000);
timer.setSingleShot(true);
auto getPetValidator = [](SWGPet* pet) {
QVERIFY(pet->getId() > 0);
QVERIFY(pet->getStatus()->compare("freaky") == 0);
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, getPetValidator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->getPetById(id);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
delete api;
}
void PetApiTests::updatePetTest() {
static SWGPetApi* api = getApi();
SWGPet* pet = createRandomPet();
static SWGPet* petToCheck;
qint64 id = pet->getId();
static QEventLoop loop;
QTimer timer;
timer.setInterval(100000);
timer.setSingleShot(true);
auto validator = []() {
loop.quit();
};
connect(api, &SWGPetApi::addPetSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// create pet
api->addPet(*pet);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// fetch it
timer.setInterval(1000);
timer.setSingleShot(true);
auto fetchPet = [](SWGPet* pet) {
petToCheck = pet;
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, fetchPet);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// create pet
api->getPetById(id);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// update it
timer.setInterval(1000);
timer.setSingleShot(true);
auto updatePetTest = []() {
loop.quit();
};
connect(api, &SWGPetApi::updatePetSignal, this, updatePetTest);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
// update pet
petToCheck->setStatus(new QString("scary"));
api->updatePet(*petToCheck);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// check it
timer.setInterval(1000);
timer.setSingleShot(true);
auto fetchPet2 = [](SWGPet* pet) {
QVERIFY(pet->getId() == petToCheck->getId());
QVERIFY(pet->getStatus()->compare(petToCheck->getStatus()) == 0);
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, fetchPet2);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->getPetById(id);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
}
void PetApiTests::updatePetWithFormTest() {
static SWGPetApi* api = getApi();
SWGPet* pet = createRandomPet();
static SWGPet* petToCheck;
qint64 id = pet->getId();
static QEventLoop loop;
QTimer timer;
// create pet
timer.setInterval(1000);
timer.setSingleShot(true);
auto validator = []() {
loop.quit();
};
connect(api, &SWGPetApi::addPetSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->addPet(*pet);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// fetch it
timer.setInterval(1000);
timer.setSingleShot(true);
auto fetchPet = [](SWGPet* pet) {
petToCheck = pet;
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, fetchPet);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->getPetById(id);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// update it
timer.setInterval(1000);
timer.setSingleShot(true);
connect(api, &SWGPetApi::updatePetWithFormSignal, this, [](){loop.quit();});
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->updatePetWithForm(new QString(QString::number(id)), new QString("gorilla"), NULL);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
// fetch it
timer.setInterval(1000);
timer.setSingleShot(true);
auto fetchUpdatedPet = [](SWGPet* pet) {
QVERIFY(pet->getName()->compare(QString("gorilla")) == 0);
loop.quit();
};
connect(api, &SWGPetApi::getPetByIdSignal, this, fetchUpdatedPet);
connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit);
api->getPetById(id);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
}

View File

@ -0,0 +1,35 @@
#ifndef PETAPITESTS_H
#define PETAPITESTS_H
#include <QtTest/QtTest>
#include <QTimer>
#include "../client/SWGPetApi.h"
using namespace Swagger;
class PetApiTests: public QObject {
Q_OBJECT
public:
PetApiTests();
virtual ~PetApiTests();
static void runTests();
private:
SWGPetApi* getApi();
SWGPet* createRandomPet();
signals:
void quit();
bool success();
private slots:
void getPetByIdTest();
void findPetsByStatusTest();
void createAndGetPetTest();
void updatePetTest();
void updatePetWithFormTest();
};
#endif // PETAPITESTS_H

View File

@ -0,0 +1,46 @@
#-------------------------------------------------
#
# Project created by QtCreator 2015-05-14T20:56:31
#
#-------------------------------------------------
QT += core gui testlib network
QT -= gui
TARGET = PetStore
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++11
TEMPLATE = app
SOURCES += main.cpp \
../client/SWGCategory.cpp \
../client/SWGHelpers.cpp \
../client/SWGHttpRequest.cpp \
../client/SWGOrder.cpp \
../client/SWGPet.cpp \
../client/SWGPetApi.cpp \
../client/SWGStoreApi.cpp \
../client/SWGTag.cpp \
../client/SWGUser.cpp \
../client/SWGUserApi.cpp \
PetApiTests.cpp
HEADERS += \
../client/SWGCategory.h \
../client/SWGHelpers.h \
../client/SWGHttpRequest.h \
../client/SWGObject.h \
../client/SWGOrder.h \
../client/SWGPet.h \
../client/SWGPetApi.h \
../client/SWGStoreApi.h \
../client/SWGTag.h \
../client/SWGUser.h \
../client/SWGUserApi.h \
PetApiTests.h \
../client/SWGModelFactory.h

View File

@ -0,0 +1,269 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.3.2, 2015-05-15T11:02:11. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
<value type="QByteArray">{e1009bf2-3b8d-440a-a972-23a1fd0a9453}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
<value type="int">0</value>
</data>
<data>
<variable>ProjectExplorer.Project.EditorSettings</variable>
<valuemap type="QVariantMap">
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
<value type="QString" key="language">Cpp</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
</valuemap>
</valuemap>
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
<value type="QString" key="language">QmlJS</value>
<valuemap type="QVariantMap" key="value">
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
</valuemap>
</valuemap>
<value type="int" key="EditorConfiguration.CodeStyle.Count">2</value>
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
<value type="int" key="EditorConfiguration.IndentSize">4</value>
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
<value type="int" key="EditorConfiguration.TabSize">8</value>
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.PluginSettings</variable>
<valuemap type="QVariantMap"/>
</data>
<data>
<variable>ProjectExplorer.Project.Target.0</variable>
<valuemap type="QVariantMap">
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Desktop Qt 5.4.1 clang 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Desktop Qt 5.4.1 clang 64bit</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">qt.54.clang_64_kit</value>
<value type="int" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_4_1_clang_64bit-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">2</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/build-PetStore-Desktop_Qt_5_4_1_clang_64bit-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">qmake</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">QtProjectManager.QMakeBuildStep</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibrary">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.LinkQmlDebuggingLibraryAuto">true</value>
<value type="QString" key="QtProjectManager.QMakeBuildStep.QMakeArguments"></value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.QMakeForced">false</value>
<value type="bool" key="QtProjectManager.QMakeBuildStep.UseQtQuickCompiler">false</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.1">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">false</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments"></value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">2</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
</valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.MakeStep</value>
<valuelist type="QVariantList" key="Qt4ProjectManager.MakeStep.AutomaticallyAddedMakeArguments">
<value type="QString">-w</value>
<value type="QString">-r</value>
</valuelist>
<value type="bool" key="Qt4ProjectManager.MakeStep.Clean">true</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeArguments">clean</value>
<value type="QString" key="Qt4ProjectManager.MakeStep.MakeCommand"></value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Release</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
<value type="int" key="Qt4ProjectManager.Qt4BuildConfiguration.BuildConfiguration">0</value>
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.BuildConfigurationCount">2</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<value type="int" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
</valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy locally</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.PluginSettings"/>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
<valuelist type="QVariantList" key="Analyzer.Valgrind.AddedSuppressionFiles"/>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectBusEvents">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.CollectSystime">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableBranchSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableCacheSim">false</value>
<value type="bool" key="Analyzer.Valgrind.Callgrind.EnableEventToolTips">true</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.MinimumCostRatio">0.01</value>
<value type="double" key="Analyzer.Valgrind.Callgrind.VisualisationMinimumCostRatio">10</value>
<value type="bool" key="Analyzer.Valgrind.FilterExternalIssues">true</value>
<value type="int" key="Analyzer.Valgrind.LeakCheckOnFinish">1</value>
<value type="int" key="Analyzer.Valgrind.NumCallers">25</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.RemovedSuppressionFiles"/>
<value type="int" key="Analyzer.Valgrind.SelfModifyingCodeDetection">1</value>
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
<value type="bool" key="Analyzer.Valgrind.ShowReachable">false</value>
<value type="bool" key="Analyzer.Valgrind.TrackOrigins">true</value>
<value type="QString" key="Analyzer.Valgrind.ValgrindExecutable">/usr/local/bin/valgrind</value>
<valuelist type="QVariantList" key="Analyzer.Valgrind.VisibleErrorKinds">
<value type="int">11</value>
<value type="int">14</value>
<value type="int">12</value>
<value type="int">13</value>
<value type="int">2</value>
<value type="int">3</value>
<value type="int">4</value>
<value type="int">5</value>
<value type="int">6</value>
<value type="int">7</value>
<value type="int">8</value>
<value type="int">9</value>
<value type="int">10</value>
<value type="int">0</value>
<value type="int">1</value>
</valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">PetStore</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/Users/tony/dev/projects/swagger-api/swagger-codegen/samples/client/petstore/qt5cpp/PetStore/PetStore.pro</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">PetStore.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">false</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
<value type="bool" key="RunConfiguration.UseMultiProcess">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
</valuemap>
<value type="int" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
</data>
<data>
<variable>ProjectExplorer.Project.TargetCount</variable>
<value type="int">1</value>
</data>
<data>
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
<value type="int">18</value>
</data>
<data>
<variable>Version</variable>
<value type="int">18</value>
</data>
</qtcreator>

View File

@ -0,0 +1,12 @@
#include <QCoreApplication>
#include "PetApiTests.h"
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
PetApiTests::runTests();
return a.exec();
}

View File

@ -154,6 +154,11 @@ stringValue(qint32 value) {
return QString::number(value);
}
QString
stringValue(qint64 value) {
return QString::number(value);
}
QString
stringValue(bool value) {
return QString(value ? "true" : "false");

View File

@ -10,6 +10,7 @@ namespace Swagger {
bool isCompatibleJsonValue(QString type);
QString stringValue(QString* value);
QString stringValue(qint32 value);
QString stringValue(qint64 value);
QString stringValue(bool value);
}

View File

@ -26,7 +26,7 @@ void HttpRequestInput::add_var(QString key, QString value) {
}
void HttpRequestInput::add_file(QString variable_name, QString local_filename, QString request_filename, QString mime_type) {
HttpRequestInputFileElement file;
SWGHttpRequestInputFileElement file;
file.variable_name = variable_name;
file.local_filename = local_filename;
file.request_filename = request_filename;
@ -173,7 +173,7 @@ void HttpRequestWorker::execute(HttpRequestInput *input) {
}
// add files
for (QList<HttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
for (QList<SWGHttpRequestInputFileElement>::iterator file_info = input->files.begin(); file_info != input->files.end(); file_info++) {
QFileInfo fi(file_info->local_filename);
// ensure necessary variables are available

View File

@ -13,11 +13,10 @@
#include <QNetworkAccessManager>
#include <QNetworkReply>
enum HttpRequestVarLayout {NOT_SET, ADDRESS, URL_ENCODED, MULTIPART};
class HttpRequestInputFileElement {
class SWGHttpRequestInputFileElement {
public:
QString variable_name;
@ -36,7 +35,7 @@ public:
HttpRequestVarLayout var_layout;
QMap<QString, QString> vars;
QMap<QString, QString> headers;
QList<HttpRequestInputFileElement> files;
QList<SWGHttpRequestInputFileElement> files;
QByteArray request_body;
HttpRequestInput();

View File

@ -9,8 +9,7 @@
#include "SWGOrder.h"
namespace Swagger {
void*
create(QString type) {
inline void* create(QString type) {
if(QString("SWGUser").compare(type) == 0) {
return new SWGUser();
}
@ -29,6 +28,18 @@ namespace Swagger {
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,5 +1,6 @@
#include "SWGPetApi.h"
#include "SWGHelpers.h"
#include "SWGModelFactory.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -19,16 +20,20 @@ SWGPetApi::updatePet(SWGPet body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "PUT");
// body
input.request_body.append(body.asJson());
QString output = body.asJson();
input.request_body.append(output);
@ -63,16 +68,20 @@ SWGPetApi::addPet(SWGPet body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
QString output = body.asJson();
input.request_body.append(output);
@ -103,19 +112,10 @@ SWGPetApi::addPetCallback(HttpRequestWorker * worker) {
emit addPetSignal();
}
void
SWGPetApi::findPetsByStatus(QList&lt;QString*&gt;* status) {
SWGPetApi::findPetsByStatus(QList<QString*>* 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)));
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -123,6 +123,57 @@ SWGPetApi::findPetsByStatus(QList&lt;QString*&gt;* status) {
if(status->size() > 0) {
if(QString("multi").indexOf("multi") == 0) {
foreach(QString* t, *status) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=").append(stringValue(t));
}
}
else if (QString("multi").indexOf("ssv") == 0) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=");
qint32 count = 0;
foreach(QString* t, *status) {
if(count > 0) {
fullPath.append(" ");
}
fullPath.append(stringValue(t));
}
}
else if (QString("multi").indexOf("tsv") == 0) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=");
qint32 count = 0;
foreach(QString* t, *status) {
if(count > 0) {
fullPath.append("\t");
}
fullPath.append(stringValue(t));
}
}
}
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
@ -165,19 +216,10 @@ SWGPetApi::findPetsByStatusCallback(HttpRequestWorker * worker) {
}
void
SWGPetApi::findPetsByTags(QList&lt;QString*&gt;* tags) {
SWGPetApi::findPetsByTags(QList<QString*>* 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)));
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -185,6 +227,57 @@ SWGPetApi::findPetsByTags(QList&lt;QString*&gt;* tags) {
if(tags->size() > 0) {
if(QString("multi").indexOf("multi") == 0) {
foreach(QString* t, *tags) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=").append(stringValue(t));
}
}
else if (QString("multi").indexOf("ssv") == 0) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=");
qint32 count = 0;
foreach(QString* t, *tags) {
if(count > 0) {
fullPath.append(" ");
}
fullPath.append(stringValue(t));
}
}
else if (QString("multi").indexOf("tsv") == 0) {
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=");
qint32 count = 0;
foreach(QString* t, *tags) {
if(count > 0) {
fullPath.append("\t");
}
fullPath.append(stringValue(t));
}
}
}
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
@ -231,6 +324,9 @@ SWGPetApi::getPetById(qint64 petId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
@ -238,9 +334,7 @@ SWGPetApi::getPetById(qint64 petId) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -266,9 +360,11 @@ SWGPetApi::getPetByIdCallback(HttpRequestWorker * worker) {
QString json(worker->response);
SWGPet* output = new SWGPet(&json);
SWGPet* output = static_cast<SWGPet*>(create(json, QString("SWGPet")));
@ -282,16 +378,25 @@ SWGPetApi::updatePetWithForm(QString* petId, QString* name, QString* status) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
if(name != NULL) {
input.add_var("name", *name);
}
if(status != NULL) {
input.add_var("status", *status);
}
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
@ -326,6 +431,9 @@ SWGPetApi::deletePet(QString* api_key, qint64 petId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
@ -333,13 +441,11 @@ SWGPetApi::deletePet(QString* api_key, qint64 petId) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
input.headers
// TODO: add header support
connect(worker,
@ -368,20 +474,25 @@ SWGPetApi::deletePetCallback(HttpRequestWorker * worker) {
emit deletePetSignal();
}
void
SWGPetApi::uploadFile(qint64 petId, QString* additionalMetadata, SWGFile* file) {
SWGPetApi::uploadFile(qint64 petId, QString* additionalMetadata, SWGHttpRequestInputFileElement* file) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
fullPath.replace(petIdPathParam, stringValue(petId));
if(additionalMetadata != NULL) {
input.add_var("additionalMetadata", *additionalMetadata);
}
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");

View File

@ -5,7 +5,7 @@
#include "SWGPet.h"
#include <QString>
#include "SWGFile.h"
#include "SWGHttpRequest.h"
#include <QObject>
@ -29,7 +29,7 @@ public:
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);
void uploadFile(qint64 petId, QString* additionalMetadata, SWGHttpRequestInputFileElement* file);
private:
void updatePetCallback (HttpRequestWorker * worker);

View File

@ -1,5 +1,6 @@
#include "SWGStoreApi.h"
#include "SWGHelpers.h"
#include "SWGModelFactory.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -19,10 +20,6 @@ SWGStoreApi::getInventory() {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/inventory");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -30,6 +27,11 @@ SWGStoreApi::getInventory() {
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
@ -51,9 +53,22 @@ SWGStoreApi::getInventoryCallback(HttpRequestWorker * worker) {
QString json(worker->response);
QMap&lt;String, qint32&gt;* output = new QMap(&json);
QMap<QString, qint32>* output = new QMap<QString, qint32>();
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], "QMap", "");
output->insert(key, *val);
}
@ -67,16 +82,20 @@ SWGStoreApi::placeOrder(SWGOrder body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
QString output = body.asJson();
input.request_body.append(output);
@ -102,9 +121,11 @@ SWGStoreApi::placeOrderCallback(HttpRequestWorker * worker) {
QString json(worker->response);
SWGOrder* output = new SWGOrder(&json);
SWGOrder* output = static_cast<SWGOrder*>(create(json, QString("SWGOrder")));
@ -118,6 +139,9 @@ SWGStoreApi::getOrderById(QString* orderId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
QString orderIdPathParam("{"); orderIdPathParam.append("orderId").append("}");
fullPath.replace(orderIdPathParam, stringValue(orderId));
@ -125,9 +149,7 @@ SWGStoreApi::getOrderById(QString* orderId) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -153,9 +175,11 @@ SWGStoreApi::getOrderByIdCallback(HttpRequestWorker * worker) {
QString json(worker->response);
SWGOrder* output = new SWGOrder(&json);
SWGOrder* output = static_cast<SWGOrder*>(create(json, QString("SWGOrder")));
@ -169,6 +193,9 @@ SWGStoreApi::deleteOrder(QString* orderId) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
QString orderIdPathParam("{"); orderIdPathParam.append("orderId").append("}");
fullPath.replace(orderIdPathParam, stringValue(orderId));
@ -176,9 +203,7 @@ SWGStoreApi::deleteOrder(QString* orderId) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");

View File

@ -34,7 +34,7 @@ private:
void deleteOrderCallback (HttpRequestWorker * worker);
signals:
void getInventorySignal(QMap<String, qint32>* summary);
void getInventorySignal(QMap<QString, qint32>* summary);
void placeOrderSignal(SWGOrder* summary);
void getOrderByIdSignal(SWGOrder* summary);
void deleteOrderSignal();

View File

@ -1,5 +1,6 @@
#include "SWGUserApi.h"
#include "SWGHelpers.h"
#include "SWGModelFactory.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -19,16 +20,20 @@ SWGUserApi::createUser(SWGUser body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
QString output = body.asJson();
input.request_body.append(output);
@ -59,20 +64,28 @@ SWGUserApi::createUserCallback(HttpRequestWorker * worker) {
emit createUserSignal();
}
void
SWGUserApi::createUsersWithArrayInput(QList&lt;SWGUser*&gt;* body) {
SWGUserApi::createUsersWithArrayInput(QList<SWGUser*>* body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithArray");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
QJsonArray* bodyArray = new QJsonArray();
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*bodyArray);
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
@ -103,20 +116,28 @@ SWGUserApi::createUsersWithArrayInputCallback(HttpRequestWorker * worker) {
emit createUsersWithArrayInputSignal();
}
void
SWGUserApi::createUsersWithListInput(QList&lt;SWGUser*&gt;* body) {
SWGUserApi::createUsersWithListInput(QList<SWGUser*>* body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/createWithList");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "POST");
// body
input.request_body.append(body.asJson());
QJsonArray* bodyArray = new QJsonArray();
toJsonArray((QList<void*>*)body, bodyArray, QString("body"), QString("SWGUser*"));
QJsonDocument doc(*bodyArray);
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
@ -151,23 +172,38 @@ SWGUserApi::loginUser(QString* username, QString* password) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/login");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
if(fullPath.compare("?") > 0) fullPath.append("?");
else fullPath.append("&");
if(fullPath.indexOf("?") > 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("&");
if(fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("password"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(password)));
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -193,9 +229,11 @@ SWGUserApi::loginUserCallback(HttpRequestWorker * worker) {
QString json(worker->response);
QString* output = new QString(&json);
QString* output = static_cast<QString*>(create(json, QString("QString")));
@ -209,10 +247,6 @@ SWGUserApi::logoutUser() {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/logout");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -220,6 +254,11 @@ SWGUserApi::logoutUser() {
connect(worker,
&HttpRequestWorker::on_execution_finished,
this,
@ -250,6 +289,9 @@ SWGUserApi::getUserByName(QString* username) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
@ -257,9 +299,7 @@ SWGUserApi::getUserByName(QString* username) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "GET");
@ -285,9 +325,11 @@ SWGUserApi::getUserByNameCallback(HttpRequestWorker * worker) {
QString json(worker->response);
SWGUser* output = new SWGUser(&json);
SWGUser* output = static_cast<SWGUser*>(create(json, QString("SWGUser")));
@ -301,6 +343,9 @@ SWGUserApi::updateUser(QString* username, SWGUser body) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "PUT");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
@ -308,12 +353,13 @@ SWGUserApi::updateUser(QString* username, SWGUser body) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "PUT");
// body
input.request_body.append(body.asJson());
QString output = body.asJson();
input.request_body.append(output);
@ -348,6 +394,9 @@ SWGUserApi::deleteUser(QString* username) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");
QString usernamePathParam("{"); usernamePathParam.append("username").append("}");
fullPath.replace(usernamePathParam, stringValue(username));
@ -355,9 +404,7 @@ SWGUserApi::deleteUser(QString* username) {
HttpRequestWorker *worker = new HttpRequestWorker();
HttpRequestInput input(fullPath, "DELETE");