[QT5] Support optional params using QVariant (#8733)

Use QVariant for optional parameters
This commit is contained in:
Sean Kelly 2021-03-02 22:45:04 -08:00 committed by GitHub
parent d31875f505
commit 89b9802be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 800 additions and 606 deletions

View File

@ -227,7 +227,7 @@ QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool
{{#operations}} {{#operations}}
{{#operation}} {{#operation}}
void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) { void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} &{{/required}}{{^required}}const QVariant &{{/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}}")){
@ -250,7 +250,10 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}
{
QString {{paramName}}PathParam("{"); QString {{paramName}}PathParam("{");
{{paramName}}PathParam.append("{{baseName}}").append("}"); {{paramName}}PathParam.append("{{baseName}}").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -263,7 +266,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
{{^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}}.asJsonObject(); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/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,12 +310,14 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
{{/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}}))); fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} {{/isPrimitiveType}}
if ({{{paramName}}}.size() > 0) { {{/collectionFormat}}
{{#collectionFormat}}
if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(pathDelimiter); fullPath.append(pathDelimiter);
} }
@ -321,11 +326,16 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
} }
fullPath.replace({{paramName}}PathParam, paramString); fullPath.replace({{paramName}}PathParam, paramString);
} }
{{/collectionFormat}}{{/pathParams}} {{/collectionFormat}}
}
{{/pathParams}}
{{#hasQueryParams}} {{#hasQueryParams}}
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{{/hasQueryParams}} {{/hasQueryParams}}
{{#queryParams}} {{#queryParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{
queryStyle = "{{style}}"; queryStyle = "{{style}}";
if(queryStyle == "") if(queryStyle == "")
queryStyle = "form"; queryStyle = "form";
@ -339,7 +349,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}.asJsonObject(); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/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) {
@ -385,11 +395,13 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
} }
fullPath.append(paramString); fullPath.append(paramString);
{{/isPrimitiveType}}{{#isPrimitiveType}} {{/isPrimitiveType}}{{#isPrimitiveType}}
fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})));
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} {{/isPrimitiveType}}
if ({{{paramName}}}.size() > 0) { {{/collectionFormat}}
{{#collectionFormat}}
if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
if (QString("{{collectionFormat}}").indexOf("multi") == 0) { if (QString("{{collectionFormat}}").indexOf("multi") == 0) {
foreach ({{{baseType}}} t, {{paramName}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (fullPath.indexOf("?") > 0) if (fullPath.indexOf("?") > 0)
fullPath.append(queryPrefix); fullPath.append(queryPrefix);
else else
@ -402,7 +414,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter));
} }
@ -415,7 +427,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append("\t"); fullPath.append("\t");
} }
@ -428,7 +440,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(queryDelimiter); fullPath.append(queryDelimiter);
} }
@ -441,7 +453,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(queryDelimiter); fullPath.append(queryDelimiter);
} }
@ -454,7 +466,7 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
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}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
fullPath.append(queryDelimiter); fullPath.append(queryDelimiter);
} }
@ -463,7 +475,10 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
} }
} }
} }
{{/collectionFormat}}{{/queryParams}} {{/collectionFormat}}
}
{{/queryParams}}
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager); {{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}} worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}}
@ -481,22 +496,39 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
formSuffix = getParamStyleSuffix(formStyle); formSuffix = getParamStyleSuffix(formStyle);
formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}}); formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}});
{{/first}} {{/first}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{
{{^isFile}} {{^isFile}}
input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}} input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
input.add_file("{{baseName}}", {{paramName}}.local_filename, {{paramName}}.request_filename, {{paramName}}.mime_type);{{/isFile}}{{/formParams}}{{#bodyParams}}{{#isContainer}}{{#isArray}} {{/isFile}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toArray());{{/isArray}}{{#isMap}} {{#isFile}}
QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toObject());{{/isMap}} 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);
{{/isFile}}
}
{{/formParams}}
{{#bodyParams}}
{{#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}}
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}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}} QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}});{{/isByteArray}}{{^isString}}{{^isByteArray}}{{^isFile}}
QByteArray output = {{paramName}}.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}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}}
QByteArray output = {{paramName}}.asByteArray();{{/isFile}} QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asByteArray();{{/isFile}}
input.request_body.append(output); input.request_body.append(output);
{{/isContainer}}{{/bodyParams}}{{#headerParams}} {{/isContainer}}
{{^collectionFormat}}{{^isPrimitiveType}} {{/bodyParams}}
{{#headerParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{
{{^collectionFormat}}
{{^isPrimitiveType}}
QString headerString; QString headerString;
QJsonObject parameter = {{paramName}}.asJsonObject(); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/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) {
@ -536,15 +568,16 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
count++; count++;
} }
input.headers.insert("{{baseName}}", headerString); input.headers.insert("{{baseName}}", headerString);
{{/isPrimitiveType}}{{#isPrimitiveType}} {{/isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) { {{#isPrimitiveType}}
input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}})); if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
} }
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} {{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}
QString headerString; QString headerString;
if ({{{paramName}}}.size() > 0) { if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) {
qint32 count = 0; qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
headerString.append(","); headerString.append(",");
} }
@ -554,12 +587,17 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName
input.headers.insert("{{baseName}}", headerString); input.headers.insert("{{baseName}}", headerString);
} }
{{/collectionFormat}} {{/collectionFormat}}
}
{{/headerParams}} {{/headerParams}}
{{#cookieParams}} {{#cookieParams}}
{{^required}}if(!{{paramName}}.isNull()){{/required}}
{
if(QString("{{style}}").indexOf("form") == 0){ if(QString("{{style}}").indexOf("form") == 0){
{{^collectionFormat}}{{^isPrimitiveType}}{{^isExplode}} {{^collectionFormat}}
{{^isPrimitiveType}}
{{^isExplode}}
QString cookieString = "{{baseName}}="; QString cookieString = "{{baseName}}=";
QJsonObject parameter = {{paramName}}.asJsonObject(); QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/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) {
@ -598,15 +636,20 @@ if(QString("{{style}}").indexOf("form") == 0){
count++; count++;
} }
input.headers.insert("Cookie", cookieString); input.headers.insert("Cookie", cookieString);
{{/isExplode}}{{/isPrimitiveType}}{{#isPrimitiveType}} {{/isExplode}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) { {{/isPrimitiveType}}
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}})); {{#isPrimitiveType}}
if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) {
input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}));
} }
{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}{{^isExplode}} {{/isPrimitiveType}}
{{/collectionFormat}}
{{#collectionFormat}}
{{^isExplode}}
QString cookieString = "{{baseName}}="; QString cookieString = "{{baseName}}=";
if ({{{paramName}}}.size() > 0) { if ({{{paramName}}}.size() > 0) {
qint32 count = 0; qint32 count = 0;
foreach ({{{baseType}}} t, {{paramName}}) { foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) {
if (count > 0) { if (count > 0) {
cookieString.append(","); cookieString.append(",");
} }
@ -617,6 +660,7 @@ if(QString("{{style}}").indexOf("form") == 0){
} }
{{/isExplode}}{{/collectionFormat}} {{/isExplode}}{{/collectionFormat}}
} }
}
{{/cookieParams}} {{/cookieParams}}
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)); }

