From 89b9802be3ffd3ea527a8be76745d75c7d875ce0 Mon Sep 17 00:00:00 2001 From: Sean Kelly Date: Tue, 2 Mar 2021 22:45:04 -0800 Subject: [PATCH] [QT5] Support optional params using QVariant (#8733) Use QVariant for optional parameters --- .../cpp-qt5-client/api-body.mustache | 672 ++++++++++-------- .../cpp-qt5-client/api-header.mustache | 14 +- .../petstore/cpp-qt5/PetStore/PetApiTests.cpp | 2 +- .../petstore/cpp-qt5/client/PFXPetApi.cpp | 442 ++++++------ .../petstore/cpp-qt5/client/PFXPetApi.h | 44 +- .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 52 +- .../petstore/cpp-qt5/client/PFXStoreApi.h | 15 + .../petstore/cpp-qt5/client/PFXUserApi.cpp | 132 ++-- .../petstore/cpp-qt5/client/PFXUserApi.h | 33 + 9 files changed, 800 insertions(+), 606 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache index c1b3705fb3c..855560a0b0d 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache @@ -227,7 +227,7 @@ QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool {{#operations}} {{#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}}}"); {{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} if(_apiKeys.contains("{{name}}")){ @@ -250,220 +250,235 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName b64.append(_username.toUtf8() + ":" + _password.toUtf8()); addHeaders("Authorization","Basic " + b64.toBase64()); }{{/isBasicBasic}}{{/authMethods}} + {{#pathParams}} - QString {{paramName}}PathParam("{"); - {{paramName}}PathParam.append("{{baseName}}").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = "{{style}}"; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "{{baseName}}", {{isExplode}}); + {{^required}}if(!{{paramName}}.isNull()){{/required}} + { + QString {{paramName}}PathParam("{"); + {{paramName}}PathParam.append("{{baseName}}").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = "{{style}}"; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "{{baseName}}", {{isExplode}}); {{^collectionFormat}} - {{^isPrimitiveType}} - QString paramString = (pathStyle == "matrix" && {{isExplode}}) ? pathPrefix : pathPrefix+"{{baseName}}"+pathSuffix; - QJsonObject parameter = {{paramName}}.asJsonObject(); - qint32 count = 0; - foreach(const QString& key, parameter.keys()) { - if (count > 0) { - pathDelimiter = (pathStyle == "matrix" && {{isExplode}}) ? ";" : getParamStyleDelimiter(pathStyle, key, {{isExplode}}); - paramString.append(pathDelimiter); + {{^isPrimitiveType}} + QString paramString = (pathStyle == "matrix" && {{isExplode}}) ? pathPrefix : pathPrefix+"{{baseName}}"+pathSuffix; + QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject(); + qint32 count = 0; + foreach(const QString& key, parameter.keys()) { + if (count > 0) { + pathDelimiter = (pathStyle == "matrix" && {{isExplode}}) ? ";" : getParamStyleDelimiter(pathStyle, key, {{isExplode}}); + paramString.append(pathDelimiter); + } + QString assignOperator = ({{isExplode}}) ? "=" : ","; + switch(parameter.value(key).type()) { + case QJsonValue::String: + { + paramString.append(key+assignOperator+parameter.value(key).toString()); + break; + } + case QJsonValue::Double: + { + paramString.append(key+assignOperator+QString::number(parameter.value(key).toDouble())); + break; + } + case QJsonValue::Bool: + { + paramString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString()); + break; + } + case QJsonValue::Array: + { + paramString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString()); + break; + } + case QJsonValue::Object: + { + paramString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString()); + break; + } + case QJsonValue::Null: + case QJsonValue::Undefined: + break; + } + count++; } - QString assignOperator = ({{isExplode}}) ? "=" : ","; - switch(parameter.value(key).type()) { - case QJsonValue::String: - { - paramString.append(key+assignOperator+parameter.value(key).toString()); - break; - } - case QJsonValue::Double: - { - paramString.append(key+assignOperator+QString::number(parameter.value(key).toDouble())); - break; - } - case QJsonValue::Bool: - { - paramString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString()); - break; - } - case QJsonValue::Array: - { - paramString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString()); - break; - } - case QJsonValue::Object: - { - paramString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString()); - break; - } - case QJsonValue::Null: - case QJsonValue::Undefined: - break; - } - count++; - } - fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(paramString)); - {{/isPrimitiveType}} - {{#isPrimitiveType}} - QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix; - fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); -{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} - if ({{{paramName}}}.size() > 0) { + fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(paramString)); + {{/isPrimitiveType}} + {{#isPrimitiveType}} + QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix; + fullPath.replace({{paramName}}PathParam, paramString+QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}))); + {{/isPrimitiveType}} + {{/collectionFormat}} + {{#collectionFormat}} + if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) { QString paramString = (pathStyle == "matrix") ? pathPrefix+"{{baseName}}"+pathSuffix : pathPrefix; qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { if (count > 0) { fullPath.append(pathDelimiter); } fullPath.append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue(t))); count++; } - fullPath.replace({{paramName}}PathParam, paramString); + fullPath.replace({{paramName}}PathParam, paramString); + } + {{/collectionFormat}} } -{{/collectionFormat}}{{/pathParams}} + + {{/pathParams}} {{#hasQueryParams}} QString queryPrefix, querySuffix, queryDelimiter, queryStyle; {{/hasQueryParams}} -{{#queryParams}} - queryStyle = "{{style}}"; - if(queryStyle == "") - queryStyle = "form"; - queryPrefix = getParamStylePrefix(queryStyle); - querySuffix = getParamStyleSuffix(queryStyle); - queryDelimiter = getParamStyleDelimiter(queryStyle, "{{baseName}}", {{isExplode}}); -{{^collectionFormat}} - if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); - else - fullPath.append("?"); - {{^isPrimitiveType}} - QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : ""; - QJsonObject parameter = {{paramName}}.asJsonObject(); - qint32 count = 0; - foreach(const QString& key, parameter.keys()) { - if (count > 0) { - queryDelimiter = ((queryStyle == "form" || queryStyle == "deepObject") && {{isExplode}}) ? "&" : getParamStyleDelimiter(queryStyle, key, {{isExplode}}); - paramString.append(queryDelimiter); + {{#queryParams}} + {{^required}}if(!{{paramName}}.isNull()){{/required}} + { + queryStyle = "{{style}}"; + if(queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "{{baseName}}", {{isExplode}}); + {{^collectionFormat}} + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + {{^isPrimitiveType}} + QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : ""; + QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject(); + qint32 count = 0; + foreach(const QString& key, parameter.keys()) { + if (count > 0) { + queryDelimiter = ((queryStyle == "form" || queryStyle == "deepObject") && {{isExplode}}) ? "&" : getParamStyleDelimiter(queryStyle, key, {{isExplode}}); + paramString.append(queryDelimiter); + } + QString assignOperator; + if (queryStyle == "form") + assignOperator = ({{isExplode}}) ? "=" : ","; + else if (queryStyle == "deepObject") + assignOperator = ({{isExplode}}) ? "=" : "none"; + switch(parameter.value(key).type()) { + case QJsonValue::String: + { + paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+parameter.value(key).toString()); + break; + } + case QJsonValue::Double: + { + paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QString::number(parameter.value(key).toDouble())); + break; + } + case QJsonValue::Bool: + { + paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toBool()).toString()); + break; + } + case QJsonValue::Array: + { + paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toArray()).toString()); + break; + } + case QJsonValue::Object: + { + paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toObject()).toString()); + break; + } + case QJsonValue::Null: + case QJsonValue::Undefined: + break; + } + count++; } - QString assignOperator; - if (queryStyle == "form") - assignOperator = ({{isExplode}}) ? "=" : ","; - else if (queryStyle == "deepObject") - assignOperator = ({{isExplode}}) ? "=" : "none"; - switch(parameter.value(key).type()) { - case QJsonValue::String: - { - paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+parameter.value(key).toString()); - break; - } - case QJsonValue::Double: - { - paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QString::number(parameter.value(key).toDouble())); - break; - } - case QJsonValue::Bool: - { - paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toBool()).toString()); - break; - } - case QJsonValue::Array: - { - paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toArray()).toString()); - break; - } - case QJsonValue::Object: - { - paramString.append(((queryStyle == "form") ? key : QString("{{baseName}}").append("[").append(key).append("]"))+assignOperator+QVariant(parameter.value(key).toObject()).toString()); - break; - } - case QJsonValue::Null: - case QJsonValue::Undefined: - break; - } - count++; - } - fullPath.append(paramString); - {{/isPrimitiveType}}{{#isPrimitiveType}} - fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); -{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} - if ({{{paramName}}}.size() > 0) { - if (QString("{{collectionFormat}}").indexOf("multi") == 0) { - foreach ({{{baseType}}} t, {{paramName}}) { + fullPath.append(paramString); + {{/isPrimitiveType}}{{#isPrimitiveType}} + fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}))); + {{/isPrimitiveType}} + {{/collectionFormat}} + {{#collectionFormat}} + if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) { + if (QString("{{collectionFormat}}").indexOf("multi") == 0) { + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + fullPath.append("{{{baseName}}}=").append(::{{cppNamespace}}::toStringValue(t)); + } + } else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) { if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); + fullPath.append("&"); else - fullPath.append("?"); - fullPath.append("{{{baseName}}}=").append(::{{cppNamespace}}::toStringValue(t)); - } - } else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + fullPath.append(({{isExplode}})? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + } + fullPath.append(::{{cppNamespace}}::toStringValue(t)); + count++; } - fullPath.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } - } else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - fullPath.append("\t"); + } else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + fullPath.append("\t"); + } + fullPath.append(::{{cppNamespace}}::toStringValue(t)); + count++; } - fullPath.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } - } else if (QString("{{collectionFormat}}").indexOf("csv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("{{collectionFormat}}").indexOf("csv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::{{cppNamespace}}::toStringValue(t)); + count++; } - fullPath.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } - } else if (QString("{{collectionFormat}}").indexOf("pipes") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("{{collectionFormat}}").indexOf("pipes") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::{{cppNamespace}}::toStringValue(t)); + count++; } - fullPath.append(::{{cppNamespace}}::toStringValue(t)); - count++; + } else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::{{cppNamespace}}::toStringValue(t)); + count++; + } } - } else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("{{baseName}}").append(querySuffix); - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - fullPath.append(queryDelimiter); - } - fullPath.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } } + {{/collectionFormat}} } -{{/collectionFormat}}{{/queryParams}} + +{{/queryParams}} {{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}} @@ -481,142 +496,171 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName formSuffix = getParamStyleSuffix(formStyle); formDelimiter = getParamStyleDelimiter(formStyle, "{{baseName}}", {{isExplode}}); {{/first}} + + {{^required}}if(!{{paramName}}.isNull()){{/required}} + { {{^isFile}} - input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}} - input.add_file("{{baseName}}", {{paramName}}.local_filename, {{paramName}}.request_filename, {{paramName}}.mime_type);{{/isFile}}{{/formParams}}{{#bodyParams}}{{#isContainer}}{{#isArray}} - QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toArray());{{/isArray}}{{#isMap}} - QJsonDocument doc(::{{cppNamespace}}::toJsonValue({{paramName}}).toObject());{{/isMap}} + input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})); +{{/isFile}} +{{#isFile}} + input.add_file("{{baseName}}", {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.local_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.request_filename, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.mime_type); +{{/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(); input.request_body.append(bytes); {{/isContainer}}{{^isContainer}}{{#isString}} - QByteArray output = {{paramName}}.toUtf8();{{/isString}}{{#isByteArray}}QByteArray output({{paramName}});{{/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}}.asByteArray();{{/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}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJson().toUtf8();{{/isFile}}{{/isByteArray}}{{/isString}}{{#isFile}}{{#hasConsumes}}input.headers.insert("Content-Type", {{#consumes}}{{^-first}}, {{/-first}}"{{mediaType}}"{{/consumes}});{{/hasConsumes}} + QByteArray output = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asByteArray();{{/isFile}} input.request_body.append(output); -{{/isContainer}}{{/bodyParams}}{{#headerParams}} -{{^collectionFormat}}{{^isPrimitiveType}} - QString headerString; - QJsonObject parameter = {{paramName}}.asJsonObject(); - qint32 count = 0; - foreach(const QString& key, parameter.keys()) { - if (count > 0) { - headerString.append(","); +{{/isContainer}} +{{/bodyParams}} +{{#headerParams}} + {{^required}}if(!{{paramName}}.isNull()){{/required}} + { + {{^collectionFormat}} + {{^isPrimitiveType}} + QString headerString; + QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject(); + qint32 count = 0; + foreach(const QString& key, parameter.keys()) { + if (count > 0) { + headerString.append(","); + } + QString assignOperator = ({{isExplode}}) ? "=" : ","; + switch(parameter.value(key).type()) { + case QJsonValue::String: + { + headerString.append(key+assignOperator+parameter.value(key).toString()); + break; + } + case QJsonValue::Double: + { + headerString.append(key+assignOperator+QString::number(parameter.value(key).toDouble())); + break; + } + case QJsonValue::Bool: + { + headerString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString()); + break; + } + case QJsonValue::Array: + { + headerString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString()); + break; + } + case QJsonValue::Object: + { + headerString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString()); + break; + } + case QJsonValue::Null: + case QJsonValue::Undefined: + break; + } + count++; } - QString assignOperator = ({{isExplode}}) ? "=" : ","; - switch(parameter.value(key).type()) { - case QJsonValue::String: - { - headerString.append(key+assignOperator+parameter.value(key).toString()); - break; - } - case QJsonValue::Double: - { - headerString.append(key+assignOperator+QString::number(parameter.value(key).toDouble())); - break; - } - case QJsonValue::Bool: - { - headerString.append(key+assignOperator+QVariant(parameter.value(key).toBool()).toString()); - break; - } - case QJsonValue::Array: - { - headerString.append(key+assignOperator+QVariant(parameter.value(key).toArray()).toString()); - break; - } - case QJsonValue::Object: - { - headerString.append(key+assignOperator+QVariant(parameter.value(key).toObject()).toString()); - break; - } - case QJsonValue::Null: - case QJsonValue::Undefined: - break; + input.headers.insert("{{baseName}}", headerString); + {{/isPrimitiveType}} + {{#isPrimitiveType}} + if (!::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}).isEmpty()) { + input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}})); } - count++; - } - input.headers.insert("{{baseName}}", headerString); -{{/isPrimitiveType}}{{#isPrimitiveType}} - if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) { - input.headers.insert("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}})); - } -{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} - QString headerString; - if ({{{paramName}}}.size() > 0) { - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - headerString.append(","); + {{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}} + QString headerString; + if ({{{paramName}}}{{^required}}.value<{{{dataType}}}>(){{/required}}.size() > 0) { + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + headerString.append(","); + } + headerString.append(::{{cppNamespace}}::toStringValue(t)); + count++; } - headerString.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } - input.headers.insert("{{baseName}}", headerString); - } -{{/collectionFormat}} + input.headers.insert("{{baseName}}", headerString); + } + {{/collectionFormat}} +} {{/headerParams}} {{#cookieParams}} -if(QString("{{style}}").indexOf("form") == 0){ -{{^collectionFormat}}{{^isPrimitiveType}}{{^isExplode}} - QString cookieString = "{{baseName}}="; - QJsonObject parameter = {{paramName}}.asJsonObject(); - qint32 count = 0; - foreach(const QString& key, parameter.keys()) { - if (count > 0) { - cookieString.append(","); + {{^required}}if(!{{paramName}}.isNull()){{/required}} + { + if(QString("{{style}}").indexOf("form") == 0){ + {{^collectionFormat}} + {{^isPrimitiveType}} + {{^isExplode}} + QString cookieString = "{{baseName}}="; + QJsonObject parameter = {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}.asJsonObject(); + qint32 count = 0; + foreach(const QString& key, parameter.keys()) { + if (count > 0) { + cookieString.append(","); + } + switch(parameter.value(key).type()) { + case QJsonValue::String: + { + cookieString.append(key+","+parameter.value(key).toString()); + break; + } + case QJsonValue::Double: + { + cookieString.append(key+","+QString::number(parameter.value(key).toDouble())); + break; + } + case QJsonValue::Bool: + { + cookieString.append(key+","+QVariant(parameter.value(key).toBool()).toString()); + break; + } + case QJsonValue::Array: + { + cookieString.append(key+","+QVariant(parameter.value(key).toArray()).toString()); + break; + } + case QJsonValue::Object: + { + cookieString.append(key+","+QVariant(parameter.value(key).toObject()).toString()); + break; + } + case QJsonValue::Null: + case QJsonValue::Undefined: + break; + } + count++; + } + input.headers.insert("Cookie", cookieString); + {{/isExplode}} + {{/isPrimitiveType}} + {{#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}} + QString cookieString = "{{baseName}}="; + if ({{{paramName}}}.size() > 0) { + qint32 count = 0; + foreach ({{{baseType}}} t, {{paramName}}{{^required}}.value<{{{dataType}}}>(){{/required}}) { + if (count > 0) { + cookieString.append(","); + } + cookieString.append(::{{cppNamespace}}::toStringValue(t)); + count++; + } + input.headers.insert("Cookie", cookieString); + } + {{/isExplode}}{{/collectionFormat}} } - switch(parameter.value(key).type()) { - case QJsonValue::String: - { - cookieString.append(key+","+parameter.value(key).toString()); - break; - } - case QJsonValue::Double: - { - cookieString.append(key+","+QString::number(parameter.value(key).toDouble())); - break; - } - case QJsonValue::Bool: - { - cookieString.append(key+","+QVariant(parameter.value(key).toBool()).toString()); - break; - } - case QJsonValue::Array: - { - cookieString.append(key+","+QVariant(parameter.value(key).toArray()).toString()); - break; - } - case QJsonValue::Object: - { - cookieString.append(key+","+QVariant(parameter.value(key).toObject()).toString()); - break; - } - case QJsonValue::Null: - case QJsonValue::Undefined: - break; - } - count++; } - input.headers.insert("Cookie", cookieString); -{{/isExplode}}{{/isPrimitiveType}}{{#isPrimitiveType}} - if (!::{{cppNamespace}}::toStringValue({{paramName}}).isEmpty()) { - input.headers.insert("Cookie", "{{baseName}}="+::{{cppNamespace}}::toStringValue({{paramName}})); - } -{{/isPrimitiveType}}{{/collectionFormat}}{{#collectionFormat}}{{^isExplode}} - QString cookieString = "{{baseName}}="; - if ({{{paramName}}}.size() > 0) { - qint32 count = 0; - foreach ({{{baseType}}} t, {{paramName}}) { - if (count > 0) { - cookieString.append(","); - } - cookieString.append(::{{cppNamespace}}::toStringValue(t)); - count++; - } - input.headers.insert("Cookie", cookieString); - } -{{/isExplode}}{{/collectionFormat}} -} {{/cookieParams}} foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache index 11ba25f2adc..ec9228f4f6a 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache @@ -13,6 +13,7 @@ #include #include #include +#include {{#cppNamespaceDeclarations}} namespace {{this}} { @@ -46,7 +47,18 @@ public: QString getParamStyleSuffix(QString style); QString getParamStyleDelimiter(QString style, QString name, bool isExplode); {{#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: QMap _serverIndices; diff --git a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp index 41c6ca49056..23f6d04b83d 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp @@ -235,7 +235,7 @@ void PetApiTests::updatePetWithFormTest() { }); QString name("gorilla"); - api.updatePetWithForm(id, name, nullptr); + api.updatePetWithForm(id, name); QTimer::singleShot(5000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY2(petUpdated, "didn't finish within timeout"); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index 0935f41cfce..79cad8362a5 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -235,7 +235,6 @@ void PFXPetApi::addPet(const PFXPet &body) { QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -273,31 +272,35 @@ 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 pet_idPathParam("{"); - pet_idPathParam.append("petId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; - fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + { + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "DELETE"); - - - if (!::test_namespace::toStringValue(api_key).isEmpty()) { - input.headers.insert("api_key", ::test_namespace::toStringValue(api_key)); + if(!api_key.isNull()) + { + if (!::test_namespace::toStringValue(api_key.value()).isEmpty()) { + input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value())); + } } foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } @@ -333,87 +336,89 @@ void PFXPetApi::findPetsByStatus(const QList &status) { QString queryPrefix, querySuffix, queryDelimiter, queryStyle; - queryStyle = "form"; - if(queryStyle == "") + + { queryStyle = "form"; - queryPrefix = getParamStylePrefix(queryStyle); - querySuffix = getParamStyleSuffix(queryStyle); - queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false); - - if (status.size() > 0) { - if (QString("csv").indexOf("multi") == 0) { - foreach (QString t, status) { + if(queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "status", false); + if (status.size() > 0) { + if (QString("csv").indexOf("multi") == 0) { + foreach (QString t, status) { + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + fullPath.append("status=").append(::test_namespace::toStringValue(t)); + } + } else if (QString("csv").indexOf("ssv") == 0) { if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); + fullPath.append("&"); else - fullPath.append("?"); - fullPath.append("status=").append(::test_namespace::toStringValue(t)); - } - } else if (QString("csv").indexOf("ssv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); - qint32 count = 0; - foreach (QString t, status) { - if (count > 0) { - fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); + qint32 count = 0; + foreach (QString t, status) { + if (count > 0) { + fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("tsv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); - qint32 count = 0; - foreach (QString t, status) { - if (count > 0) { - fullPath.append("\t"); + } else if (QString("csv").indexOf("tsv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); + qint32 count = 0; + foreach (QString t, status) { + if (count > 0) { + fullPath.append("\t"); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("csv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); - qint32 count = 0; - foreach (QString t, status) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("csv").indexOf("csv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); + qint32 count = 0; + foreach (QString t, status) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("pipes") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); - qint32 count = 0; - foreach (QString t, status) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("csv").indexOf("pipes") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); + qint32 count = 0; + foreach (QString t, status) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; + } else if (QString("csv").indexOf("deepObject") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); + qint32 count = 0; + foreach (QString t, status) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; + } } - } else if (QString("csv").indexOf("deepObject") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("status").append(querySuffix); - qint32 count = 0; - foreach (QString t, status) { - if (count > 0) { - fullPath.append(queryDelimiter); - } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } } } @@ -466,87 +471,89 @@ void PFXPetApi::findPetsByTags(const QList &tags) { QString queryPrefix, querySuffix, queryDelimiter, queryStyle; - queryStyle = "form"; - if(queryStyle == "") + + { queryStyle = "form"; - queryPrefix = getParamStylePrefix(queryStyle); - querySuffix = getParamStyleSuffix(queryStyle); - queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false); - - if (tags.size() > 0) { - if (QString("csv").indexOf("multi") == 0) { - foreach (QString t, tags) { + if(queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "tags", false); + if (tags.size() > 0) { + if (QString("csv").indexOf("multi") == 0) { + foreach (QString t, tags) { + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + fullPath.append("tags=").append(::test_namespace::toStringValue(t)); + } + } else if (QString("csv").indexOf("ssv") == 0) { if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); + fullPath.append("&"); else - fullPath.append("?"); - fullPath.append("tags=").append(::test_namespace::toStringValue(t)); - } - } else if (QString("csv").indexOf("ssv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); - qint32 count = 0; - foreach (QString t, tags) { - if (count > 0) { - fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); + qint32 count = 0; + foreach (QString t, tags) { + if (count > 0) { + fullPath.append((false)? queryDelimiter : QUrl::toPercentEncoding(queryDelimiter)); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("tsv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); - qint32 count = 0; - foreach (QString t, tags) { - if (count > 0) { - fullPath.append("\t"); + } else if (QString("csv").indexOf("tsv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); + qint32 count = 0; + foreach (QString t, tags) { + if (count > 0) { + fullPath.append("\t"); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("csv") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); - qint32 count = 0; - foreach (QString t, tags) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("csv").indexOf("csv") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); + qint32 count = 0; + foreach (QString t, tags) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } - } else if (QString("csv").indexOf("pipes") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); - qint32 count = 0; - foreach (QString t, tags) { - if (count > 0) { - fullPath.append(queryDelimiter); + } else if (QString("csv").indexOf("pipes") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); + qint32 count = 0; + foreach (QString t, tags) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; } - fullPath.append(::test_namespace::toStringValue(t)); - count++; + } else if (QString("csv").indexOf("deepObject") == 0) { + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); + qint32 count = 0; + foreach (QString t, tags) { + if (count > 0) { + fullPath.append(queryDelimiter); + } + fullPath.append(::test_namespace::toStringValue(t)); + count++; + } } - } else if (QString("csv").indexOf("deepObject") == 0) { - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?").append(queryPrefix).append("tags").append(querySuffix); - qint32 count = 0; - foreach (QString t, tags) { - if (count > 0) { - fullPath.append(queryDelimiter); - } - fullPath.append(::test_namespace::toStringValue(t)); - count++; - } } } @@ -601,18 +608,21 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { addHeaders("api_key",_apiKeys.find("api_key").value()); } - QString pet_idPathParam("{"); - pet_idPathParam.append("petId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; - fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + { + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -653,7 +663,6 @@ void PFXPetApi::updatePet(const PFXPet &body) { QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -691,28 +700,43 @@ 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 pet_idPathParam("{"); - pet_idPathParam.append("petId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; - fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + { + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); - 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())); + } + + + if(!status.isNull()) + { + input.add_var("status", ::test_namespace::toStringValue(status.value())); + } + + foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); @@ -741,29 +765,43 @@ 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 pet_idPathParam("{"); - pet_idPathParam.append("petId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; - fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + { + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); - 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())); + } + + + if(!file.isNull()) + { + 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)); } connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback); connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 5daa4b47fef..93fcee1b7fa 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -25,6 +25,7 @@ #include #include #include +#include namespace test_namespace { @@ -56,14 +57,51 @@ public: QString getParamStyleSuffix(QString style); QString getParamStyleDelimiter(QString style, QString name, bool isExplode); + /** + * @param[in] body PFXPet [required] + */ 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 [required] + */ void findPetsByStatus(const QList &status); + + /** + * @param[in] tags QList [required] + */ Q_DECL_DEPRECATED void findPetsByTags(const QList &tags); + + /** + * @param[in] pet_id qint64 [required] + */ void getPetById(const qint64 &pet_id); + + /** + * @param[in] body PFXPet [required] + */ 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: QMap _serverIndices; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index 6f8cbecf42f..e8e8c4a94c2 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -222,18 +222,21 @@ QString PFXStoreApi::getParamStyleDelimiter(QString style, QString name, bool is void PFXStoreApi::deleteOrder(const QString &order_id) { QString fullPath = QString(_serverConfigs["deleteOrder"][_serverIndices.value("deleteOrder")].URL()+"/store/order/{orderId}"); - QString order_idPathParam("{"); - order_idPathParam.append("orderId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix; - fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + + { + QString order_idPathParam("{"); + order_idPathParam.append("orderId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix; + fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -277,7 +280,6 @@ void PFXStoreApi::getInventory() { } - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -325,18 +327,21 @@ void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) { void PFXStoreApi::getOrderById(const qint64 &order_id) { QString fullPath = QString(_serverConfigs["getOrderById"][_serverIndices.value("getOrderById")].URL()+"/store/order/{orderId}"); - QString order_idPathParam("{"); - order_idPathParam.append("orderId").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix; - fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + + { + QString order_idPathParam("{"); + order_idPathParam.append("orderId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"orderId"+pathSuffix : pathPrefix; + fullPath.replace(order_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -377,7 +382,6 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { QString fullPath = QString(_serverConfigs["placeOrder"][_serverIndices.value("placeOrder")].URL()+"/store/order"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index f72bdec0efb..8a467731d48 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace test_namespace { @@ -55,11 +56,25 @@ public: QString getParamStyleSuffix(QString style); QString getParamStyleDelimiter(QString style, QString name, bool isExplode); + /** + * @param[in] order_id QString [required] + */ void deleteOrder(const QString &order_id); + + void getInventory(); + + /** + * @param[in] order_id qint64 [required] + */ void getOrderById(const qint64 &order_id); + + /** + * @param[in] body PFXOrder [required] + */ void placeOrder(const PFXOrder &body); + private: QMap _serverIndices; QMap> _serverConfigs; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 2cc891dc413..2379544e521 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -235,7 +235,6 @@ void PFXUserApi::createUser(const PFXUser &body) { QString fullPath = QString(_serverConfigs["createUser"][_serverIndices.value("createUser")].URL()+"/user"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -277,13 +276,11 @@ void PFXUserApi::createUsersWithArrayInput(const QList &body) { QString fullPath = QString(_serverConfigs["createUsersWithArrayInput"][_serverIndices.value("createUsersWithArrayInput")].URL()+"/user/createWithArray"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); - QJsonDocument doc(::test_namespace::toJsonValue(body).toArray()); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -320,13 +317,11 @@ void PFXUserApi::createUsersWithListInput(const QList &body) { QString fullPath = QString(_serverConfigs["createUsersWithListInput"][_serverIndices.value("createUsersWithListInput")].URL()+"/user/createWithList"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); - QJsonDocument doc(::test_namespace::toJsonValue(body).toArray()); QByteArray bytes = doc.toJson(); input.request_body.append(bytes); @@ -362,18 +357,21 @@ void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) void PFXUserApi::deleteUser(const QString &username) { QString fullPath = QString(_serverConfigs["deleteUser"][_serverIndices.value("deleteUser")].URL()+"/user/{username}"); - QString usernamePathParam("{"); - usernamePathParam.append("username").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; - fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + { + QString usernamePathParam("{"); + usernamePathParam.append("username").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; + fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -412,18 +410,21 @@ void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) { void PFXUserApi::getUserByName(const QString &username) { QString fullPath = QString(_serverConfigs["getUserByName"][_serverIndices.value("getUserByName")].URL()+"/user/{username}"); - QString usernamePathParam("{"); - usernamePathParam.append("username").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; - fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + { + QString usernamePathParam("{"); + usernamePathParam.append("username").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; + fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -465,30 +466,37 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { QString queryPrefix, querySuffix, queryDelimiter, queryStyle; - queryStyle = ""; - if(queryStyle == "") - queryStyle = "form"; - queryPrefix = getParamStylePrefix(queryStyle); - querySuffix = getParamStyleSuffix(queryStyle); - queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false); - if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); - else - fullPath.append("?"); + + { + queryStyle = ""; + if(queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "username", false); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); - fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - queryStyle = ""; - if(queryStyle == "") - queryStyle = "form"; - queryPrefix = getParamStylePrefix(queryStyle); - querySuffix = getParamStyleSuffix(queryStyle); - queryDelimiter = getParamStyleDelimiter(queryStyle, "password", false); - if (fullPath.indexOf("?") > 0) - fullPath.append(queryPrefix); - else - fullPath.append("?"); + fullPath.append(QUrl::toPercentEncoding("username")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + } - fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password))); + + { + queryStyle = ""; + if(queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "password", false); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + + fullPath.append(QUrl::toPercentEncoding("password")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -530,7 +538,6 @@ void PFXUserApi::logoutUser() { QString fullPath = QString(_serverConfigs["logoutUser"][_serverIndices.value("logoutUser")].URL()+"/user/logout"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -568,18 +575,21 @@ void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) { void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { QString fullPath = QString(_serverConfigs["updateUser"][_serverIndices.value("updateUser")].URL()+"/user/{username}"); - QString usernamePathParam("{"); - usernamePathParam.append("username").append("}"); - QString pathPrefix, pathSuffix, pathDelimiter; - QString pathStyle = ""; - if(pathStyle == "") - pathStyle = "simple"; - pathPrefix = getParamStylePrefix(pathStyle); - pathSuffix = getParamStyleSuffix(pathStyle); - pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); - QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; - fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + { + QString usernamePathParam("{"); + usernamePathParam.append("username").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "username", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"username"+pathSuffix : pathPrefix; + fullPath.replace(usernamePathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index adba64db9f7..8c075177211 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -24,6 +24,7 @@ #include #include #include +#include namespace test_namespace { @@ -55,15 +56,47 @@ public: QString getParamStyleSuffix(QString style); QString getParamStyleDelimiter(QString style, QString name, bool isExplode); + /** + * @param[in] body PFXUser [required] + */ void createUser(const PFXUser &body); + + /** + * @param[in] body QList [required] + */ void createUsersWithArrayInput(const QList &body); + + /** + * @param[in] body QList [required] + */ void createUsersWithListInput(const QList &body); + + /** + * @param[in] username QString [required] + */ void deleteUser(const QString &username); + + /** + * @param[in] username QString [required] + */ void getUserByName(const QString &username); + + /** + * @param[in] username QString [required] + * @param[in] password QString [required] + */ void loginUser(const QString &username, const QString &password); + + void logoutUser(); + + /** + * @param[in] username QString [required] + * @param[in] body PFXUser [required] + */ void updateUser(const QString &username, const PFXUser &body); + private: QMap _serverIndices; QMap> _serverConfigs;