[C++][Qt]Replace usage of QVariant with a more intuitive optional wrapper (#8960)

* Replace usage of QVariant with a more intuitive wrapper which also supports non standard types/classes

* Fix crash due to usage of object instead of reference
This commit is contained in:
sunn 2021-03-15 18:56:20 +01:00 committed by GitHub
parent 9d8494a89d
commit fcab51322e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 231 additions and 216 deletions

View File

@ -1,6 +1,5 @@
{{>licenseInfo}}
#include "{{classname}}.h"
#include "{{prefix}}Helpers.h"
#include "{{prefix}}ServerConfiguration.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -21,7 +20,6 @@ namespace {{this}} {
}
void {{classname}}::initializeServerConfigs(){
//Default server
QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>();
//varying endpoint server
@ -224,7 +222,7 @@ QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool
{{#operations}}
{{#operation}}
void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const QVariant &{{/required}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const ::{{cppNamespace}}::OptionalParam<{{{dataType}}}> &{{/required}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) {
QString fullPath = QString(_serverConfigs["{{nickname}}"][_serverIndices.value("{{nickname}}")].URL()+"{{{path}}}");
{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}
if(_apiKeys.contains("{{name}}")){
@ -247,9 +245,8 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
b64.append(_username.toUtf8() + ":" + _password.toUtf8());
addHeaders("Authorization","Basic " + b64.toBase64());
}{{/isBasicBasic}}{{/authMethods}}
{{#pathParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^required}}if({{paramName}}.hasValue()){{/required}}
{
QString {{paramName}}PathParam("{");
{{paramName}}PathParam.append("{{baseName}}").append("}");
@ -263,7 +260,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
{{^collectionFormat}}
{{^isPrimitiveType}}
QString paramString = (pathStyle == "matrix" && {{isExplode}}) ? pathPrefix : pathPrefix+"{{baseName}}"+pathSuffix;
QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
QJsonObject parameter = {{paramName}}{{^required}}.value(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
@ -307,14 +304,14 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix;
fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}})));
{{/isPrimitiveType}}
{{/collectionFormat}}
{{#collectionFormat}}
if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
if({{{paramName}}}{{^required}}.value(){{/required}}.size() > 0) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix;
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append(pathDelimiter);
}
@ -325,13 +322,12 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
{{/collectionFormat}}
}
{{/pathParams}}
{{#hasQueryParams}}
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{{/hasQueryParams}}
{{#queryParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^required}}if({{paramName}}.hasValue()){{/required}}
{
queryStyle = "{{style}}";
if(queryStyle == "")
@ -346,7 +342,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
fullPath.append("?");
{{^isPrimitiveType}}
QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : "";
QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
QJsonObject parameter = {{paramName}}{{^required}}.value(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
@ -392,13 +388,13 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
fullPath.append(paramString);
{{/isPrimitiveType}}{{#isPrimitiveType}}
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}})));
{{/isPrimitiveType}}
{{/collectionFormat}}
{{#collectionFormat}}
if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
if({{{paramName}}}{{^required}}.value(){{/required}}.size() > 0) {
if (QString("{{collectionFormat}}").indexOf("multi") == 0) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix);
else
@ -411,7 +407,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
}
@ -424,7 +420,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append("\t");
}
@ -437,7 +433,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
@ -450,7 +446,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
@ -463,7 +459,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
else
fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix);
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
fullPath.append(queryDelimiter);
}
@ -474,7 +470,6 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
{{/collectionFormat}}
}
{{/queryParams}}
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
@ -493,39 +488,38 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
formSuffix = getParamStyleSuffix(formStyle);
formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}});
{{/first}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^required}}if({{paramName}}.hasValue()){{/required}}
{
{{^isFile}}
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}));
{{/isFile}}
{{#isFile}}
input.add_file("{{baseName}}", {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.local_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.request_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.mime_type);
input.add_file("{{baseName}}", {{paramName}}{{^required}}.value(){{/required}}.local_filename, {{paramName}}{{^required}}.value(){{/required}}.request_filename, {{paramName}}{{^required}}.value(){{/required}}.mime_type);
{{/isFile}}
}
{{/formParams}}
{{#bodyParams}}
{{^required}}if({{paramName}}.hasValue()){{/required}}{
{{#isContainer}}
{{#isArray}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).toArray());{{/isArray}}{{#isMap}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).toObject());{{/isMap}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value(){{/required}}).toArray());{{/isArray}}{{#isMap}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}{{^required}}.value(){{/required}}).toObject());{{/isMap}}
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
{{/isContainer}}{{^isContainer}}{{#isString}}
QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}}
QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}}
QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asByteArray();{{/isFile}}
QByteArray output = {{paramName}}{{^required}}.value(){{/required}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}}{{^required}}.value(){{/required}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}}
QByteArray output = {{paramName}}{{^required}}.value(){{/required}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}}
QByteArray output = {{paramName}}{{^required}}.value(){{/required}}.asByteArray();{{/isFile}}
input.request_body.append(output);
{{/isContainer}}
{{/bodyParams}}
}{{/bodyParams}}
{{#headerParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^required}}if({{paramName}}.hasValue()){{/required}}
{
{{^collectionFormat}}
{{^isPrimitiveType}}
QString headerString;
QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
QJsonObject parameter = {{paramName}}{{^required}}.value(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
@ -567,14 +561,14 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
input.headers.insert("{{baseName}}", headerString);
{{/isPrimitiveType}}
{{#isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}).isEmpty()) {
input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}));
}
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}
QString headerString;
if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
if ({{{paramName}}}{{^required}}.value(){{/required}}.size() > 0) {
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
headerString.append(",");
}
@ -587,14 +581,14 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
{{/headerParams}}
{{#cookieParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{{^required}}if({{paramName}}.hasValue()){{/required}}
{
if(QString("{{style}}").indexOf("form") == 0){
{{^collectionFormat}}
{{^isPrimitiveType}}
{{^isExplode}}
QString cookieString = "{{baseName}}=";
QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject();
QJsonObject parameter = {{paramName}}{{^required}}.value(){{/required}}.asJsonObject();
qint32 count = 0;
foreach(const QString& key, parameter.keys()) {
if (count > 0) {
@ -636,8 +630,8 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
{{/isExplode}}
{{/isPrimitiveType}}
{{#isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
if(!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}).isEmpty()) {
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value(){{/required}}));
}
{{/isPrimitiveType}}
{{/collectionFormat}}
@ -646,7 +640,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
QString cookieString = "{{baseName}}=";
if ({{{paramName}}}.size() > 0) {
qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value(){{/required}}) {
if (count > 0) {
cookieString.append(",");
}
@ -664,7 +658,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<{{prefix}}HttpRequestWorker>().count() == 0){
if(findChildren<{{prefix}}HttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});

View File

@ -2,6 +2,7 @@
#ifndef {{prefix}}_{{classname}}_H
#define {{prefix}}_{{classname}}_H
#include "{{prefix}}Helpers.h"
#include "{{prefix}}HttpRequest.h"
#include "{{prefix}}ServerConfiguration.h"
@ -13,7 +14,6 @@
#include <QStringList>
#include <QList>
#include <QNetworkAccessManager>
#include <QVariant>
{{#cppNamespaceDeclarations}}
namespace {{this}} {
@ -57,7 +57,7 @@ public:
{{/required}}
{{/allParams}}
*/{{/hasParams}}
{{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const QVariant &{{/required}}{{paramName}}{{^required}} = QVariant(){{/required}}{{^-last}}, {{/-last}}{{/allParams}});
{{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const ::{{cppNamespace}}::OptionalParam<{{{dataType}}}> &{{/required}}{{paramName}}{{^required}} = ::{{cppNamespace}}::OptionalParam<{{{dataType}}}>(){{/required}}{{^-last}}, {{/-last}}{{/allParams}});
{{/operation}}{{/operations}}
private:

View File

@ -11,7 +11,6 @@
#include <QList>
#include <QMap>
#include <QSet>
#include <QVariant>
#include "{{prefix}}Enum.h"
#include "{{prefix}}HttpFileElement.h"
@ -21,6 +20,27 @@
namespace {{this}} {
{{/cppNamespaceDeclarations}}
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};
bool setDateTimeFormat(const QString&);
template <typename T>

View File

@ -217,6 +217,7 @@ void PetApiTests::updatePetWithFormTest() {
// fetch it
bool petUpdated2 = false;
connect(&api, &PFXPetApi::getPetByIdSignal, [&](PFXPet pet) {
Q_UNUSED(pet);
petUpdated2 = true;
// QVERIFY(pet.getName().compare(QString("gorilla")) == 0);
QTimer::singleShot(0, &loop, &QEventLoop::quit);

View File

@ -21,7 +21,6 @@
#include <QList>
#include <QMap>
#include <QSet>
#include <QVariant>
#include "PFXEnum.h"
#include "PFXHttpFileElement.h"
@ -29,6 +28,27 @@
namespace test_namespace {
template <typename T>
class OptionalParam {
public:
T m_Value;
bool m_hasValue;
public:
OptionalParam(){
m_hasValue = false;
}
OptionalParam(const T &val){
m_hasValue = true;
m_Value = val;
}
bool hasValue() const {
return m_hasValue;
}
T value() const{
return m_Value;
}
};
bool setDateTimeFormat(const QString&);
template <typename T>

View File

@ -10,7 +10,6 @@
*/
#include "PFXPetApi.h"
#include "PFXHelpers.h"
#include "PFXServerConfiguration.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -29,7 +28,6 @@ PFXPetApi::~PFXPetApi() {
}
void PFXPetApi::initializeServerConfigs(){
//Default server
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
//varying endpoint server
@ -225,21 +223,22 @@ QString PFXPetApi::getParamStyleDelimiter(QString style, QString name, bool isEx
void PFXPetApi::addPet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
{
QByteArray output = body.asJson().toUtf8();
input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -269,11 +268,10 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
}
}
void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) {
void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &api_key) {
QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}");
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
@ -287,16 +285,16 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "DELETE");
if(!api_key.isNull())
if(api_key.hasValue())
{
if (!::test_namespace::toStringValue(api_key.value<QString>()).isEmpty()) {
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value<QString>()));
if (!::test_namespace::toStringValue(api_key.value()).isEmpty()) {
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
}
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
@ -304,7 +302,7 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) {
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -337,7 +335,6 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus");
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
@ -424,18 +421,18 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
}
}
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -478,7 +475,6 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags");
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
@ -565,18 +561,18 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
}
}
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -624,7 +620,6 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
}
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
@ -638,18 +633,18 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -683,21 +678,22 @@ void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::updatePet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "PUT");
{
QByteArray output = body.asJson().toUtf8();
input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -727,11 +723,10 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
}
}
void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, const QVariant &status) {
void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &name, const ::test_namespace::OptionalParam<QString> &status) {
QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}");
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
@ -745,22 +740,18 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, co
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
if(!name.isNull())
if(name.hasValue())
{
input.add_var("name", ::test_namespace::toStringValue(name.value<QString>()));
input.add_var("name", ::test_namespace::toStringValue(name.value()));
}
if(!status.isNull())
if(status.hasValue())
{
input.add_var("status", ::test_namespace::toStringValue(status.value<QString>()));
input.add_var("status", ::test_namespace::toStringValue(status.value()));
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
@ -768,7 +759,7 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, co
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -798,11 +789,10 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
}
}
void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_metadata, const QVariant &file) {
void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &additional_metadata, const ::test_namespace::OptionalParam<PFXHttpFileElement> &file) {
QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage");
{
QString pet_idPathParam("{");
pet_idPathParam.append("petId").append("}");
@ -816,22 +806,18 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_meta
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
if(!additional_metadata.isNull())
if(additional_metadata.hasValue())
{
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value<QString>()));
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value()));
}
if(!file.isNull())
if(file.hasValue())
{
input.add_file("file", file.value<PFXHttpFileElement>().local_filename, file.value<PFXHttpFileElement>().request_filename, file.value<PFXHttpFileElement>().mime_type);
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
@ -839,7 +825,7 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_meta
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXPetApi_H
#define PFX_PFXPetApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h"
@ -25,7 +26,6 @@
#include <QStringList>
#include <QList>
#include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace {
@ -66,7 +66,7 @@ public:
* @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional]
*/
void deletePet(const qint64 &pet_id, const QVariant &api_key = QVariant());
void deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &api_key = ::test_namespace::OptionalParam<QString>());
/**
* @param[in] status QList<QString> [required]
@ -93,14 +93,14 @@ public:
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
void updatePetWithForm(const qint64 &pet_id, const QVariant &name = QVariant(), const QVariant &status = QVariant());
void updatePetWithForm(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &name = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<QString> &status = ::test_namespace::OptionalParam<QString>());
/**
* @param[in] pet_id qint64 [required]
* @param[in] additional_metadata QString [optional]
* @param[in] file PFXHttpFileElement [optional]
*/
void uploadFile(const qint64 &pet_id, const QVariant &additional_metadata = QVariant(), const QVariant &file = QVariant());
void uploadFile(const qint64 &pet_id, const ::test_namespace::OptionalParam<QString> &additional_metadata = ::test_namespace::OptionalParam<QString>(), const ::test_namespace::OptionalParam<PFXHttpFileElement> &file = ::test_namespace::OptionalParam<PFXHttpFileElement>());
private:

View File

@ -10,7 +10,6 @@
*/
#include "PFXStoreApi.h"
#include "PFXHelpers.h"
#include "PFXServerConfiguration.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -29,7 +28,6 @@ PFXStoreApi::~PFXStoreApi() {
}
void PFXStoreApi::initializeServerConfigs(){
//Default server
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
//varying endpoint server
@ -218,7 +216,6 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
QString fullPath = QString(_serverConfigs["deleteOrder"][_serverIndices.value("deleteOrder")].URL()+"/store/order/{orderId}");
{
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
@ -232,18 +229,18 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "DELETE");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::deleteOrderCallback);
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -280,18 +277,18 @@ void PFXStoreApi::getInventory() {
addHeaders("api_key",_apiKeys.find("api_key").value());
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getInventoryCallback);
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -335,7 +332,6 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
QString fullPath = QString(_serverConfigs["getOrderById"][_serverIndices.value("getOrderById")].URL()+"/store/order/{orderId}");
{
QString order_idPathParam("{");
order_idPathParam.append("orderId").append("}");
@ -349,18 +345,18 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix;
fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getOrderByIdCallback);
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -394,21 +390,22 @@ void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) {
void PFXStoreApi::placeOrder(const PFXOrder &body) {
QString fullPath = QString(_serverConfigs["placeOrder"][_serverIndices.value("placeOrder")].URL()+"/store/order");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
{
QByteArray output = body.asJson().toUtf8();
input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::placeOrderCallback);
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXStoreApi_H
#define PFX_PFXStoreApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h"
@ -24,7 +25,6 @@
#include <QStringList>
#include <QList>
#include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace {

View File

@ -10,7 +10,6 @@
*/
#include "PFXUserApi.h"
#include "PFXHelpers.h"
#include "PFXServerConfiguration.h"
#include <QJsonArray>
#include <QJsonDocument>
@ -29,7 +28,6 @@ PFXUserApi::~PFXUserApi() {
}
void PFXUserApi::initializeServerConfigs(){
//Default server
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
//varying endpoint server
@ -225,21 +223,22 @@ QString PFXUserApi::getParamStyleDelimiter(QString style, QString name, bool isE
void PFXUserApi::createUser(const PFXUser &body) {
QString fullPath = QString(_serverConfigs["createUser"][_serverIndices.value("createUser")].URL()+"/user");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
{
QByteArray output = body.asJson().toUtf8();
input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -272,21 +271,22 @@ void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
QString fullPath = QString(_serverConfigs["createUsersWithArrayInput"][_serverIndices.value("createUsersWithArrayInput")].URL()+"/user/createWithArray");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
{
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -319,21 +319,22 @@ void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker)
void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
QString fullPath = QString(_serverConfigs["createUsersWithListInput"][_serverIndices.value("createUsersWithListInput")].URL()+"/user/createWithList");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST");
{
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson();
input.request_body.append(bytes);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -367,7 +368,6 @@ void PFXUserApi::deleteUser(const QString &username) {
QString fullPath = QString(_serverConfigs["deleteUser"][_serverIndices.value("deleteUser")].URL()+"/user/{username}");
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
@ -381,18 +381,18 @@ void PFXUserApi::deleteUser(const QString &username) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "DELETE");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -426,7 +426,6 @@ void PFXUserApi::getUserByName(const QString &username) {
QString fullPath = QString(_serverConfigs["getUserByName"][_serverIndices.value("getUserByName")].URL()+"/user/{username}");
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
@ -440,18 +439,18 @@ void PFXUserApi::getUserByName(const QString &username) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -485,7 +484,6 @@ void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
void PFXUserApi::loginUser(const QString &username, const QString &password) {
QString fullPath = QString(_serverConfigs["loginUser"][_serverIndices.value("loginUser")].URL()+"/user/login");
QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
@ -503,7 +501,6 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
{
queryStyle = "";
if(queryStyle == "")
@ -518,18 +515,18 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -564,18 +561,18 @@ void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
void PFXUserApi::logoutUser() {
QString fullPath = QString(_serverConfigs["logoutUser"][_serverIndices.value("logoutUser")].URL()+"/user/logout");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});
@ -609,7 +606,6 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
QString fullPath = QString(_serverConfigs["updateUser"][_serverIndices.value("updateUser")].URL()+"/user/{username}");
{
QString usernamePathParam("{");
usernamePathParam.append("username").append("}");
@ -623,21 +619,22 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix;
fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
}
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "PUT");
{
QByteArray output = body.asJson().toUtf8();
input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback);
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){
if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted();
}
});

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXUserApi_H
#define PFX_PFXUserApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h"
@ -24,7 +25,6 @@
#include <QStringList>
#include <QList>
#include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace {