Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generators/cpp-qt5-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public CppQt5ClientCodegen() {
.includeSecurityFeatures(SecurityFeature.BasicAuth)
.includeSecurityFeatures(SecurityFeature.ApiKey)
.includeSecurityFeatures(SecurityFeature.BearerToken)
.includeSecurityFeatures(SecurityFeature.OAuth2_Implicit)
.includeGlobalFeatures(GlobalFeature.ParameterStyling)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -65,6 +66,7 @@ private:
QMap<QString,QList<{{prefix}}ServerConfiguration>> _serverConfigs;
QMap<QString, QString> _apiKeys;
QString _bearerToken;
QString _oauthToken;
QString _username;
QString _password;
int _timeOut;
Expand Down
58 changes: 58 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));


{
Expand Down Expand Up @@ -334,6 +355,9 @@ void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
QString fullPath = QString(_serverConfigs["findPetsByStatus"][_serverIndices.value("findPetsByStatus")].URL()+"/pet/findByStatus");

if(!_oauthToken.isEmpty())
addHeaders("Authorization", "Bearer " + _oauthToken);


QString queryPrefix, querySuffix, queryDelimiter, queryStyle;

Expand Down Expand Up @@ -469,6 +493,9 @@ void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
QString fullPath = QString(_serverConfigs["findPetsByTags"][_serverIndices.value("findPetsByTags")].URL()+"/pet/findByTags");

if(!_oauthToken.isEmpty())
addHeaders("Authorization", "Bearer " + _oauthToken);


QString queryPrefix, querySuffix, queryDelimiter, queryStyle;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)));


{
Expand Down Expand Up @@ -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)));


{
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXPetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -108,6 +109,7 @@ class PFXPetApi : public QObject {
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
QMap<QString, QString> _apiKeys;
QString _bearerToken;
QString _oauthToken;
QString _username;
QString _password;
int _timeOut;
Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXStoreApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -80,6 +81,7 @@ class PFXStoreApi : public QObject {
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
QMap<QString, QString> _apiKeys;
QString _bearerToken;
QString _oauthToken;
QString _username;
QString _password;
int _timeOut;
Expand Down
4 changes: 4 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions samples/client/petstore/cpp-qt5/client/PFXUserApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -102,6 +103,7 @@ class PFXUserApi : public QObject {
QMap<QString,QList<PFXServerConfiguration>> _serverConfigs;
QMap<QString, QString> _apiKeys;
QString _bearerToken;
QString _oauthToken;
QString _username;
QString _password;
int _timeOut;
Expand Down