mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-25 11:00:52 +00:00
* HttpFileElement * HttpRequest * Add .clang-format * cpp-qt5-client: fix warning reordering member initialization * api * enum * licenseInfo * model * object * helper * test * QString::arg start from %1 (not from %0) * fixup! model
425 lines
15 KiB
C++
425 lines
15 KiB
C++
/**
|
|
* OpenAPI Petstore
|
|
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
|
*
|
|
* The version of the OpenAPI document: 1.0.0
|
|
*
|
|
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
|
|
* https://openapi-generator.tech
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
#include "PFXUserApi.h"
|
|
#include "PFXHelpers.h"
|
|
|
|
#include <QJsonArray>
|
|
#include <QJsonDocument>
|
|
|
|
namespace test_namespace {
|
|
|
|
PFXUserApi::PFXUserApi(const QString &scheme, const QString &host, int port, const QString &basePath, const int timeOut)
|
|
: _scheme(scheme),
|
|
_host(host),
|
|
_port(port),
|
|
_basePath(basePath),
|
|
_timeOut(timeOut) {}
|
|
|
|
PFXUserApi::~PFXUserApi() {
|
|
}
|
|
|
|
void PFXUserApi::setScheme(const QString &scheme) {
|
|
_scheme = scheme;
|
|
}
|
|
|
|
void PFXUserApi::setHost(const QString &host) {
|
|
_host = host;
|
|
}
|
|
|
|
void PFXUserApi::setPort(int port) {
|
|
_port = port;
|
|
}
|
|
|
|
void PFXUserApi::setBasePath(const QString &basePath) {
|
|
_basePath = basePath;
|
|
}
|
|
|
|
void PFXUserApi::setTimeOut(const int timeOut) {
|
|
_timeOut = timeOut;
|
|
}
|
|
|
|
void PFXUserApi::setWorkingDirectory(const QString &path) {
|
|
_workingDirectory = path;
|
|
}
|
|
|
|
void PFXUserApi::addHeaders(const QString &key, const QString &value) {
|
|
defaultHeaders.insert(key, value);
|
|
}
|
|
|
|
void PFXUserApi::createUser(const PFXUser &body) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user");
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "POST");
|
|
|
|
QString output = body.asJson();
|
|
input.request_body.append(output);
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUserCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::createUserCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit createUserSignal();
|
|
emit createUserSignalFull(worker);
|
|
} else {
|
|
emit createUserSignalE(error_type, error_str);
|
|
emit createUserSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::createUsersWithArrayInput(const QList<PFXUser> &body) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/createWithArray");
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "POST");
|
|
|
|
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
|
|
QByteArray bytes = doc.toJson();
|
|
input.request_body.append(bytes);
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithArrayInputCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit createUsersWithArrayInputSignal();
|
|
emit createUsersWithArrayInputSignalFull(worker);
|
|
} else {
|
|
emit createUsersWithArrayInputSignalE(error_type, error_str);
|
|
emit createUsersWithArrayInputSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::createUsersWithListInput(const QList<PFXUser> &body) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/createWithList");
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "POST");
|
|
|
|
QJsonDocument doc(::test_namespace::toJsonValue(body).toArray());
|
|
QByteArray bytes = doc.toJson();
|
|
input.request_body.append(bytes);
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::createUsersWithListInputCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit createUsersWithListInputSignal();
|
|
emit createUsersWithListInputSignalFull(worker);
|
|
} else {
|
|
emit createUsersWithListInputSignalE(error_type, error_str);
|
|
emit createUsersWithListInputSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::deleteUser(const QString &username) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/{username}");
|
|
QString usernamePathParam("{");
|
|
usernamePathParam.append("username").append("}");
|
|
fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "DELETE");
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::deleteUserCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::deleteUserCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit deleteUserSignal();
|
|
emit deleteUserSignalFull(worker);
|
|
} else {
|
|
emit deleteUserSignalE(error_type, error_str);
|
|
emit deleteUserSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::getUserByName(const QString &username) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/{username}");
|
|
QString usernamePathParam("{");
|
|
usernamePathParam.append("username").append("}");
|
|
fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "GET");
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::getUserByNameCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
PFXUser output(QString(worker->response));
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit getUserByNameSignal(output);
|
|
emit getUserByNameSignalFull(worker, output);
|
|
} else {
|
|
emit getUserByNameSignalE(output, error_type, error_str);
|
|
emit getUserByNameSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::loginUser(const QString &username, const QString &password) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/login");
|
|
|
|
if (fullPath.indexOf("?") > 0)
|
|
fullPath.append("&");
|
|
else
|
|
fullPath.append("?");
|
|
fullPath.append(QUrl::toPercentEncoding("username")).append("=").append(QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
|
|
|
|
if (fullPath.indexOf("?") > 0)
|
|
fullPath.append("&");
|
|
else
|
|
fullPath.append("?");
|
|
fullPath.append(QUrl::toPercentEncoding("password")).append("=").append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password)));
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "GET");
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::loginUserCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::loginUserCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
QString output;
|
|
::test_namespace::fromStringValue(QString(worker->response), output);
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit loginUserSignal(output);
|
|
emit loginUserSignalFull(worker, output);
|
|
} else {
|
|
emit loginUserSignalE(output, error_type, error_str);
|
|
emit loginUserSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::logoutUser() {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/logout");
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "GET");
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::logoutUserCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::logoutUserCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit logoutUserSignal();
|
|
emit logoutUserSignalFull(worker);
|
|
} else {
|
|
emit logoutUserSignalE(error_type, error_str);
|
|
emit logoutUserSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
void PFXUserApi::updateUser(const QString &username, const PFXUser &body) {
|
|
QString fullPath = QString("%1://%2%3%4%5")
|
|
.arg(_scheme)
|
|
.arg(_host)
|
|
.arg(_port ? ":" + QString::number(_port) : "")
|
|
.arg(_basePath)
|
|
.arg("/user/{username}");
|
|
QString usernamePathParam("{");
|
|
usernamePathParam.append("username").append("}");
|
|
fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username)));
|
|
|
|
PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this);
|
|
worker->setTimeOut(_timeOut);
|
|
worker->setWorkingDirectory(_workingDirectory);
|
|
PFXHttpRequestInput input(fullPath, "PUT");
|
|
|
|
QString output = body.asJson();
|
|
input.request_body.append(output);
|
|
|
|
foreach (QString key, this->defaultHeaders.keys()) { input.headers.insert(key, this->defaultHeaders.value(key)); }
|
|
|
|
connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXUserApi::updateUserCallback);
|
|
|
|
worker->execute(&input);
|
|
}
|
|
|
|
void PFXUserApi::updateUserCallback(PFXHttpRequestWorker *worker) {
|
|
QString msg;
|
|
QString error_str = worker->error_str;
|
|
QNetworkReply::NetworkError error_type = worker->error_type;
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
|
} else {
|
|
msg = "Error: " + worker->error_str;
|
|
}
|
|
worker->deleteLater();
|
|
|
|
if (worker->error_type == QNetworkReply::NoError) {
|
|
emit updateUserSignal();
|
|
emit updateUserSignalFull(worker);
|
|
} else {
|
|
emit updateUserSignalE(error_type, error_str);
|
|
emit updateUserSignalEFull(worker, error_type, error_str);
|
|
}
|
|
}
|
|
|
|
} // namespace test_namespace
|