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

View File

@ -2,6 +2,7 @@
#ifndef {{prefix}}_{{classname}}_H #ifndef {{prefix}}_{{classname}}_H
#define {{prefix}}_{{classname}}_H #define {{prefix}}_{{classname}}_H
#include "{{prefix}}Helpers.h"
#include "{{prefix}}HttpRequest.h" #include "{{prefix}}HttpRequest.h"
#include "{{prefix}}ServerConfiguration.h" #include "{{prefix}}ServerConfiguration.h"
@ -13,7 +14,6 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
namespace {{this}} { namespace {{this}} {
@ -57,7 +57,7 @@ public:
{{/required}} {{/required}}
{{/allParams}} {{/allParams}}
*/{{/hasParams}} */{{/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}} {{/operation}}{{/operations}}
private: private:
@ -86,7 +86,7 @@ signals:
{{#operations}}{{#operation}} {{#operations}}{{#operation}}
void {{nickname}}SignalEFull({{prefix}}HttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);{{/operation}}{{/operations}} void {{nickname}}SignalEFull({{prefix}}HttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);{{/operation}}{{/operations}}
void abortRequestsSignal(); void abortRequestsSignal();
void allPendingRequestsCompleted(); void allPendingRequestsCompleted();
}; };

View File

@ -11,7 +11,6 @@
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QSet> #include <QSet>
#include <QVariant>
#include "{{prefix}}Enum.h" #include "{{prefix}}Enum.h"
#include "{{prefix}}HttpFileElement.h" #include "{{prefix}}HttpFileElement.h"
@ -21,6 +20,27 @@
namespace {{this}} { namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/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&); bool setDateTimeFormat(const QString&);
template <typename T> template <typename T>

View File

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

View File

@ -21,7 +21,6 @@
#include <QList> #include <QList>
#include <QMap> #include <QMap>
#include <QSet> #include <QSet>
#include <QVariant>
#include "PFXEnum.h" #include "PFXEnum.h"
#include "PFXHttpFileElement.h" #include "PFXHttpFileElement.h"
@ -29,6 +28,27 @@
namespace test_namespace { 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&); bool setDateTimeFormat(const QString&);
template <typename T> template <typename T>

View File

@ -10,7 +10,6 @@
*/ */
#include "PFXPetApi.h" #include "PFXPetApi.h"
#include "PFXHelpers.h"
#include "PFXServerConfiguration.h" #include "PFXServerConfiguration.h"
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@ -29,7 +28,6 @@ PFXPetApi::~PFXPetApi() {
} }
void PFXPetApi::initializeServerConfigs(){ void PFXPetApi::initializeServerConfigs(){
//Default server //Default server
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>(); QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
//varying endpoint server //varying endpoint server
@ -38,22 +36,22 @@ void PFXPetApi::initializeServerConfigs(){
QUrl("http://petstore.swagger.io/v2"), QUrl("http://petstore.swagger.io/v2"),
"No description provided", "No description provided",
QMap<QString, PFXServerVariable>())); QMap<QString, PFXServerVariable>()));
_serverConfigs.insert("addPet",defaultConf); _serverConfigs.insert("addPet", defaultConf);
_serverIndices.insert("addPet",0); _serverIndices.insert("addPet", 0);
_serverConfigs.insert("deletePet",defaultConf); _serverConfigs.insert("deletePet", defaultConf);
_serverIndices.insert("deletePet",0); _serverIndices.insert("deletePet", 0);
_serverConfigs.insert("findPetsByStatus",defaultConf); _serverConfigs.insert("findPetsByStatus", defaultConf);
_serverIndices.insert("findPetsByStatus",0); _serverIndices.insert("findPetsByStatus", 0);
_serverConfigs.insert("findPetsByTags",defaultConf); _serverConfigs.insert("findPetsByTags", defaultConf);
_serverIndices.insert("findPetsByTags",0); _serverIndices.insert("findPetsByTags", 0);
_serverConfigs.insert("getPetById",defaultConf); _serverConfigs.insert("getPetById", defaultConf);
_serverIndices.insert("getPetById",0); _serverIndices.insert("getPetById", 0);
_serverConfigs.insert("updatePet",defaultConf); _serverConfigs.insert("updatePet", defaultConf);
_serverIndices.insert("updatePet",0); _serverIndices.insert("updatePet", 0);
_serverConfigs.insert("updatePetWithForm",defaultConf); _serverConfigs.insert("updatePetWithForm", defaultConf);
_serverIndices.insert("updatePetWithForm",0); _serverIndices.insert("updatePetWithForm", 0);
_serverConfigs.insert("uploadFile",defaultConf); _serverConfigs.insert("uploadFile", defaultConf);
_serverIndices.insert("uploadFile",0); _serverIndices.insert("uploadFile", 0);
} }
/** /**
@ -225,21 +223,22 @@ QString PFXPetApi::getParamStyleDelimiter(QString style, QString name, bool isEx
void PFXPetApi::addPet(const PFXPet &body) { void PFXPetApi::addPet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
{
QByteArray output = body.asJson().toUtf8(); QByteArray output = body.asJson().toUtf8();
input.request_body.append(output); input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -269,10 +268,9 @@ 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 fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}");
{ {
QString pet_idPathParam("{"); QString pet_idPathParam("{");
@ -287,24 +285,24 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "DELETE"); PFXHttpRequestInput input(fullPath, "DELETE");
if(!api_key.isNull())
if(api_key.hasValue())
{ {
if (!::test_namespace::toStringValue(api_key.value<QString>()).isEmpty()) { if (!::test_namespace::toStringValue(api_key.value()).isEmpty()) {
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value<QString>())); 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)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -337,7 +335,6 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByStatus(const QList<QString> &status) { void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus"); QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus");
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{ {
@ -347,7 +344,7 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
queryPrefix = getParamStylePrefix(queryStyle); queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle); querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false); queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false);
if (status.size() > 0) { if(status.size() > 0) {
if (QString("csv").indexOf("multi") == 0) { if (QString("csv").indexOf("multi") == 0) {
foreach (QString t, status) { foreach (QString t, status) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
@ -424,18 +421,18 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
} }
} }
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET"); PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -478,7 +475,6 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByTags(const QList<QString> &tags) { void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags"); QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags");
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{ {
@ -488,7 +484,7 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
queryPrefix = getParamStylePrefix(queryStyle); queryPrefix = getParamStylePrefix(queryStyle);
querySuffix = getParamStyleSuffix(queryStyle); querySuffix = getParamStyleSuffix(queryStyle);
queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false); queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false);
if (tags.size() > 0) { if(tags.size() > 0) {
if (QString("csv").indexOf("multi") == 0) { if (QString("csv").indexOf("multi") == 0) {
foreach (QString t, tags) { foreach (QString t, tags) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
@ -565,18 +561,18 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
} }
} }
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET"); PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -623,7 +619,6 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
addHeaders("api_key",_apiKeys.find("api_key").value()); addHeaders("api_key",_apiKeys.find("api_key").value());
} }
{ {
QString pet_idPathParam("{"); QString pet_idPathParam("{");
@ -638,18 +633,18 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "GET"); PFXHttpRequestInput input(fullPath, "GET");
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -683,21 +678,22 @@ void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::updatePet(const PFXPet &body) { void PFXPetApi::updatePet(const PFXPet &body) {
QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet");
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "PUT"); PFXHttpRequestInput input(fullPath, "PUT");
{
QByteArray output = body.asJson().toUtf8(); QByteArray output = body.asJson().toUtf8();
input.request_body.append(output); input.request_body.append(output);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback); connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -727,10 +723,9 @@ 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 fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}");
{ {
QString pet_idPathParam("{"); QString pet_idPathParam("{");
@ -745,22 +740,18 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, co
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
if(name.hasValue())
if(!name.isNull())
{ {
input.add_var("name", ::test_namespace::toStringValue(name.value<QString>())); input.add_var("name", ::test_namespace::toStringValue(name.value()));
} }
if(status.hasValue())
if(!status.isNull())
{ {
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)); } 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(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });
@ -798,10 +789,9 @@ 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 fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage");
{ {
QString pet_idPathParam("{"); QString pet_idPathParam("{");
@ -816,22 +806,18 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_meta
QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix;
fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id)));
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
PFXHttpRequestInput input(fullPath, "POST"); PFXHttpRequestInput input(fullPath, "POST");
if(additional_metadata.hasValue())
if(!additional_metadata.isNull())
{ {
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value<QString>())); input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value()));
} }
if(file.hasValue())
if(!file.isNull())
{ {
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)); } 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(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
connect(worker, &QObject::destroyed, [this](){ connect(worker, &QObject::destroyed, [this](){
if(findChildren<PFXHttpRequestWorker>().count() == 0){ if(findChildren<PFXHttpRequestWorker*>().count() == 0){
emit allPendingRequestsCompleted(); emit allPendingRequestsCompleted();
} }
}); });

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXPetApi_H #ifndef PFX_PFXPetApi_H
#define PFX_PFXPetApi_H #define PFX_PFXPetApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h" #include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h" #include "PFXServerConfiguration.h"
@ -25,7 +26,6 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -66,7 +66,7 @@ public:
* @param[in] pet_id qint64 [required] * @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional] * @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] * @param[in] status QList<QString> [required]
@ -93,14 +93,14 @@ public:
* @param[in] name QString [optional] * @param[in] name QString [optional]
* @param[in] status 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] pet_id qint64 [required]
* @param[in] additional_metadata QString [optional] * @param[in] additional_metadata QString [optional]
* @param[in] file PFXHttpFileElement [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: private:
@ -164,7 +164,7 @@ signals:
void updatePetWithFormSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void updatePetWithFormSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void uploadFileSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void uploadFileSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void abortRequestsSignal(); void abortRequestsSignal();
void allPendingRequestsCompleted(); void allPendingRequestsCompleted();
}; };

View File

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

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXStoreApi_H #ifndef PFX_PFXStoreApi_H
#define PFX_PFXStoreApi_H #define PFX_PFXStoreApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h" #include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h" #include "PFXServerConfiguration.h"
@ -24,7 +25,6 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -116,7 +116,7 @@ signals:
void getOrderByIdSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void getOrderByIdSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void placeOrderSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void placeOrderSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void abortRequestsSignal(); void abortRequestsSignal();
void allPendingRequestsCompleted(); void allPendingRequestsCompleted();
}; };

View File

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

View File

@ -12,6 +12,7 @@
#ifndef PFX_PFXUserApi_H #ifndef PFX_PFXUserApi_H
#define PFX_PFXUserApi_H #define PFX_PFXUserApi_H
#include "PFXHelpers.h"
#include "PFXHttpRequest.h" #include "PFXHttpRequest.h"
#include "PFXServerConfiguration.h" #include "PFXServerConfiguration.h"
@ -24,7 +25,6 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -158,7 +158,7 @@ signals:
void logoutUserSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void logoutUserSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void updateUserSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void updateUserSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);
void abortRequestsSignal(); void abortRequestsSignal();
void allPendingRequestsCompleted(); void allPendingRequestsCompleted();
}; };