View File

@ -13,6 +13,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
namespace {{this}} { namespace {{this}} {
@ -46,7 +47,18 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
{{#operations}}{{#operation}} {{#operations}}{{#operation}}
{{#isDeprecated}}Q_DECL_DEPRECATED {{/isDeprecated}}void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{/operation}}{{/operations}} {{#hasParams}} /**
{{#allParams}}
{{#required}}
* @param[in] {{paramName}} {{{dataType}}} [required]
{{/required}}
{{^required}}
* @param[in] {{paramName}} {{{dataType}}} [optional]
{{/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}});
{{/operation}}{{/operations}}
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;

View File

@ -235,7 +235,7 @@ void PetApiTests::updatePetWithFormTest() {
}); });
QString name("gorilla"); QString name("gorilla");
api.updatePetWithForm(id, name, nullptr); api.updatePetWithForm(id, name);
QTimer::singleShot(5000, &loop, &QEventLoop::quit); QTimer::singleShot(5000, &loop, &QEventLoop::quit);
loop.exec(); loop.exec();
QVERIFY2(petUpdated, "didn't finish within timeout"); QVERIFY2(petUpdated, "didn't finish within timeout");

View File

@ -235,7 +235,6 @@ 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);
@ -273,9 +272,12 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &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("{");
pet_idPathParam.append("petId").append("}"); pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -287,17 +289,18 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
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 (!::test_namespace::toStringValue(api_key).isEmpty()) { if (!::test_namespace::toStringValue(api_key.value<QString>()).isEmpty()) {
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key)); input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value<QString>()));
}
} }
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)); }
@ -333,13 +336,14 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
queryStyle = "form"; queryStyle = "form";
if(queryStyle == "") if(queryStyle == "")
queryStyle = "form"; queryStyle = "form";
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) {
@ -416,6 +420,7 @@ 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);
@ -466,13 +471,14 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
queryStyle = "form"; queryStyle = "form";
if(queryStyle == "") if(queryStyle == "")
queryStyle = "form"; queryStyle = "form";
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) {
@ -549,6 +555,7 @@ 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);
@ -601,6 +608,9 @@ 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("{");
pet_idPathParam.append("petId").append("}"); pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -612,7 +622,7 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
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);
@ -653,7 +663,6 @@ 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);
@ -691,9 +700,12 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, const QString &status) { void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, const QVariant &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("{");
pet_idPathParam.append("petId").append("}"); pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -705,14 +717,26 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, con
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
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");
input.add_var("name", ::test_namespace::toStringValue(name)); input.add_var("status", ::test_namespace::toStringValue(status)); foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
if(!name.isNull())
{
input.add_var("name", ::test_namespace::toStringValue(name.value<QString>()));
}
if(!status.isNull())
{
input.add_var("status", ::test_namespace::toStringValue(status.value<QString>()));
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
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);
@ -741,9 +765,12 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
} }
} }
void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file) { void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_metadata, const QVariant &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("{");
pet_idPathParam.append("petId").append("}"); pet_idPathParam.append("petId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -755,15 +782,26 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metad
pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false);
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");
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata));
input.add_file("file", file.local_filename, file.request_filename, file.mime_type); foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } if(!additional_metadata.isNull())
{
input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata.value<QString>()));
}
if(!file.isNull())
{
input.add_file("file", file.value<PFXHttpFileElement>().local_filename, file.value<PFXHttpFileElement>().request_filename, file.value<PFXHttpFileElement>().mime_type);
}
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
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);

