From 91c6f3a1856d85b056923bb66d5d670202c66fdd Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Fri, 20 Nov 2020 18:41:19 +0100 Subject: [PATCH 1/6] first commit of api Key feature. --- .../languages/CppQt5ClientCodegen.java | 2 ++ .../resources/cpp-qt5-client/README.mustache | 25 +++++++++++++++++++ .../cpp-qt5-client/api-body.mustache | 12 ++++++++- .../cpp-qt5-client/api-header.mustache | 4 ++- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java index a199ab9f70f..79a63c00845 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppQt5ClientCodegen.java @@ -80,6 +80,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, PREFIX + "HttpFileElement.cpp")); supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h")); supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h")); + supportingFiles.add(new SupportingFile("README.mustache", "","README.md")); supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt")); if (optionalProjectFileFlag) { supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri")); @@ -108,6 +109,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege supportingFiles.add(new SupportingFile("HttpFileElement.cpp.mustache", sourceFolder, modelNamePrefix + "HttpFileElement.cpp")); supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h")); supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h")); + supportingFiles.add(new SupportingFile("README.mustache", "","README.md")); supportingFiles.add(new SupportingFile("CMakeLists.txt.mustache", sourceFolder, "CMakeLists.txt")); diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache new file mode 100644 index 00000000000..b210df428b4 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache @@ -0,0 +1,25 @@ +{{^authMethods}} +All endpoints do not require authorization. +{{/authMethods}} +{{#authMethods}} +{{#last}} +Authentication schemes defined for the API: +{{/last}} +{{/authMethods}} +{{#authMethods}} +<a name="{{name}}"></a> +### {{name}} +{{#isApiKey}}- **Type**: API key +- **API key parameter name**: {{keyParamName}} +- **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} +{{/isApiKey}} +{{#isBasic}}- **Type**: HTTP basic authentication +{{/isBasic}} +{{#isOAuth}}- **Type**: OAuth +- **Flow**: {{flow}} +- **Authorization URL**: {{authorizationUrl}} +- **Scopes**: {{^scopes}}N/A{{/scopes}} +{{#scopes}} - {{scope}}: {{description}} +{{/scopes}} +{{/isOAuth}} +{{/authMethods}} 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 2d90ddfb681..2703e344be3 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 @@ -9,10 +9,11 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} -{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) +{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut, const QString &apiKey) : _scheme(scheme), _host(host), _port(port), + _apiKey(apiKey), _basePath(basePath), _timeOut(timeOut), _manager(nullptr), @@ -34,6 +35,10 @@ void {{classname}}::setPort(int port) { _port = port; } +void {{classname}}::setApiKey(const QString &apiKey){ + _apiKey = apiKey; +} + void {{classname}}::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -80,6 +85,11 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName {{paramName}}PathParam.append("{{baseName}}").append("}"); fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); {{/pathParams}} + +{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} + addHeaders("{{name}}",_apiKey); +{{/isKeyInHeader}}{{/isApiKey}}{{/authMethods}} + {{#queryParams}}{{^collectionFormat}} if (fullPath.indexOf("?") > 0) fullPath.append("&"); 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 4052153e77a..f09a08322cd 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 @@ -18,12 +18,13 @@ class {{classname}} : public QObject { Q_OBJECT public: - {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString &basePath = "{{basePathWithoutHost}}", const int timeOut = 0); + {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString &basePath = "{{basePathWithoutHost}}", const int timeOut = 0, const QString &apiKey=""); ~{{classname}}(); void setScheme(const QString &scheme); void setHost(const QString &host); void setPort(int port); + void setApiKey(const QString &apiKey); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -38,6 +39,7 @@ public: private: QString _scheme, _host; int _port; + QString _apiKey; QString _basePath; int _timeOut; QString _workingDirectory; -- GitLab From 8f7325c3cccc936d55f1d648238bd452f2cdb495 Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Mon, 23 Nov 2020 13:05:10 +0100 Subject: [PATCH 2/6] added multi key and URL query key support --- .../cpp-qt5-client/api-body.mustache | 19 ++++++++++++------- .../cpp-qt5-client/api-header.mustache | 9 +++++---- 2 files changed, 17 insertions(+), 11 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 2703e344be3..5987b368084 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 @@ -9,11 +9,10 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} -{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut, const QString &apiKey) +{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut) : _scheme(scheme), _host(host), _port(port), - _apiKey(apiKey), _basePath(basePath), _timeOut(timeOut), _manager(nullptr), @@ -35,8 +34,8 @@ void {{classname}}::setPort(int port) { _port = port; } -void {{classname}}::setApiKey(const QString &apiKey){ - _apiKey = apiKey; +void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey){ + _apiKeys.insert(apiKeyName,apiKey); } void {{classname}}::setBasePath(const QString &basePath) { @@ -73,7 +72,7 @@ void {{classname}}::abortRequests(){ {{#operations}} {{#operation}} -void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) { +void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { QString fullPath = QString("%1://%2%3%4%5") .arg(_scheme) .arg(_host) @@ -87,8 +86,14 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName {{/pathParams}} {{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} - addHeaders("{{name}}",_apiKey); -{{/isKeyInHeader}}{{/isApiKey}}{{/authMethods}} + addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); +{{/isKeyInHeader}}{{#isKeyInQuery}} + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); +{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}} {{#queryParams}}{{^collectionFormat}} if (fullPath.indexOf("?") > 0) 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 f09a08322cd..27c9debef3d 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 @@ -8,6 +8,7 @@ {{/imports}} #include <QObject> + #include <QStringList> #include <QNetworkAccessManager> {{#cppNamespaceDeclarations}} @@ -18,13 +19,13 @@ class {{classname}} : public QObject { Q_OBJECT public: - {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString &basePath = "{{basePathWithoutHost}}", const int timeOut = 0, const QString &apiKey=""); + {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString &basePath = "{{basePathWithoutHost}}", const int timeOut = 0); ~{{classname}}(); void setScheme(const QString &scheme); void setHost(const QString &host); void setPort(int port); - void setApiKey(const QString &apiKey); + void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -34,12 +35,12 @@ public: void enableResponseCompression(); void abortRequests(); {{#operations}}{{#operation}} - void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{/operation}}{{/operations}} + void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/operation}}{{/operations}} private: QString _scheme, _host; int _port; - QString _apiKey; + QMap<QString, QString> _apiKeys; QString _basePath; int _timeOut; QString _workingDirectory; -- GitLab From 27dec370ea2c09ea1138340dd0092be0bba434c1 Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Mon, 23 Nov 2020 14:06:12 +0100 Subject: [PATCH 3/6] fixed error in mustache files, updated samples and tests --- .../cpp-qt5-client/api-body.mustache | 2 +- .../cpp-qt5-client/api-header.mustache | 2 +- .../petstore/cpp-qt5/PetStore/PetApiTests.cpp | 1 + .../cpp-qt5/PetStore/StoreApiTests.cpp | 1 + .../petstore/cpp-qt5/client/PFXPetApi.cpp | 30 +++++++++++++++++++ .../petstore/cpp-qt5/client/PFXPetApi.h | 3 ++ .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 18 +++++++++++ .../petstore/cpp-qt5/client/PFXStoreApi.h | 3 ++ .../petstore/cpp-qt5/client/PFXUserApi.cpp | 28 +++++++++++++++++ .../petstore/cpp-qt5/client/PFXUserApi.h | 3 ++ 10 files changed, 89 insertions(+), 2 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 5987b368084..ef63154312d 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 @@ -72,7 +72,7 @@ void {{classname}}::abortRequests(){ {{#operations}} {{#operation}} -void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { +void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}) { QString fullPath = QString("%1://%2%3%4%5") .arg(_scheme) .arg(_host) 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 27c9debef3d..efe3fc3e8eb 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 @@ -35,7 +35,7 @@ public: void enableResponseCompression(); void abortRequests(); {{#operations}}{{#operation}} - void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}});{{/operation}}{{/operations}} + void {{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}});{{/operation}}{{/operations}} private: QString _scheme, _host; diff --git a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp index 1a657a6ceec..41c6ca49056 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp @@ -37,6 +37,7 @@ void PetApiTests::findPetsByStatusTest() { void PetApiTests::createAndGetPetTest() { PFXPetApi api; + api.setApiKey("api_key","special-key"); QEventLoop loop; bool petCreated = false; diff --git a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp index 0c0c926d1eb..5b97968e12e 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp @@ -59,6 +59,7 @@ void StoreApiTests::getOrderByIdTest() { void StoreApiTests::getInventoryTest() { PFXStoreApi api; + api.setApiKey("api_key","special-key"); QEventLoop loop; bool inventoryFetched = false; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index c94bcc0da8a..cff44360208 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -42,6 +42,10 @@ void PFXPetApi::setPort(int port) { _port = port; } +void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ + _apiKeys.insert(apiKeyName,apiKey); +} + void PFXPetApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -82,6 +86,9 @@ void PFXPetApi::addPet(const PFXPet &body) { .arg(_basePath) .arg("/pet"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -130,6 +137,9 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -176,6 +186,9 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) { .arg(_basePath) .arg("/pet/findByStatus"); + + + if (status.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, status) { @@ -266,6 +279,9 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) { .arg(_basePath) .arg("/pet/findByTags"); + + + if (tags.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, tags) { @@ -359,6 +375,11 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + addHeaders("api_key",_apiKeys.find("api_key").value()); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -402,6 +423,9 @@ void PFXPetApi::updatePet(const PFXPet &body) { .arg(_basePath) .arg("/pet"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -450,6 +474,9 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, con pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -497,6 +524,9 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metad pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index aa85e82e34e..31c676a95a8 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -20,6 +20,7 @@ #include <QString> #include <QObject> + #include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -34,6 +35,7 @@ public: void setScheme(const QString &scheme); void setHost(const QString &host); void setPort(int port); + void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -55,6 +57,7 @@ public: private: QString _scheme, _host; int _port; + QMap<QString, QString> _apiKeys; QString _basePath; int _timeOut; QString _workingDirectory; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index d56512f6112..fc6e7124ced 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -42,6 +42,10 @@ void PFXStoreApi::setPort(int port) { _port = port; } +void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ + _apiKeys.insert(apiKeyName,apiKey); +} + void PFXStoreApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -85,6 +89,9 @@ void PFXStoreApi::deleteOrder(const QString &order_id) { order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -127,6 +134,11 @@ void PFXStoreApi::getInventory() { .arg(_basePath) .arg("/store/inventory"); + + addHeaders("api_key",_apiKeys.find("api_key").value()); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -182,6 +194,9 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) { order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -225,6 +240,9 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { .arg(_basePath) .arg("/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 238338cd9c2..41ad9b856b0 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -19,6 +19,7 @@ #include <QString> #include <QObject> + #include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -33,6 +34,7 @@ public: void setScheme(const QString &scheme); void setHost(const QString &host); void setPort(int port); + void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -50,6 +52,7 @@ public: private: QString _scheme, _host; int _port; + QMap<QString, QString> _apiKeys; QString _basePath; int _timeOut; QString _workingDirectory; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 74060393b01..a23bd3987b4 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -42,6 +42,10 @@ void PFXUserApi::setPort(int port) { _port = port; } +void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ + _apiKeys.insert(apiKeyName,apiKey); +} + void PFXUserApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -82,6 +86,9 @@ void PFXUserApi::createUser(const PFXUser &body) { .arg(_basePath) .arg("/user"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -127,6 +134,9 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) { .arg(_basePath) .arg("/user/createWithArray"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -173,6 +183,9 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) { .arg(_basePath) .arg("/user/createWithList"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -222,6 +235,9 @@ void PFXUserApi::deleteUser(const QString &username) { usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -267,6 +283,9 @@ void PFXUserApi::getUserByName(const QString &username) { usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -310,6 +329,9 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { .arg(_basePath) .arg("/user/login"); + + + if (fullPath.indexOf("?") > 0) fullPath.append("&"); else @@ -366,6 +388,9 @@ void PFXUserApi::logoutUser() { .arg(_basePath) .arg("/user/logout"); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -411,6 +436,9 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); + + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index e2698e5d1a2..79ef7b1e1e1 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -19,6 +19,7 @@ #include <QString> #include <QObject> + #include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -33,6 +34,7 @@ public: void setScheme(const QString &scheme); void setHost(const QString &host); void setPort(int port); + void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -54,6 +56,7 @@ public: private: QString _scheme, _host; int _port; + QMap<QString, QString> _apiKeys; QString _basePath; int _timeOut; QString _workingDirectory; -- GitLab From 5a60115643ced34b504306afd1eda111c54c8440 Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Mon, 23 Nov 2020 15:57:13 +0100 Subject: [PATCH 4/6] added Basic Auth with Base64 encoding. --- .../cpp-qt5-client/api-body.mustache | 20 +++++++---- .../cpp-qt5-client/api-header.mustache | 7 +++- .../petstore/cpp-qt5/client/PFXPetApi.cpp | 33 +++++++++---------- .../petstore/cpp-qt5/client/PFXPetApi.h | 7 +++- .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 21 +++++++----- .../petstore/cpp-qt5/client/PFXStoreApi.h | 7 +++- .../petstore/cpp-qt5/client/PFXUserApi.cpp | 32 +++++++++--------- .../petstore/cpp-qt5/client/PFXUserApi.h | 7 +++- 8 files changed, 82 insertions(+), 52 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 ef63154312d..d741f3cd557 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 @@ -38,6 +38,14 @@ void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void {{classname}}::setUsername(const QString &username) { + _username = username; +} + +void {{classname}}::setPassword(const QString &password) { + _password = password; +} + void {{classname}}::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -83,17 +91,17 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{baseName}}").append("}"); fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); -{{/pathParams}} - -{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} - addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); -{{/isKeyInHeader}}{{#isKeyInQuery}} + {{/pathParams}} + {{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); + {{/isKeyInHeader}}{{#isKeyInQuery}} if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?"); fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); -{{/isKeyInQuery}}{{/isApiKey}}{{/authMethods}} + {{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}QByteArray b64; + b64.append(_username + ":" + _password); + addHeaders("Authorization","Basic " + b64.toBase64());{{/isBasic}}{{/authMethods}} {{#queryParams}}{{^collectionFormat}} if (fullPath.indexOf("?") > 0) 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 efe3fc3e8eb..258497b2d9a 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 @@ -8,7 +8,8 @@ {{/imports}} #include <QObject> - #include <QStringList> +#include <QByteArray> +#include <QStringList> #include <QNetworkAccessManager> {{#cppNamespaceDeclarations}} @@ -26,6 +27,8 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setUsername(const QString &username); + void setPassword(const QString &password); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -41,6 +44,8 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index cff44360208..4e0254d251f 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -46,6 +46,14 @@ void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXPetApi::setUsername(const QString &username) { + _username = username; +} + +void PFXPetApi::setPassword(const QString &password) { + _password = password; +} + void PFXPetApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -85,8 +93,7 @@ void PFXPetApi::addPet(const PFXPet &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -136,8 +143,7 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -185,8 +191,7 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet/findByStatus"); - - + if (status.size() > 0) { @@ -278,8 +283,7 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet/findByTags"); - - + if (tags.size() > 0) { @@ -374,10 +378,8 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - - addHeaders("api_key",_apiKeys.find("api_key").value()); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -422,8 +424,7 @@ void PFXPetApi::updatePet(const PFXPet &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -473,8 +474,7 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, con QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -523,8 +523,7 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metad QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 31c676a95a8..5a44a2f3419 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -20,7 +20,8 @@ #include <QString> #include <QObject> - #include <QStringList> +#include <QByteArray> +#include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -36,6 +37,8 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setUsername(const QString &username); + void setPassword(const QString &password); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -58,6 +61,8 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index fc6e7124ced..ba6f8c84908 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -46,6 +46,14 @@ void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXStoreApi::setUsername(const QString &username) { + _username = username; +} + +void PFXStoreApi::setPassword(const QString &password) { + _password = password; +} + void PFXStoreApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -88,8 +96,7 @@ void PFXStoreApi::deleteOrder(const QString &order_id) { QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -133,10 +140,8 @@ void PFXStoreApi::getInventory() { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/store/inventory"); - - addHeaders("api_key",_apiKeys.find("api_key").value()); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -193,8 +198,7 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) { QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -239,8 +243,7 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/store/order"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index 41ad9b856b0..fd8c19166ab 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -19,7 +19,8 @@ #include <QString> #include <QObject> - #include <QStringList> +#include <QByteArray> +#include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -35,6 +36,8 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setUsername(const QString &username); + void setPassword(const QString &password); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -53,6 +56,8 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index a23bd3987b4..4693e6f6b0a 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -46,6 +46,14 @@ void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXUserApi::setUsername(const QString &username) { + _username = username; +} + +void PFXUserApi::setPassword(const QString &password) { + _password = password; +} + void PFXUserApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -85,8 +93,7 @@ void PFXUserApi::createUser(const PFXUser &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -133,8 +140,7 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/createWithArray"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -182,8 +188,7 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/createWithList"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -234,8 +239,7 @@ void PFXUserApi::deleteUser(const QString &username) { QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -282,8 +286,7 @@ void PFXUserApi::getUserByName(const QString &username) { QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -328,8 +331,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/login"); - - + if (fullPath.indexOf("?") > 0) @@ -387,8 +389,7 @@ void PFXUserApi::logoutUser() { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/logout"); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -435,8 +436,7 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index 79ef7b1e1e1..06267ff6057 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -19,7 +19,8 @@ #include <QString> #include <QObject> - #include <QStringList> +#include <QByteArray> +#include <QStringList> #include <QNetworkAccessManager> namespace test_namespace { @@ -35,6 +36,8 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setUsername(const QString &username); + void setPassword(const QString &password); void setBasePath(const QString &basePath); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -57,6 +60,8 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory; -- GitLab From 65189060acc3894886f60362923776430278cbd0 Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Tue, 24 Nov 2020 13:24:53 +0100 Subject: [PATCH 5/6] updated Readme, added bearer token --- .../resources/cpp-qt5-client/README.mustache | 183 ++++++++++++++++-- .../cpp-qt5-client/api-body.mustache | 15 +- .../cpp-qt5-client/api-header.mustache | 2 + samples/client/petstore/cpp-qt5/README.md | 174 +++++++++++++++++ .../petstore/cpp-qt5/client/PFXPetApi.cpp | 13 +- .../petstore/cpp-qt5/client/PFXPetApi.h | 2 + .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 7 +- .../petstore/cpp-qt5/client/PFXStoreApi.h | 2 + .../petstore/cpp-qt5/client/PFXUserApi.cpp | 14 +- .../petstore/cpp-qt5/client/PFXUserApi.h | 2 + 10 files changed, 386 insertions(+), 28 deletions(-) create mode 100644 samples/client/petstore/cpp-qt5/README.md diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache index b210df428b4..a7fdb18eb03 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache @@ -1,25 +1,180 @@ -{{^authMethods}} -All endpoints do not require authorization. -{{/authMethods}} -{{#authMethods}} -{{#last}} -Authentication schemes defined for the API: -{{/last}} -{{/authMethods}} -{{#authMethods}} -<a name="{{name}}"></a> -### {{name}} -{{#isApiKey}}- **Type**: API key +# {{artifactId}} + +{{appName}} + +- API version: {{appVersion}} +{{^hideGenerationTimestamp}} + +- Build date: {{generatedDate}} +{{/hideGenerationTimestamp}} + +{{#appDescriptionWithNewLines}}{{{appDescriptionWithNewLines}}}{{/appDescriptionWithNewLines}} + +{{#infoUrl}} + For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) +{{/infoUrl}} + +*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* + +## Licence + +{{licenseInfo}} + +for more information visit [{{licenseInfo}}]({{licenseUrl}}) + +## Requirements + +Building the API client library requires: + +1. Java {{#supportJava6}}1.6{{/supportJava6}}{{^supportJava6}}{{#java8}}1.8{{/java8}}{{^java8}}1.7{{/java8}}{{/supportJava6}}+ +2. Maven/Gradle + +## Installation + +To install the API client library to your local Maven repository, simply execute: + +```shell +mvn clean install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn clean deploy +``` + +Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information. + +### Generate manually + +At first generate the JAR by executing: + +```shell +mvn clean package +``` + +Use the Jar file to generate the Qt5 Client: + +```shell +java -jar target/openapi-generator-cli.jar generate -i <yourOpenApiFile> -g cpp-qt5-client -o <outputDir> +``` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +example.h: + +```c++ +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} +#include <iostream> +#include "../client/{{{classname}}}.h" + +using namespace test_namespace; + +class Example : public QObject { + Q_OBJECT + {{#allParams}} + {{{dataType}}} create(); + {{/allParams}} +public slots: + void exampleFunction1(); +}; +{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} +``` +example.cpp: + +```c++ +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} +#include "../client/{{{classname}}}.h" +#include "example.h" +#include <QTimer> +#include <QEventLoop> + +{{#allParams}} +{{dataType}} Example::create(){ + {{{dataType}}} obj; +{{/allParams}} + return obj; +} + +void Example::exampleFunction1(){ + {{{classname}}} apiInstance; + {{#hasAuthMethods}}{{#authMethods}}{{#isBasic}}{{#isBasicBasic}} + // Configure HTTP basic authorization: {{{name}}} + apiInstance.setUsername("YOUR USERNAME"); + apiInstance.setPassword("YOUR PASSWORD");{{/isBasicBasic}}{{#isBasicBearer}} + // Configure HTTP bearer authorization: {{{name}}} + apiInstance.setBearerToken("BEARER TOKEN");{{/isBasicBearer}}{{/isBasic}}{{#isApiKey}} + // Configure API key authorization: {{{name}}} + apiInstance.setApiKey("YOUR API KEY NAME","YOUR API KEY");{{/isApiKey}}{{#isOAuth}} + //OAuth Authentication supported right now{{/isOAuth}}{{#isHttpSignature}} + //No Http Signature Authentication supported right now{{/isHttpSignature}} + {{/authMethods}} + {{/hasAuthMethods}} + {{#allParams}} + + QEventLoop loop; + connect(&apiInstance, &{{{classname}}}::{{nickname}}Signal, [&]() { + loop.quit(); + }); + connect(&apiInstance, &{{{classname}}}::{{nickname}}SignalE, [&](QNetworkReply::NetworkError, QString error_str) { + qDebug() << "Error happened while issuing request : " << error_str; + loop.quit(); + }); + + {{{dataType}}} {{{paramName}}} = create(); // {{{dataType}}} | {{{description}}} + {{/allParams}} + apiInstance.{{{operationId}}}({{#allParams}}{{{paramName}}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); + QTimer::singleShot(5000, &loop, &QEventLoop::quit); + loop.exec(); + } +{{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} +``` + +## Documentation for API Endpoints + +All URIs are relative to *{{basePath}}* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +{{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationId}}) | **{{httpMethod}}** {{commonPath}}{{path}} | {{#summary}}{{summary}}{{/summary}} +{{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} + +## Documentation for Models + +{{#models}}{{#model}} - [{{classname}}]({{modelDocPath}}{{classname}}.md) +{{/model}}{{/models}} + +## Documentation for Authorization + +{{^authMethods}}All endpoints do not require authorization. +{{/authMethods}}Authentication schemes defined for the API: +{{#authMethods}}### {{name}} + +{{#isApiKey}} + +- **Type**: API key - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}}- **Type**: HTTP basic authentication +{{#isBasic}} + +- **Type**: HTTP basic authentication {{/isBasic}} -{{#isOAuth}}- **Type**: OAuth +{{#isOAuth}} + +- **Type**: OAuth - **Flow**: {{flow}} - **Authorization URL**: {{authorizationUrl}} - **Scopes**: {{^scopes}}N/A{{/scopes}} {{#scopes}} - {{scope}}: {{description}} {{/scopes}} {{/isOAuth}} + {{/authMethods}} + +## Author + +{{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}} +{{/-last}}{{/apis}}{{/apiInfo}} 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 d741f3cd557..2262ef4c7a2 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 @@ -38,6 +38,10 @@ void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void {{classname}}::setBearerToken(const QString &token){ + _bearerToken = token; +} + void {{classname}}::setUsername(const QString &username) { _username = username; } @@ -91,17 +95,20 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{baseName}}").append("}"); fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); - {{/pathParams}} - {{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}}addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); + {{/pathParams}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} + addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); {{/isKeyInHeader}}{{#isKeyInQuery}} if (fullPath.indexOf("?") > 0) fullPath.append("&"); else fullPath.append("?"); fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); - {{/isKeyInQuery}}{{/isApiKey}}{{#isBasic}}QByteArray b64; + {{/isKeyInQuery}}{{/isApiKey}}{{#isBasicBearer}} + addHeaders("Authorization", "Bearer " + _bearerToken); + {{/isBasicBearer}}{{#isBasicBasic}} + QByteArray b64; b64.append(_username + ":" + _password); - addHeaders("Authorization","Basic " + b64.toBase64());{{/isBasic}}{{/authMethods}} + addHeaders("Authorization","Basic " + b64.toBase64());{{/isBasicBasic}}{{/authMethods}} {{#queryParams}}{{^collectionFormat}} if (fullPath.indexOf("?") > 0) 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 258497b2d9a..4f241ec3ff3 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 @@ -27,6 +27,7 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setBasePath(const QString &basePath); @@ -44,6 +45,7 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _bearerToken; QString _username; QString _password; QString _basePath; diff --git a/samples/client/petstore/cpp-qt5/README.md b/samples/client/petstore/cpp-qt5/README.md new file mode 100644 index 00000000000..4ae23681d5d --- /dev/null +++ b/samples/client/petstore/cpp-qt5/README.md @@ -0,0 +1,174 @@ +# + +OpenAPI Petstore + +- API version: 1.0.0 + +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + + +*Automatically generated by the [OpenAPI Generator](https://openapi-generator.tech)* + +## Licence + +Apache-2.0 + +for more information visit [Apache-2.0](https://www.apache.org/licenses/LICENSE-2.0.html) + +## Requirements + +Building the API client library requires: + +1. Java 1.7+ +2. Maven/Gradle + +## Installation + +To install the API client library to your local Maven repository, simply execute: + +```shell +mvn clean install +``` + +To deploy it to a remote Maven repository instead, configure the settings of the repository and execute: + +```shell +mvn clean deploy +``` + +Refer to the [OSSRH Guide](http://central.sonatype.org/pages/ossrh-guide.html) for more information. + +### Generate manually + +At first generate the JAR by executing: + +```shell +mvn clean package +``` + +Use the Jar file to generate the Qt5 Client: + +```shell +java -jar target/openapi-generator-cli.jar generate -i <yourOpenApiFile> -g cpp-qt5-client -o <outputDir> +``` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +example.h: + +```c++ + +#include <iostream> +#include "../client/PFXPetApi.h" + +using namespace test_namespace; + +class Example : public QObject { + Q_OBJECT + PFXPet create(); +public slots: + void exampleFunction1(); +}; + +``` +example.cpp: + +```c++ + +#include "../client/PFXPetApi.h" +#include "example.h" +#include <QTimer> +#include <QEventLoop> + +PFXPet Example::create(){ + PFXPet obj; + return obj; +} + +void Example::exampleFunction1(){ + PFXPetApi apiInstance; + + //OAuth Authentication supported right now + + QEventLoop loop; + connect(&apiInstance, &PFXPetApi::addPetSignal, [&]() { + loop.quit(); + }); + connect(&apiInstance, &PFXPetApi::addPetSignalE, [&](QNetworkReply::NetworkError, QString error_str) { + qDebug() << "Error happened while issuing request : " << error_str; + loop.quit(); + }); + + PFXPet body = create(); // PFXPet | Pet object that needs to be added to the store + apiInstance.addPet(body); + QTimer::singleShot(5000, &loop, &QEventLoop::quit); + loop.exec(); + } + +``` + +## Documentation for API Endpoints + +All URIs are relative to *http://petstore.swagger.io/v2* + +Class | Method | HTTP request | Description +------------ | ------------- | ------------- | ------------- +*PFXPetApi* | [**addPet**](PFXPetApi.md#addPet) | **POST** /pet | Add a new pet to the store +*PFXPetApi* | [**deletePet**](PFXPetApi.md#deletePet) | **DELETE** /pet/{petId} | Deletes a pet +*PFXPetApi* | [**findPetsByStatus**](PFXPetApi.md#findPetsByStatus) | **GET** /pet/findByStatus | Finds Pets by status +*PFXPetApi* | [**findPetsByTags**](PFXPetApi.md#findPetsByTags) | **GET** /pet/findByTags | Finds Pets by tags +*PFXPetApi* | [**getPetById**](PFXPetApi.md#getPetById) | **GET** /pet/{petId} | Find pet by ID +*PFXPetApi* | [**updatePet**](PFXPetApi.md#updatePet) | **PUT** /pet | Update an existing pet +*PFXPetApi* | [**updatePetWithForm**](PFXPetApi.md#updatePetWithForm) | **POST** /pet/{petId} | Updates a pet in the store with form data +*PFXPetApi* | [**uploadFile**](PFXPetApi.md#uploadFile) | **POST** /pet/{petId}/uploadImage | uploads an image +*PFXStoreApi* | [**deleteOrder**](PFXStoreApi.md#deleteOrder) | **DELETE** /store/order/{orderId} | Delete purchase order by ID +*PFXStoreApi* | [**getInventory**](PFXStoreApi.md#getInventory) | **GET** /store/inventory | Returns pet inventories by status +*PFXStoreApi* | [**getOrderById**](PFXStoreApi.md#getOrderById) | **GET** /store/order/{orderId} | Find purchase order by ID +*PFXStoreApi* | [**placeOrder**](PFXStoreApi.md#placeOrder) | **POST** /store/order | Place an order for a pet +*PFXUserApi* | [**createUser**](PFXUserApi.md#createUser) | **POST** /user | Create user +*PFXUserApi* | [**createUsersWithArrayInput**](PFXUserApi.md#createUsersWithArrayInput) | **POST** /user/createWithArray | Creates list of users with given input array +*PFXUserApi* | [**createUsersWithListInput**](PFXUserApi.md#createUsersWithListInput) | **POST** /user/createWithList | Creates list of users with given input array +*PFXUserApi* | [**deleteUser**](PFXUserApi.md#deleteUser) | **DELETE** /user/{username} | Delete user +*PFXUserApi* | [**getUserByName**](PFXUserApi.md#getUserByName) | **GET** /user/{username} | Get user by user name +*PFXUserApi* | [**loginUser**](PFXUserApi.md#loginUser) | **GET** /user/login | Logs user into the system +*PFXUserApi* | [**logoutUser**](PFXUserApi.md#logoutUser) | **GET** /user/logout | Logs out current logged in user session +*PFXUserApi* | [**updateUser**](PFXUserApi.md#updateUser) | **PUT** /user/{username} | Updated user + + +## Documentation for Models + + - [PFXApiResponse](PFXApiResponse.md) + - [PFXCategory](PFXCategory.md) + - [PFXOrder](PFXOrder.md) + - [PFXPet](PFXPet.md) + - [PFXTag](PFXTag.md) + - [PFXUser](PFXUser.md) + + +## Documentation for Authorization + +Authentication schemes defined for the API: +### api_key + + +- **Type**: API key +- **API key parameter name**: api_key +- **Location**: HTTP header + +### petstore_auth + + +- **Type**: OAuth +- **Flow**: implicit +- **Authorization URL**: http://petstore.swagger.io/api/oauth/dialog +- **Scopes**: + - write:pets: modify pets in your account + - read:pets: read your pets + + +## Author + + + diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index 4e0254d251f..eb917a7ef60 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -46,6 +46,10 @@ void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXPetApi::setBearerToken(const QString &token){ + _bearerToken = token; +} + void PFXPetApi::setUsername(const QString &username) { _username = username; } @@ -93,7 +97,7 @@ void PFXPetApi::addPet(const PFXPet &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -191,7 +195,7 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet/findByStatus"); - + if (status.size() > 0) { @@ -283,7 +287,7 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet/findByTags"); - + if (tags.size() > 0) { @@ -378,6 +382,7 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); + addHeaders("api_key",_apiKeys.find("api_key").value()); @@ -424,7 +429,7 @@ void PFXPetApi::updatePet(const PFXPet &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/pet"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 5a44a2f3419..71f0e48cb37 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -37,6 +37,7 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setBasePath(const QString &basePath); @@ -61,6 +62,7 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _bearerToken; QString _username; QString _password; QString _basePath; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index ba6f8c84908..e1d8d69cce6 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -46,6 +46,10 @@ void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXStoreApi::setBearerToken(const QString &token){ + _bearerToken = token; +} + void PFXStoreApi::setUsername(const QString &username) { _username = username; } @@ -140,6 +144,7 @@ void PFXStoreApi::getInventory() { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/store/inventory"); + addHeaders("api_key",_apiKeys.find("api_key").value()); @@ -243,7 +248,7 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/store/order"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index fd8c19166ab..626a0236ee4 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -36,6 +36,7 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setBasePath(const QString &basePath); @@ -56,6 +57,7 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _bearerToken; QString _username; QString _password; QString _basePath; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 4693e6f6b0a..c1130069c53 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -46,6 +46,10 @@ void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey){ _apiKeys.insert(apiKeyName,apiKey); } +void PFXUserApi::setBearerToken(const QString &token){ + _bearerToken = token; +} + void PFXUserApi::setUsername(const QString &username) { _username = username; } @@ -93,7 +97,7 @@ void PFXUserApi::createUser(const PFXUser &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -140,7 +144,7 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/createWithArray"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -188,7 +192,7 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/createWithList"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); @@ -331,7 +335,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/login"); - + if (fullPath.indexOf("?") > 0) @@ -389,7 +393,7 @@ void PFXUserApi::logoutUser() { .arg(_port ? ":" + QString::number(_port) : "") .arg(_basePath) .arg("/user/logout"); - + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index 06267ff6057..d6bb21b5a8d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -36,6 +36,7 @@ public: void setHost(const QString &host); void setPort(int port); void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setBasePath(const QString &basePath); @@ -60,6 +61,7 @@ private: QString _scheme, _host; int _port; QMap<QString, QString> _apiKeys; + QString _bearerToken; QString _username; QString _password; QString _basePath; -- GitLab From b39eaa6884a47713e1545b8df3a85695bf25c25c Mon Sep 17 00:00:00 2001 From: Marius Dege <marius.dege@basyskom.com> Date: Fri, 27 Nov 2020 13:37:06 +0100 Subject: [PATCH 6/6] added check that authentication credentials are set. fixed typo in README --- .../resources/cpp-qt5-client/README.mustache | 7 +++-- .../cpp-qt5-client/api-body.mustache | 28 +++++++++++-------- .../cpp-qt5/PetStore/StoreApiTests.cpp | 3 ++ .../petstore/cpp-qt5/client/PFXPetApi.cpp | 12 ++------ .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 8 ++---- .../petstore/cpp-qt5/client/PFXUserApi.cpp | 8 ------ 6 files changed, 31 insertions(+), 35 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache index a7fdb18eb03..2cd99b3520e 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache @@ -158,10 +158,13 @@ Class | Method | HTTP request | Description - **API key parameter name**: {{keyParamName}} - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} {{/isApiKey}} -{{#isBasic}} +{{#isBasicBasic}} - **Type**: HTTP basic authentication -{{/isBasic}} +{{/isBasicBasic}} +{{#isBasicBearer}} +- **Type**: HTTP Bearer Token authentication +{{/isBasicBearer}} {{#isOAuth}} - **Type**: OAuth 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 2262ef4c7a2..5e37fc0ba11 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 @@ -96,20 +96,26 @@ void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}} &{{paramName {{paramName}}PathParam.append("{{baseName}}").append("}"); fullPath.replace({{paramName}}PathParam, QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}))); {{/pathParams}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} - addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); + if(_apiKeys.contains("{{name}}")){ + addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); + } {{/isKeyInHeader}}{{#isKeyInQuery}} - if (fullPath.indexOf("?") > 0) - fullPath.append("&"); - else - fullPath.append("?"); - fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); + if(_apiKeys.contains("{{name}}")){ + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); + } {{/isKeyInQuery}}{{/isApiKey}}{{#isBasicBearer}} - addHeaders("Authorization", "Bearer " + _bearerToken); + if(!_bearerToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _bearerToken); {{/isBasicBearer}}{{#isBasicBasic}} - QByteArray b64; - b64.append(_username + ":" + _password); - addHeaders("Authorization","Basic " + b64.toBase64());{{/isBasicBasic}}{{/authMethods}} - + if(!_username.isEmpty() && !_password.isEmpty()){ + QByteArray b64; + b64.append(_username + ":" + _password); + addHeaders("Authorization","Basic " + b64.toBase64()); + }{{/isBasicBasic}}{{/authMethods}} {{#queryParams}}{{^collectionFormat}} if (fullPath.indexOf("?") > 0) fullPath.append("&"); diff --git a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp index 5b97968e12e..ba3487d6879 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp @@ -6,6 +6,8 @@ void StoreApiTests::placeOrderTest() { PFXStoreApi api; + // api.setUsername("TestName"); + // api.setPassword("TestPassword"); QEventLoop loop; bool orderPlaced = false; @@ -36,6 +38,7 @@ void StoreApiTests::placeOrderTest() { void StoreApiTests::getOrderByIdTest() { PFXStoreApi api; + api.setApiKey("api_key_2","testKey"); QEventLoop loop; bool orderFetched = false; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index eb917a7ef60..d637fddb7fe 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -99,7 +99,6 @@ void PFXPetApi::addPet(const PFXPet &body) { .arg("/pet"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -149,7 +148,6 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const QString &api_key) { fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -197,7 +195,6 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) { .arg("/pet/findByStatus"); - if (status.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, status) { @@ -289,7 +286,6 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) { .arg("/pet/findByTags"); - if (tags.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, tags) { @@ -383,10 +379,11 @@ void PFXPetApi::getPetById(const qint64 &pet_id) { pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - addHeaders("api_key",_apiKeys.find("api_key").value()); + if(_apiKeys.contains("api_key")){ + addHeaders("api_key",_apiKeys.find("api_key").value()); + } - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -431,7 +428,6 @@ void PFXPetApi::updatePet(const PFXPet &body) { .arg("/pet"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -481,7 +477,6 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QString &name, con fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -530,7 +525,6 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const QString &additional_metad fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index e1d8d69cce6..922e1fd5c3d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -102,7 +102,6 @@ void PFXStoreApi::deleteOrder(const QString &order_id) { fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -145,10 +144,11 @@ void PFXStoreApi::getInventory() { .arg(_basePath) .arg("/store/inventory"); - addHeaders("api_key",_apiKeys.find("api_key").value()); + if(_apiKeys.contains("api_key")){ + addHeaders("api_key",_apiKeys.find("api_key").value()); + } - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -205,7 +205,6 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) { fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -250,7 +249,6 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) { .arg("/store/order"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index c1130069c53..68390407530 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -99,7 +99,6 @@ void PFXUserApi::createUser(const PFXUser &body) { .arg("/user"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -146,7 +145,6 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) { .arg("/user/createWithArray"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -194,7 +192,6 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) { .arg("/user/createWithList"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -245,7 +242,6 @@ void PFXUserApi::deleteUser(const QString &username) { fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -292,7 +288,6 @@ void PFXUserApi::getUserByName(const QString &username) { fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -337,7 +332,6 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { .arg("/user/login"); - if (fullPath.indexOf("?") > 0) fullPath.append("&"); else @@ -395,7 +389,6 @@ void PFXUserApi::logoutUser() { .arg("/user/logout"); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -442,7 +435,6 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) { fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); - PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); -- GitLab