From cb1a620628a63cbca1375eaad9b8d83127224d6c Mon Sep 17 00:00:00 2001 From: basyskom-dege <72982549+basyskom-dege@users.noreply.github.com> Date: Sat, 28 Nov 2020 08:02:09 +0100 Subject: [PATCH] [C++][Qt5] added Authentication Support (#8004) * first commit of api Key feature. * added multi key and URL query key support * fixed error in mustache files, updated samples and tests * added Basic Auth with Base64 encoding. * updated Readme, added bearer token * added check that authentication credentials are set. fixed typo in README --- .../languages/CppQt5ClientCodegen.java | 2 + .../resources/cpp-qt5-client/README.mustache | 183 ++++++++++++++++++ .../cpp-qt5-client/api-body.mustache | 38 +++- .../cpp-qt5-client/api-header.mustache | 10 + .../petstore/cpp-qt5/PetStore/PetApiTests.cpp | 1 + .../cpp-qt5/PetStore/StoreApiTests.cpp | 4 + samples/client/petstore/cpp-qt5/README.md | 174 +++++++++++++++++ .../petstore/cpp-qt5/client/PFXPetApi.cpp | 28 +++ .../petstore/cpp-qt5/client/PFXPetApi.h | 10 + .../petstore/cpp-qt5/client/PFXStoreApi.cpp | 24 +++ .../petstore/cpp-qt5/client/PFXStoreApi.h | 10 + .../petstore/cpp-qt5/client/PFXUserApi.cpp | 24 +++ .../petstore/cpp-qt5/client/PFXUserApi.h | 10 + 13 files changed, 517 insertions(+), 1 deletion(-) create mode 100644 modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache create mode 100644 samples/client/petstore/cpp-qt5/README.md 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..2cd99b3520e --- /dev/null +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/README.mustache @@ -0,0 +1,183 @@ +# {{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 -g cpp-qt5-client -o +``` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +example.h: + +```c++ +{{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} +#include +#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 +#include + +{{#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}} +{{#isBasicBasic}} + +- **Type**: HTTP basic authentication +{{/isBasicBasic}} +{{#isBasicBearer}} +- **Type**: HTTP Bearer Token authentication +{{/isBasicBearer}} +{{#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 2d90ddfb681..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 @@ -34,6 +34,22 @@ void {{classname}}::setPort(int port) { _port = port; } +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; +} + +void {{classname}}::setPassword(const QString &password) { + _password = password; +} + void {{classname}}::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -79,7 +95,27 @@ 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}} + {{/pathParams}}{{#authMethods}}{{#isApiKey}}{{#isKeyInHeader}} + if(_apiKeys.contains("{{name}}")){ + addHeaders("{{name}}",_apiKeys.find("{{name}}").value()); + } + {{/isKeyInHeader}}{{#isKeyInQuery}} + if(_apiKeys.contains("{{name}}")){ + if (fullPath.indexOf("?") > 0) + fullPath.append("&"); + else + fullPath.append("?"); + fullPath.append("{{{name}}}=").append(_apiKeys.find("{{name}}").value()); + } + {{/isKeyInQuery}}{{/isApiKey}}{{#isBasicBearer}} + if(!_bearerToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _bearerToken); + {{/isBasicBearer}}{{#isBasicBasic}} + 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/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..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 @@ -8,6 +8,8 @@ {{/imports}} #include +#include +#include #include {{#cppNamespaceDeclarations}} @@ -24,6 +26,10 @@ public: void setScheme(const QString &scheme); 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); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -38,6 +44,10 @@ public: private: QString _scheme, _host; int _port; + QMap _apiKeys; + QString _bearerToken; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory; 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..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; @@ -59,6 +62,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/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 -g cpp-qt5-client -o +``` + +## Getting Started + +Please follow the [installation](#installation) instruction and execute the following Java code: + +example.h: + +```c++ + +#include +#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 +#include + +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 c94bcc0da8a..d637fddb7fe 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -42,6 +42,22 @@ void PFXPetApi::setPort(int port) { _port = port; } +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; +} + +void PFXPetApi::setPassword(const QString &password) { + _password = password; +} + void PFXPetApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -82,6 +98,7 @@ void PFXPetApi::addPet(const PFXPet &body) { .arg(_basePath) .arg("/pet"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -129,6 +146,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); worker->setTimeOut(_timeOut); @@ -176,6 +194,7 @@ void PFXPetApi::findPetsByStatus(const QList &status) { .arg(_basePath) .arg("/pet/findByStatus"); + if (status.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, status) { @@ -266,6 +285,7 @@ void PFXPetApi::findPetsByTags(const QList &tags) { .arg(_basePath) .arg("/pet/findByTags"); + if (tags.size() > 0) { if (QString("csv").indexOf("multi") == 0) { foreach (QString t, tags) { @@ -358,6 +378,11 @@ 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))); + + if(_apiKeys.contains("api_key")){ + addHeaders("api_key",_apiKeys.find("api_key").value()); + } + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -402,6 +427,7 @@ void PFXPetApi::updatePet(const PFXPet &body) { .arg(_basePath) .arg("/pet"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -449,6 +475,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); worker->setTimeOut(_timeOut); @@ -496,6 +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); worker->setTimeOut(_timeOut); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index aa85e82e34e..71f0e48cb37 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -20,6 +20,8 @@ #include #include +#include +#include #include namespace test_namespace { @@ -34,6 +36,10 @@ public: void setScheme(const QString &scheme); 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); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -55,6 +61,10 @@ public: private: QString _scheme, _host; int _port; + QMap _apiKeys; + QString _bearerToken; + 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 d56512f6112..922e1fd5c3d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -42,6 +42,22 @@ void PFXStoreApi::setPort(int port) { _port = port; } +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; +} + +void PFXStoreApi::setPassword(const QString &password) { + _password = password; +} + void PFXStoreApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -84,6 +100,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); worker->setTimeOut(_timeOut); @@ -127,6 +144,11 @@ void PFXStoreApi::getInventory() { .arg(_basePath) .arg("/store/inventory"); + 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); @@ -181,6 +203,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); worker->setTimeOut(_timeOut); @@ -225,6 +248,7 @@ 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..626a0236ee4 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -19,6 +19,8 @@ #include #include +#include +#include #include namespace test_namespace { @@ -33,6 +35,10 @@ public: void setScheme(const QString &scheme); 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); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -50,6 +56,10 @@ public: private: QString _scheme, _host; int _port; + QMap _apiKeys; + QString _bearerToken; + 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 74060393b01..68390407530 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -42,6 +42,22 @@ void PFXUserApi::setPort(int port) { _port = port; } +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; +} + +void PFXUserApi::setPassword(const QString &password) { + _password = password; +} + void PFXUserApi::setBasePath(const QString &basePath) { _basePath = basePath; } @@ -82,6 +98,7 @@ void PFXUserApi::createUser(const PFXUser &body) { .arg(_basePath) .arg("/user"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -127,6 +144,7 @@ void PFXUserApi::createUsersWithArrayInput(const QList &body) { .arg(_basePath) .arg("/user/createWithArray"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -173,6 +191,7 @@ void PFXUserApi::createUsersWithListInput(const QList &body) { .arg(_basePath) .arg("/user/createWithList"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -221,6 +240,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); worker->setTimeOut(_timeOut); @@ -266,6 +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); worker->setTimeOut(_timeOut); @@ -310,6 +331,7 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) { .arg(_basePath) .arg("/user/login"); + if (fullPath.indexOf("?") > 0) fullPath.append("&"); else @@ -366,6 +388,7 @@ void PFXUserApi::logoutUser() { .arg(_basePath) .arg("/user/logout"); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); worker->setWorkingDirectory(_workingDirectory); @@ -410,6 +433,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); worker->setTimeOut(_timeOut); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index e2698e5d1a2..d6bb21b5a8d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -19,6 +19,8 @@ #include #include +#include +#include #include namespace test_namespace { @@ -33,6 +35,10 @@ public: void setScheme(const QString &scheme); 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); void setTimeOut(const int timeOut); void setWorkingDirectory(const QString &path); @@ -54,6 +60,10 @@ public: private: QString _scheme, _host; int _port; + QMap _apiKeys; + QString _bearerToken; + QString _username; + QString _password; QString _basePath; int _timeOut; QString _workingDirectory;