View File

@ -25,6 +25,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -56,14 +57,51 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] body PFXPet [required]
*/
void addPet(const PFXPet &body); void addPet(const PFXPet &body);
void deletePet(const qint64 &pet_id, const QString &api_key);
/**
* @param[in] pet_id qint64 [required]
* @param[in] api_key QString [optional]
*/
void deletePet(const qint64 &pet_id, const QVariant &api_key = QVariant());
/**
* @param[in] status QList<QString> [required]
*/
void findPetsByStatus(const QList<QString> &status); void findPetsByStatus(const QList<QString> &status);
/**
* @param[in] tags QList<QString> [required]
*/
Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags); Q_DECL_DEPRECATED void findPetsByTags(const QList<QString> &tags);
/**
* @param[in] pet_id qint64 [required]
*/
void getPetById(const qint64 &pet_id); void getPetById(const qint64 &pet_id);
/**
* @param[in] body PFXPet [required]
*/
void updatePet(const PFXPet &body); void updatePet(const PFXPet &body);
void updatePetWithForm(const qint64 &pet_id, const QString &name, const QString &status);
void uploadFile(const qint64 &pet_id, const QString &additional_metadata, const PFXHttpFileElement &file); /**
* @param[in] pet_id qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
void updatePetWithForm(const qint64 &pet_id, const QVariant &name = QVariant(), const QVariant &status = QVariant());
/**
* @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());
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;

View File

@ -222,6 +222,9 @@ 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("{");
order_idPathParam.append("orderId").append("}"); order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -233,7 +236,7 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
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);
@ -277,7 +280,6 @@ void PFXStoreApi::getInventory() {
} }
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager);
worker->setTimeOut(_timeOut); worker->setTimeOut(_timeOut);
worker->setWorkingDirectory(_workingDirectory); worker->setWorkingDirectory(_workingDirectory);
@ -325,6 +327,9 @@ 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("{");
order_idPathParam.append("orderId").append("}"); order_idPathParam.append("orderId").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -336,7 +341,7 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
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);
@ -377,7 +382,6 @@ 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);

View File

@ -24,6 +24,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -55,11 +56,25 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] order_id QString [required]
*/
void deleteOrder(const QString &order_id); void deleteOrder(const QString &order_id);
void getInventory(); void getInventory();
/**
* @param[in] order_id qint64 [required]
*/
void getOrderById(const qint64 &order_id); void getOrderById(const qint64 &order_id);
/**
* @param[in] body PFXOrder [required]
*/
void placeOrder(const PFXOrder &body); void placeOrder(const PFXOrder &body);
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs; QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;

