forked from loafle/openapi-generator-original
cpp-qt-client: Fix cppcheck warnings (#10322)
* Fix cppcheck warnings * Improve coding style * Add 4 spaces
This commit is contained in:
parent
86ead27a40
commit
2239ca36fd
@ -11,8 +11,8 @@ namespace {{this}} {
|
|||||||
{{classname}}::{{classname}}(const int timeOut)
|
{{classname}}::{{classname}}(const int timeOut)
|
||||||
: _timeOut(timeOut),
|
: _timeOut(timeOut),
|
||||||
_manager(nullptr),
|
_manager(nullptr),
|
||||||
isResponseCompressionEnabled(false),
|
_isResponseCompressionEnabled(false),
|
||||||
isRequestCompressionEnabled(false) {
|
_isRequestCompressionEnabled(false) {
|
||||||
initializeServerConfigs();
|
initializeServerConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -23,7 +23,9 @@ void {{classname}}::initializeServerConfigs(){
|
|||||||
//Default server
|
//Default server
|
||||||
QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>();
|
QList<{{prefix}}ServerConfiguration> defaultConf = QList<{{prefix}}ServerConfiguration>();
|
||||||
//varying endpoint server
|
//varying endpoint server
|
||||||
|
{{#servers}}
|
||||||
QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>();
|
QList<{{prefix}}ServerConfiguration> serverConf = QList<{{prefix}}ServerConfiguration>();
|
||||||
|
{{/servers}}
|
||||||
{{#vendorExtensions.x-cpp-global-server-list}}
|
{{#vendorExtensions.x-cpp-global-server-list}}
|
||||||
defaultConf.append({{prefix}}ServerConfiguration(
|
defaultConf.append({{prefix}}ServerConfiguration(
|
||||||
QUrl("{{{url}}}"),
|
QUrl("{{{url}}}"),
|
||||||
@ -66,9 +68,10 @@ int {{classname}}::setDefaultServerValue(int serverIndex, const QString &operati
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
void {{classname}}::setServerIndex(const QString &operation, int serverIndex) {
|
void {{classname}}::setServerIndex(const QString &operation, int serverIndex) {
|
||||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||||
_serverIndices[operation] = serverIndex;
|
_serverIndices[operation] = serverIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
void {{classname}}::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||||
_apiKeys.insert(apiKeyName,apiKey);
|
_apiKeys.insert(apiKeyName,apiKey);
|
||||||
@ -126,8 +129,8 @@ int {{classname}}::addServerConfiguration(const QString &operation, const QUrl &
|
|||||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||||
*/
|
*/
|
||||||
void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &variables) {
|
void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &variables) {
|
||||||
for(auto e : _serverIndices.keys()){
|
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,22 +145,22 @@ void {{classname}}::setNewServer(const QString &operation, const QUrl &url, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void {{classname}}::addHeaders(const QString &key, const QString &value) {
|
void {{classname}}::addHeaders(const QString &key, const QString &value) {
|
||||||
defaultHeaders.insert(key, value);
|
_defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{classname}}::enableRequestCompression() {
|
void {{classname}}::enableRequestCompression() {
|
||||||
isRequestCompressionEnabled = true;
|
_isRequestCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{classname}}::enableResponseCompression() {
|
void {{classname}}::enableResponseCompression() {
|
||||||
isResponseCompressionEnabled = true;
|
_isResponseCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void {{classname}}::abortRequests() {
|
void {{classname}}::abortRequests() {
|
||||||
emit abortRequestsSignal();
|
emit abortRequestsSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString {{classname}}::getParamStylePrefix(QString style){
|
QString {{classname}}::getParamStylePrefix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return ";";
|
return ";";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -175,7 +178,7 @@ QString {{classname}}::getParamStylePrefix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString {{classname}}::getParamStyleSuffix(QString style){
|
QString {{classname}}::getParamStyleSuffix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return "=";
|
return "=";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -193,7 +196,7 @@ QString {{classname}}::getParamStyleSuffix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString {{classname}}::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
QString {{classname}}::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||||
|
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return (isExplode) ? ";" + name + "=" : ",";
|
return (isExplode) ? ";" + name + "=" : ",";
|
||||||
@ -474,8 +477,8 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
|||||||
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
|
{{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this, _manager);
|
||||||
worker->setTimeOut(_timeOut);
|
worker->setTimeOut(_timeOut);
|
||||||
worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}}
|
worker->setWorkingDirectory(_workingDirectory);{{#contentCompression}}
|
||||||
worker->setResponseCompressionEnabled(isResponseCompressionEnabled);
|
worker->setResponseCompressionEnabled(_isResponseCompressionEnabled);
|
||||||
worker->setRequestCompressionEnabled(isRequestCompressionEnabled);{{/contentCompression}}
|
worker->setRequestCompressionEnabled(_isRequestCompressionEnabled);{{/contentCompression}}
|
||||||
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
{{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||||
|
|
||||||
{{#formParams}}
|
{{#formParams}}
|
||||||
@ -653,11 +656,13 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
{{/cookieParams}}
|
{{/cookieParams}}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
|
||||||
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
|
if (findChildren<{{prefix}}HttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -667,15 +672,11 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
|
|||||||
}
|
}
|
||||||
|
|
||||||
void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
|
void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
{{#returnType}}
|
{{#returnType}}
|
||||||
{{#isArray}}
|
{{#isArray}}
|
||||||
|
@ -43,9 +43,9 @@ public:
|
|||||||
void enableRequestCompression();
|
void enableRequestCompression();
|
||||||
void enableResponseCompression();
|
void enableResponseCompression();
|
||||||
void abortRequests();
|
void abortRequests();
|
||||||
QString getParamStylePrefix(QString style);
|
QString getParamStylePrefix(const QString &style);
|
||||||
QString getParamStyleSuffix(QString style);
|
QString getParamStyleSuffix(const QString &style);
|
||||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||||
{{#operations}}{{#operation}}
|
{{#operations}}{{#operation}}
|
||||||
{{#hasParams}} /**
|
{{#hasParams}} /**
|
||||||
{{#allParams}}
|
{{#allParams}}
|
||||||
@ -70,9 +70,9 @@ private:
|
|||||||
int _timeOut;
|
int _timeOut;
|
||||||
QString _workingDirectory;
|
QString _workingDirectory;
|
||||||
QNetworkAccessManager* _manager;
|
QNetworkAccessManager* _manager;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> _defaultHeaders;
|
||||||
bool isResponseCompressionEnabled;
|
bool _isResponseCompressionEnabled;
|
||||||
bool isRequestCompressionEnabled;
|
bool _isRequestCompressionEnabled;
|
||||||
{{#operations}}{{#operation}}
|
{{#operations}}{{#operation}}
|
||||||
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}
|
void {{nickname}}Callback({{prefix}}HttpRequestWorker *worker);{{/operation}}{{/operations}}
|
||||||
|
|
||||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
|||||||
PFXPetApi::PFXPetApi(const int timeOut)
|
PFXPetApi::PFXPetApi(const int timeOut)
|
||||||
: _timeOut(timeOut),
|
: _timeOut(timeOut),
|
||||||
_manager(nullptr),
|
_manager(nullptr),
|
||||||
isResponseCompressionEnabled(false),
|
_isResponseCompressionEnabled(false),
|
||||||
isRequestCompressionEnabled(false) {
|
_isRequestCompressionEnabled(false) {
|
||||||
initializeServerConfigs();
|
initializeServerConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ void PFXPetApi::initializeServerConfigs(){
|
|||||||
//Default server
|
//Default server
|
||||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||||
//varying endpoint server
|
//varying endpoint server
|
||||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
|
||||||
defaultConf.append(PFXServerConfiguration(
|
defaultConf.append(PFXServerConfiguration(
|
||||||
QUrl("http://petstore.swagger.io/v2"),
|
QUrl("http://petstore.swagger.io/v2"),
|
||||||
"No description provided",
|
"No description provided",
|
||||||
@ -66,9 +65,10 @@ int PFXPetApi::setDefaultServerValue(int serverIndex, const QString &operation,
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) {
|
void PFXPetApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||||
_serverIndices[operation] = serverIndex;
|
_serverIndices[operation] = serverIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
void PFXPetApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||||
_apiKeys.insert(apiKeyName,apiKey);
|
_apiKeys.insert(apiKeyName,apiKey);
|
||||||
@ -126,8 +126,8 @@ int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url,
|
|||||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||||
*/
|
*/
|
||||||
void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
||||||
for(auto e : _serverIndices.keys()){
|
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,22 +142,22 @@ void PFXPetApi::setNewServer(const QString &operation, const QUrl &url, const QS
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::addHeaders(const QString &key, const QString &value) {
|
void PFXPetApi::addHeaders(const QString &key, const QString &value) {
|
||||||
defaultHeaders.insert(key, value);
|
_defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::enableRequestCompression() {
|
void PFXPetApi::enableRequestCompression() {
|
||||||
isRequestCompressionEnabled = true;
|
_isRequestCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::enableResponseCompression() {
|
void PFXPetApi::enableResponseCompression() {
|
||||||
isResponseCompressionEnabled = true;
|
_isResponseCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::abortRequests() {
|
void PFXPetApi::abortRequests() {
|
||||||
emit abortRequestsSignal();
|
emit abortRequestsSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXPetApi::getParamStylePrefix(QString style){
|
QString PFXPetApi::getParamStylePrefix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return ";";
|
return ";";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -175,7 +175,7 @@ QString PFXPetApi::getParamStylePrefix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXPetApi::getParamStyleSuffix(QString style){
|
QString PFXPetApi::getParamStyleSuffix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return "=";
|
return "=";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -193,7 +193,7 @@ QString PFXPetApi::getParamStyleSuffix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXPetApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
QString PFXPetApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||||
|
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return (isExplode) ? ";" + name + "=" : ",";
|
return (isExplode) ? ";" + name + "=" : ",";
|
||||||
@ -233,11 +233,13 @@ void PFXPetApi::addPet(const PFXPet &body) {
|
|||||||
QByteArray output = body.asJson().toUtf8();
|
QByteArray output = body.asJson().toUtf8();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -247,15 +249,11 @@ void PFXPetApi::addPet(const PFXPet &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -297,11 +295,13 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
|
|||||||
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
|
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -311,15 +311,11 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::deletePetCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -427,11 +423,13 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -441,15 +439,11 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
QList<PFXPet> output;
|
QList<PFXPet> output;
|
||||||
QString json(worker->response);
|
QString json(worker->response);
|
||||||
@ -567,11 +561,13 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -581,15 +577,11 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
QList<PFXPet> output;
|
QList<PFXPet> output;
|
||||||
QString json(worker->response);
|
QString json(worker->response);
|
||||||
@ -639,11 +631,13 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -653,15 +647,11 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
PFXPet output(QString(worker->response));
|
PFXPet output(QString(worker->response));
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
@ -688,11 +678,13 @@ void PFXPetApi::updatePet(const PFXPet &body) {
|
|||||||
QByteArray output = body.asJson().toUtf8();
|
QByteArray output = body.asJson().toUtf8();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -702,15 +694,11 @@ void PFXPetApi::updatePet(const PFXPet &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::updatePetCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -754,11 +742,13 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
|
|||||||
input.add_var("status", ::test_namespace::toStringValue(status.value()));
|
input.add_var("status", ::test_namespace::toStringValue(status.value()));
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -768,15 +758,11 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -820,11 +806,13 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
|
|||||||
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
|
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
|
||||||
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -834,15 +822,11 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXPetApi::uploadFileCallback(PFXHttpRequestWorker *worker) {
|
void PFXPetApi::uploadFileCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
PFXApiResponse output(QString(worker->response));
|
PFXApiResponse output(QString(worker->response));
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
@ -53,9 +53,9 @@ public:
|
|||||||
void enableRequestCompression();
|
void enableRequestCompression();
|
||||||
void enableResponseCompression();
|
void enableResponseCompression();
|
||||||
void abortRequests();
|
void abortRequests();
|
||||||
QString getParamStylePrefix(QString style);
|
QString getParamStylePrefix(const QString &style);
|
||||||
QString getParamStyleSuffix(QString style);
|
QString getParamStyleSuffix(const QString &style);
|
||||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] body PFXPet [required]
|
* @param[in] body PFXPet [required]
|
||||||
@ -113,9 +113,9 @@ private:
|
|||||||
int _timeOut;
|
int _timeOut;
|
||||||
QString _workingDirectory;
|
QString _workingDirectory;
|
||||||
QNetworkAccessManager* _manager;
|
QNetworkAccessManager* _manager;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> _defaultHeaders;
|
||||||
bool isResponseCompressionEnabled;
|
bool _isResponseCompressionEnabled;
|
||||||
bool isRequestCompressionEnabled;
|
bool _isRequestCompressionEnabled;
|
||||||
|
|
||||||
void addPetCallback(PFXHttpRequestWorker *worker);
|
void addPetCallback(PFXHttpRequestWorker *worker);
|
||||||
void deletePetCallback(PFXHttpRequestWorker *worker);
|
void deletePetCallback(PFXHttpRequestWorker *worker);
|
||||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
|||||||
PFXStoreApi::PFXStoreApi(const int timeOut)
|
PFXStoreApi::PFXStoreApi(const int timeOut)
|
||||||
: _timeOut(timeOut),
|
: _timeOut(timeOut),
|
||||||
_manager(nullptr),
|
_manager(nullptr),
|
||||||
isResponseCompressionEnabled(false),
|
_isResponseCompressionEnabled(false),
|
||||||
isRequestCompressionEnabled(false) {
|
_isRequestCompressionEnabled(false) {
|
||||||
initializeServerConfigs();
|
initializeServerConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ void PFXStoreApi::initializeServerConfigs(){
|
|||||||
//Default server
|
//Default server
|
||||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||||
//varying endpoint server
|
//varying endpoint server
|
||||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
|
||||||
defaultConf.append(PFXServerConfiguration(
|
defaultConf.append(PFXServerConfiguration(
|
||||||
QUrl("http://petstore.swagger.io/v2"),
|
QUrl("http://petstore.swagger.io/v2"),
|
||||||
"No description provided",
|
"No description provided",
|
||||||
@ -58,9 +57,10 @@ int PFXStoreApi::setDefaultServerValue(int serverIndex, const QString &operation
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex) {
|
void PFXStoreApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||||
_serverIndices[operation] = serverIndex;
|
_serverIndices[operation] = serverIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
void PFXStoreApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||||
_apiKeys.insert(apiKeyName,apiKey);
|
_apiKeys.insert(apiKeyName,apiKey);
|
||||||
@ -118,8 +118,8 @@ int PFXStoreApi::addServerConfiguration(const QString &operation, const QUrl &ur
|
|||||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||||
*/
|
*/
|
||||||
void PFXStoreApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
void PFXStoreApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
||||||
for(auto e : _serverIndices.keys()){
|
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,22 +134,22 @@ void PFXStoreApi::setNewServer(const QString &operation, const QUrl &url, const
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::addHeaders(const QString &key, const QString &value) {
|
void PFXStoreApi::addHeaders(const QString &key, const QString &value) {
|
||||||
defaultHeaders.insert(key, value);
|
_defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::enableRequestCompression() {
|
void PFXStoreApi::enableRequestCompression() {
|
||||||
isRequestCompressionEnabled = true;
|
_isRequestCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::enableResponseCompression() {
|
void PFXStoreApi::enableResponseCompression() {
|
||||||
isResponseCompressionEnabled = true;
|
_isResponseCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::abortRequests() {
|
void PFXStoreApi::abortRequests() {
|
||||||
emit abortRequestsSignal();
|
emit abortRequestsSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXStoreApi::getParamStylePrefix(QString style){
|
QString PFXStoreApi::getParamStylePrefix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return ";";
|
return ";";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -167,7 +167,7 @@ QString PFXStoreApi::getParamStylePrefix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXStoreApi::getParamStyleSuffix(QString style){
|
QString PFXStoreApi::getParamStyleSuffix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return "=";
|
return "=";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -185,7 +185,7 @@ QString PFXStoreApi::getParamStyleSuffix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXStoreApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
QString PFXStoreApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||||
|
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return (isExplode) ? ";" + name + "=" : ",";
|
return (isExplode) ? ";" + name + "=" : ",";
|
||||||
@ -235,11 +235,13 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
|
|||||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::deleteOrderCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::deleteOrderCallback);
|
||||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -249,15 +251,11 @@ void PFXStoreApi::deleteOrder(const QString &order_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker *worker) {
|
void PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -283,11 +281,13 @@ void PFXStoreApi::getInventory() {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getInventoryCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getInventoryCallback);
|
||||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -297,15 +297,11 @@ void PFXStoreApi::getInventory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) {
|
void PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
QMap<QString, qint32> output;
|
QMap<QString, qint32> output;
|
||||||
QString json(worker->response);
|
QString json(worker->response);
|
||||||
@ -351,11 +347,13 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getOrderByIdCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::getOrderByIdCallback);
|
||||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -365,15 +363,11 @@ void PFXStoreApi::getOrderById(const qint64 &order_id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) {
|
void PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
PFXOrder output(QString(worker->response));
|
PFXOrder output(QString(worker->response));
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
@ -400,11 +394,13 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
|
|||||||
QByteArray output = body.asJson().toUtf8();
|
QByteArray output = body.asJson().toUtf8();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::placeOrderCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXStoreApi::placeOrderCallback);
|
||||||
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXStoreApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -414,15 +410,11 @@ void PFXStoreApi::placeOrder(const PFXOrder &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXStoreApi::placeOrderCallback(PFXHttpRequestWorker *worker) {
|
void PFXStoreApi::placeOrderCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
PFXOrder output(QString(worker->response));
|
PFXOrder output(QString(worker->response));
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
@ -52,9 +52,9 @@ public:
|
|||||||
void enableRequestCompression();
|
void enableRequestCompression();
|
||||||
void enableResponseCompression();
|
void enableResponseCompression();
|
||||||
void abortRequests();
|
void abortRequests();
|
||||||
QString getParamStylePrefix(QString style);
|
QString getParamStylePrefix(const QString &style);
|
||||||
QString getParamStyleSuffix(QString style);
|
QString getParamStyleSuffix(const QString &style);
|
||||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] order_id QString [required]
|
* @param[in] order_id QString [required]
|
||||||
@ -85,9 +85,9 @@ private:
|
|||||||
int _timeOut;
|
int _timeOut;
|
||||||
QString _workingDirectory;
|
QString _workingDirectory;
|
||||||
QNetworkAccessManager* _manager;
|
QNetworkAccessManager* _manager;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> _defaultHeaders;
|
||||||
bool isResponseCompressionEnabled;
|
bool _isResponseCompressionEnabled;
|
||||||
bool isRequestCompressionEnabled;
|
bool _isRequestCompressionEnabled;
|
||||||
|
|
||||||
void deleteOrderCallback(PFXHttpRequestWorker *worker);
|
void deleteOrderCallback(PFXHttpRequestWorker *worker);
|
||||||
void getInventoryCallback(PFXHttpRequestWorker *worker);
|
void getInventoryCallback(PFXHttpRequestWorker *worker);
|
||||||
|
@ -19,8 +19,8 @@ namespace test_namespace {
|
|||||||
PFXUserApi::PFXUserApi(const int timeOut)
|
PFXUserApi::PFXUserApi(const int timeOut)
|
||||||
: _timeOut(timeOut),
|
: _timeOut(timeOut),
|
||||||
_manager(nullptr),
|
_manager(nullptr),
|
||||||
isResponseCompressionEnabled(false),
|
_isResponseCompressionEnabled(false),
|
||||||
isRequestCompressionEnabled(false) {
|
_isRequestCompressionEnabled(false) {
|
||||||
initializeServerConfigs();
|
initializeServerConfigs();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ void PFXUserApi::initializeServerConfigs(){
|
|||||||
//Default server
|
//Default server
|
||||||
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
QList<PFXServerConfiguration> defaultConf = QList<PFXServerConfiguration>();
|
||||||
//varying endpoint server
|
//varying endpoint server
|
||||||
QList<PFXServerConfiguration> serverConf = QList<PFXServerConfiguration>();
|
|
||||||
defaultConf.append(PFXServerConfiguration(
|
defaultConf.append(PFXServerConfiguration(
|
||||||
QUrl("http://petstore.swagger.io/v2"),
|
QUrl("http://petstore.swagger.io/v2"),
|
||||||
"No description provided",
|
"No description provided",
|
||||||
@ -66,9 +65,10 @@ int PFXUserApi::setDefaultServerValue(int serverIndex, const QString &operation,
|
|||||||
return -3;
|
return -3;
|
||||||
}
|
}
|
||||||
void PFXUserApi::setServerIndex(const QString &operation, int serverIndex) {
|
void PFXUserApi::setServerIndex(const QString &operation, int serverIndex) {
|
||||||
if(_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size() )
|
if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) {
|
||||||
_serverIndices[operation] = serverIndex;
|
_serverIndices[operation] = serverIndex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
void PFXUserApi::setApiKey(const QString &apiKeyName, const QString &apiKey) {
|
||||||
_apiKeys.insert(apiKeyName,apiKey);
|
_apiKeys.insert(apiKeyName,apiKey);
|
||||||
@ -126,8 +126,8 @@ int PFXUserApi::addServerConfiguration(const QString &operation, const QUrl &url
|
|||||||
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
|
||||||
*/
|
*/
|
||||||
void PFXUserApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
void PFXUserApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
|
||||||
for(auto e : _serverIndices.keys()){
|
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
|
||||||
setServerIndex(e, addServerConfiguration(e, url, description, variables));
|
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,22 +142,22 @@ void PFXUserApi::setNewServer(const QString &operation, const QUrl &url, const Q
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
||||||
defaultHeaders.insert(key, value);
|
_defaultHeaders.insert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::enableRequestCompression() {
|
void PFXUserApi::enableRequestCompression() {
|
||||||
isRequestCompressionEnabled = true;
|
_isRequestCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::enableResponseCompression() {
|
void PFXUserApi::enableResponseCompression() {
|
||||||
isResponseCompressionEnabled = true;
|
_isResponseCompressionEnabled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::abortRequests() {
|
void PFXUserApi::abortRequests() {
|
||||||
emit abortRequestsSignal();
|
emit abortRequestsSignal();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXUserApi::getParamStylePrefix(QString style){
|
QString PFXUserApi::getParamStylePrefix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return ";";
|
return ";";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -175,7 +175,7 @@ QString PFXUserApi::getParamStylePrefix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXUserApi::getParamStyleSuffix(QString style){
|
QString PFXUserApi::getParamStyleSuffix(const QString &style) {
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return "=";
|
return "=";
|
||||||
} else if (style == "label") {
|
} else if (style == "label") {
|
||||||
@ -193,7 +193,7 @@ QString PFXUserApi::getParamStyleSuffix(QString style){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PFXUserApi::getParamStyleDelimiter(QString style, QString name, bool isExplode){
|
QString PFXUserApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) {
|
||||||
|
|
||||||
if (style == "matrix") {
|
if (style == "matrix") {
|
||||||
return (isExplode) ? ";" + name + "=" : ",";
|
return (isExplode) ? ";" + name + "=" : ",";
|
||||||
@ -233,11 +233,13 @@ void PFXUserApi::createUser(const PFXUser &body) {
|
|||||||
QByteArray output = body.asJson().toUtf8();
|
QByteArray output = body.asJson().toUtf8();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -247,15 +249,11 @@ void PFXUserApi::createUser(const PFXUser &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -281,11 +279,13 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
|||||||
QByteArray bytes = doc.toJson();
|
QByteArray bytes = doc.toJson();
|
||||||
input.request_body.append(bytes);
|
input.request_body.append(bytes);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -295,15 +295,11 @@ void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -329,11 +325,13 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
|||||||
QByteArray bytes = doc.toJson();
|
QByteArray bytes = doc.toJson();
|
||||||
input.request_body.append(bytes);
|
input.request_body.append(bytes);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -343,15 +341,11 @@ void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -387,11 +381,13 @@ void PFXUserApi::deleteUser(const QString &username) {
|
|||||||
PFXHttpRequestInput input(fullPath, "DELETE");
|
PFXHttpRequestInput input(fullPath, "DELETE");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -401,15 +397,11 @@ void PFXUserApi::deleteUser(const QString &username) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -445,11 +437,13 @@ void PFXUserApi::getUserByName(const QString &username) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -459,15 +453,11 @@ void PFXUserApi::getUserByName(const QString &username) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
PFXUser output(QString(worker->response));
|
PFXUser output(QString(worker->response));
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
@ -521,11 +511,13 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -535,15 +527,11 @@ void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
QString output;
|
QString output;
|
||||||
::test_namespace::fromStringValue(QString(worker->response), output);
|
::test_namespace::fromStringValue(QString(worker->response), output);
|
||||||
@ -567,11 +555,13 @@ void PFXUserApi::logoutUser() {
|
|||||||
PFXHttpRequestInput input(fullPath, "GET");
|
PFXHttpRequestInput input(fullPath, "GET");
|
||||||
|
|
||||||
|
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -581,15 +571,11 @@ void PFXUserApi::logoutUser() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
@ -629,11 +615,13 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
|||||||
QByteArray output = body.asJson().toUtf8();
|
QByteArray output = body.asJson().toUtf8();
|
||||||
input.request_body.append(output);
|
input.request_body.append(output);
|
||||||
}
|
}
|
||||||
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
|
||||||
|
input.headers.insert(keyValueIt->first, keyValueIt->second);
|
||||||
|
}
|
||||||
|
|
||||||
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback);
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback);
|
||||||
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
connect(this, &PFXUserApi::abortRequestsSignal, worker, &QObject::deleteLater);
|
||||||
connect(worker, &QObject::destroyed, [this](){
|
connect(worker, &QObject::destroyed, this, [this]() {
|
||||||
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
if (findChildren<PFXHttpRequestWorker*>().count() == 0) {
|
||||||
emit allPendingRequestsCompleted();
|
emit allPendingRequestsCompleted();
|
||||||
}
|
}
|
||||||
@ -643,15 +631,11 @@ void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void PFXUserApi::updateUserCallback(PFXHttpRequestWorker *worker) {
|
void PFXUserApi::updateUserCallback(PFXHttpRequestWorker *worker) {
|
||||||
QString msg;
|
|
||||||
QString error_str = worker->error_str;
|
QString error_str = worker->error_str;
|
||||||
QNetworkReply::NetworkError error_type = worker->error_type;
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
||||||
|
|
||||||
if (worker->error_type == QNetworkReply::NoError) {
|
if (worker->error_type != QNetworkReply::NoError) {
|
||||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response));
|
||||||
} else {
|
|
||||||
msg = "Error: " + worker->error_str;
|
|
||||||
error_str = QString("%1, %2").arg(worker->error_str).arg(QString(worker->response));
|
|
||||||
}
|
}
|
||||||
worker->deleteLater();
|
worker->deleteLater();
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ public:
|
|||||||
void enableRequestCompression();
|
void enableRequestCompression();
|
||||||
void enableResponseCompression();
|
void enableResponseCompression();
|
||||||
void abortRequests();
|
void abortRequests();
|
||||||
QString getParamStylePrefix(QString style);
|
QString getParamStylePrefix(const QString &style);
|
||||||
QString getParamStyleSuffix(QString style);
|
QString getParamStyleSuffix(const QString &style);
|
||||||
QString getParamStyleDelimiter(QString style, QString name, bool isExplode);
|
QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param[in] body PFXUser [required]
|
* @param[in] body PFXUser [required]
|
||||||
@ -107,9 +107,9 @@ private:
|
|||||||
int _timeOut;
|
int _timeOut;
|
||||||
QString _workingDirectory;
|
QString _workingDirectory;
|
||||||
QNetworkAccessManager* _manager;
|
QNetworkAccessManager* _manager;
|
||||||
QMap<QString, QString> defaultHeaders;
|
QMap<QString, QString> _defaultHeaders;
|
||||||
bool isResponseCompressionEnabled;
|
bool _isResponseCompressionEnabled;
|
||||||
bool isRequestCompressionEnabled;
|
bool _isRequestCompressionEnabled;
|
||||||
|
|
||||||
void createUserCallback(PFXHttpRequestWorker *worker);
|
void createUserCallback(PFXHttpRequestWorker *worker);
|
||||||
void createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker);
|
void createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user