diff --git a/docs/generators/cpp-qt5-client.md b/docs/generators/cpp-qt5-client.md index 282c674f9edd..02ea56a5c436 100644 --- a/docs/generators/cpp-qt5-client.md +++ b/docs/generators/cpp-qt5-client.md @@ -236,7 +236,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl |ApiKey|✓|OAS2,OAS3 |OpenIDConnect|✗|OAS3 |BearerToken|✓|OAS3 -|OAuth2_Implicit|✗|OAS2,OAS3 +|OAuth2_Implicit|✓|OAS2,OAS3 |OAuth2_Password|✗|OAS2,OAS3 |OAuth2_ClientCredentials|✗|OAS2,OAS3 |OAuth2_AuthorizationCode|✗|OAS2,OAS3 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 bda75d399c29..69c77a97eeb1 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 @@ -46,6 +46,7 @@ public CppQt5ClientCodegen() { .includeSecurityFeatures(SecurityFeature.BasicAuth) .includeSecurityFeatures(SecurityFeature.ApiKey) .includeSecurityFeatures(SecurityFeature.BearerToken) + .includeSecurityFeatures(SecurityFeature.OAuth2_Implicit) .includeGlobalFeatures(GlobalFeature.ParameterStyling) ); 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 855560a0b0d7..47e5aa1d2317 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 @@ -83,6 +83,10 @@ void {{classname}}::setBearerToken(const QString &token){ _bearerToken = token; } +void {{classname}}::setOauthToken(const QString &token){ + _oauthToken = token; +} + void {{classname}}::setUsername(const QString &username) { _username = username; } @@ -249,7 +253,10 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} QByteArray b64; b64.append(_username.toUtf8() + ":" + _password.toUtf8()); addHeaders("Authorization","Basic " + b64.toBase64()); - }{{/isBasicBasic}}{{/authMethods}} + }{{/isBasicBasic}}{{#isOAuth}} + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + {{/isOAuth}}{{/authMethods}} {{#pathParams}} {{^required}}if(!{{paramName}}.isNull()){{/required}} 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 ec9228f4f6ab..ccfabaa2033f 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 @@ -31,6 +31,7 @@ public: void setServerIndex(const QString &operation, int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); + void setOauthToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setTimeOut(const int timeOut); @@ -65,6 +66,7 @@ private: QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; + QString _oauthToken; QString _username; QString _password; int _timeOut; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index 79cad8362a57..c6c991e50564 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -89,6 +89,10 @@ void PFXPetApi::setBearerToken(const QString &token){ _bearerToken = token; } +void PFXPetApi::setOauthToken(const QString &token){ + _oauthToken = token; +} + void PFXPetApi::setUsername(const QString &username) { _username = username; } @@ -234,6 +238,9 @@ QString PFXPetApi::getParamStyleDelimiter(QString style, QString name, bool isEx void PFXPetApi::addPet(const PFXPet &body) { QString fullPath = QString(_serverConfigs["addPet"][_serverIndices.value("addPet")].URL()+"/pet"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -275,6 +282,20 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::deletePet(const qint64 &pet_id, const QVariant &api_key) { QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); { @@ -334,6 +355,9 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::findPetsByStatus(const QList &status) { QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + QString queryPrefix, querySuffix, queryDelimiter, queryStyle; @@ -469,6 +493,9 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::findPetsByTags(const QList &tags) { QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + QString queryPrefix, querySuffix, queryDelimiter, queryStyle; @@ -662,6 +689,9 @@ void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::updatePet(const PFXPet &body) { QString fullPath = QString(_serverConfigs["updatePet"][_serverIndices.value("updatePet")].URL()+"/pet"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); worker->setTimeOut(_timeOut); @@ -703,6 +733,20 @@ void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const QVariant &name, const QVariant &status) { QString fullPath = QString(_serverConfigs["updatePetWithForm"][_serverIndices.value("updatePetWithForm")].URL()+"/pet/{petId}"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); { @@ -768,6 +812,20 @@ void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) { void PFXPetApi::uploadFile(const qint64 &pet_id, const QVariant &additional_metadata, const QVariant &file) { QString fullPath = QString(_serverConfigs["uploadFile"][_serverIndices.value("uploadFile")].URL()+"/pet/{petId}/uploadImage"); + if(!_oauthToken.isEmpty()) + addHeaders("Authorization", "Bearer " + _oauthToken); + + QString pet_idPathParam("{"); + pet_idPathParam.append("petId").append("}"); + QString pathPrefix, pathSuffix, pathDelimiter; + QString pathStyle = ""; + if(pathStyle == "") + pathStyle = "simple"; + pathPrefix = getParamStylePrefix(pathStyle); + pathSuffix = getParamStyleSuffix(pathStyle); + pathDelimiter = getParamStyleDelimiter(pathStyle, "petId", false); + QString paramString = (pathStyle == "matrix") ? pathPrefix+"petId"+pathSuffix : pathPrefix; + fullPath.replace(pet_idPathParam, paramString+QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); { diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index 93fcee1b7fab..97569f6fc91a 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -41,6 +41,7 @@ class PFXPetApi : public QObject { void setServerIndex(const QString &operation, int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); + void setOauthToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setTimeOut(const int timeOut); @@ -108,6 +109,7 @@ class PFXPetApi : public QObject { QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; + QString _oauthToken; QString _username; QString _password; int _timeOut; diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index e8e8c4a94c2f..f1ee34e106c2 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -77,6 +77,10 @@ void PFXStoreApi::setBearerToken(const QString &token){ _bearerToken = token; } +void PFXStoreApi::setOauthToken(const QString &token){ + _oauthToken = token; +} + void PFXStoreApi::setUsername(const QString &username) { _username = username; } diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index 8a467731d48b..03faee207ee4 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -40,6 +40,7 @@ class PFXStoreApi : public QObject { void setServerIndex(const QString &operation, int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); + void setOauthToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setTimeOut(const int timeOut); @@ -80,6 +81,7 @@ class PFXStoreApi : public QObject { QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; + QString _oauthToken; QString _username; QString _password; int _timeOut; diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index 2379544e5213..8633317ab706 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -89,6 +89,10 @@ void PFXUserApi::setBearerToken(const QString &token){ _bearerToken = token; } +void PFXUserApi::setOauthToken(const QString &token){ + _oauthToken = token; +} + void PFXUserApi::setUsername(const QString &username) { _username = username; } diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index 8c0751772119..42c592373c6b 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -40,6 +40,7 @@ class PFXUserApi : public QObject { void setServerIndex(const QString &operation, int serverIndex); void setApiKey(const QString &apiKeyName, const QString &apiKey); void setBearerToken(const QString &token); + void setOauthToken(const QString &token); void setUsername(const QString &username); void setPassword(const QString &password); void setTimeOut(const int timeOut); @@ -102,6 +103,7 @@ class PFXUserApi : public QObject { QMap> _serverConfigs; QMap _apiKeys; QString _bearerToken; + QString _oauthToken; QString _username; QString _password; int _timeOut;