View File

@ -235,7 +235,6 @@ 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);
@ -277,13 +276,11 @@ 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()); QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -320,13 +317,11 @@ 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()); QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
QByteArray bytes = doc.toJson(); QByteArray bytes = doc.toJson();
input.request_body.append(bytes); input.request_body.append(bytes);
@ -362,6 +357,9 @@ 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("{");
usernamePathParam.append("username").append("}"); usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -373,7 +371,7 @@ void PFXUserApi::deleteUser(const QString &username) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
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);
@ -412,6 +410,9 @@ 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("{");
usernamePathParam.append("username").append("}"); usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -423,7 +424,7 @@ void PFXUserApi::getUserByName(const QString &username) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
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);
@ -465,6 +466,8 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
QString queryPrefix, querySuffix, queryDelimiter, queryStyle; QString queryPrefix, querySuffix, queryDelimiter, queryStyle;
{
queryStyle = ""; queryStyle = "";
if(queryStyle == "") if(queryStyle == "")
queryStyle = "form"; queryStyle = "form";
@ -477,6 +480,10 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
fullPath.append("?"); fullPath.append("?");
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 = "";
if(queryStyle == "") if(queryStyle == "")
queryStyle = "form"; queryStyle = "form";
@ -489,6 +496,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
fullPath.append("?"); fullPath.append("?");
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);
@ -530,7 +538,6 @@ 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);
@ -568,6 +575,9 @@ 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("{");
usernamePathParam.append("username").append("}"); usernamePathParam.append("username").append("}");
QString pathPrefix, pathSuffix, pathDelimiter; QString pathPrefix, pathSuffix, pathDelimiter;
@ -579,7 +589,7 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false);
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);

View File

@ -24,6 +24,7 @@
#include <QStringList> #include <QStringList>
#include <QList> #include <QList>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
#include <QVariant>
namespace test_namespace { namespace test_namespace {
@ -55,15 +56,47 @@ public:
QString getParamStyleSuffix(QString style); QString getParamStyleSuffix(QString style);
QString getParamStyleDelimiter(QString style, QString name, bool isExplode); QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
/**
* @param[in] body PFXUser [required]
*/
void createUser(const PFXUser &body); void createUser(const PFXUser &body);
/**
* @param[in] body QList<PFXUser> [required]
*/
void createUsersWithArrayInput(const QList<PFXUser> &body); void createUsersWithArrayInput(const QList<PFXUser> &body);
/**
* @param[in] body QList<PFXUser> [required]
*/
void createUsersWithListInput(const QList<PFXUser> &body); void createUsersWithListInput(const QList<PFXUser> &body);
/**
* @param[in] username QString [required]
*/
void deleteUser(const QString &username); void deleteUser(const QString &username);
/**
* @param[in] username QString [required]
*/
void getUserByName(const QString &username); void getUserByName(const QString &username);
/**
* @param[in] username QString [required]
* @param[in] password QString [required]
*/
void loginUser(const QString &username, const QString &password); void loginUser(const QString &username, const QString &password);
void logoutUser(); void logoutUser();
/**
* @param[in] username QString [required]
* @param[in] body PFXUser [required]
*/
void updateUser(const QString &username, const PFXUser &body); void updateUser(const QString &username, const PFXUser &body);
private: private:
QMap<QString,int> _serverIndices; QMap<QString,int> _serverIndices;
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs; QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;