Revision control

/**
* OpenAPI Generated Petstore Client
*
* This is a sample of Petstore application.
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "userapi.h"
#include "qoaiserverconfiguration.h"
#include <QtCore/qanystringview.h>
#include <QtCore/qflags.h>
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#include <QtNetwork/qhttpmultipart.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qnetworkrequestfactory.h>
#include <QtNetwork/qrestaccessmanager.h>
#include <string_view>
using namespace Qt::StringLiterals;
using namespace std::string_view_literals;
using namespace QtOpenApiCommon;
namespace QtOpenAPI {
UserApi::UserApi(QObject *parent)
: QOAIBaseApi(parent)
{
initializeServerConfigs();
}
UserApi::~UserApi()
{
}
void UserApi::initializeServerConfigs()
{
//Default server
QList<QOAIServerConfiguration> defaultConf = QList<QOAIServerConfiguration>();
//varying endpoint server
defaultConf.append(QOAIServerConfiguration(
u"No description provided"_s,
QMap<QString, QOAIServerVariable>()));
{
setServersForOperation(u"createInQueryMap"_s, defaultConf);
}
{
setServersForOperation(u"createUser"_s, defaultConf);
}
{
setServersForOperation(u"createUsersWithArrayInput"_s, defaultConf);
}
{
setServersForOperation(u"createUsersWithListInput"_s, defaultConf);
}
{
setServersForOperation(u"deleteUser"_s, defaultConf);
}
{
setServersForOperation(u"getUserByName"_s, defaultConf);
}
{
setServersForOperation(u"loginUser"_s, defaultConf);
}
{
setServersForOperation(u"logoutUser"_s, defaultConf);
}
{
setServersForOperation(u"updateUser"_s, defaultConf);
}
}
/**
* \fn void UserApi::createInQueryMap(const QMap<QString, QString> &username)
* 'createInQueryMap' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username QMap<QString, QString> [required]
*/
/**
* \fn template < Functor, > void UserApi::createInQueryMap(const QMap<QString, QString> &username, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'createInQueryMap' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* createInQueryMap(username, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username QMap<QString, QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::createInQueryMapCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by createInQueryMapFinished() or
* being returned as a callback parameter of createInQueryMap() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::createInQueryMapWithDataImpl(const QMap<QString, QString> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createInQueryMap() operation request.
* @param[in] username QMap<QString, QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::createInQueryMapWithDataImpl(const QMap<QString, QString> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"createInQueryMap"_s);
QString fullPath = u"/user/createInQueryMap"_s;
int queryParamCounter = 0;
{
[[maybe_unused]] QString paramString;
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || true);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, true);
SerializationOptions opts;
opts.style = "form"sv.empty() ? "form" : "form";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
paramString = opts.suffix;
if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append(u'&');
if (opts.style == "deepObject") {
qsizetype index = 0;
if (username.isEmpty())
qWarning() << "Map is empty!";
for (const auto &[key, value] : username.asKeyValueRange()) {
if (index > 0)
paramString.append(opts.delimiter);
paramString.append(opts.suffix + QUrl::toPercentEncoding(u"[%1]"_s.arg(key)) + opts.assignOperator + QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(value)));
index++;
}
} else {
paramString.append(serializeMapValue(username, opts));
}
fullPath.append(paramString);
queryParamCounter++;
}
}
QOAIHttpRequestInput input(fullPath, "POST"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
createInQueryMapCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit createInQueryMapErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::createInQueryMapCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createInQueryMapFinished();
}
/**
* \fn void UserApi::createUser(const User &user)
* 'createUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] user User [required]
*/
/**
* \fn template < Functor, > void UserApi::createUser(const User &user, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'createUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* createUser(user, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] user User [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::createUserCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by createUserFinished() or
* being returned as a callback parameter of createUser() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::createUserWithDataImpl(const User &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUser() operation request.
* @param[in] user User [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::createUserWithDataImpl(const User &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"createUser"_s);
QString fullPath = u"/user"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
QOAIHttpRequestInput input(fullPath, "POST"_L1);
input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
const QByteArray output = user.asJson().toUtf8();
input.setRequestBody(output);
}
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
createUserCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit createUserErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::createUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUserFinished();
}
/**
* \fn void UserApi::createUsersWithArrayInput(const QList<User> &user)
* 'createUsersWithArrayInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] user QList<User> [required]
*/
/**
* \fn template < Functor, > void UserApi::createUsersWithArrayInput(const QList<User> &user, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'createUsersWithArrayInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* createUsersWithArrayInput(user, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] user QList<User> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::createUsersWithArrayInputCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by createUsersWithArrayInputFinished() or
* being returned as a callback parameter of createUsersWithArrayInput() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::createUsersWithArrayInputWithDataImpl(const QList<User> &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUsersWithArrayInput() operation request.
* @param[in] user QList<User> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::createUsersWithArrayInputWithDataImpl(const QList<User> &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"createUsersWithArrayInput"_s);
QString fullPath = u"/user/createWithArray"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
QOAIHttpRequestInput input(fullPath, "POST"_L1);
input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QJsonDocument doc(::QtOpenApiCommon::toJsonValue(user).toArray());
QByteArray bytes = doc.toJson(QJsonDocument::Compact);
input.setRequestBody(bytes);
}
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
createUsersWithArrayInputCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit createUsersWithArrayInputErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::createUsersWithArrayInputCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUsersWithArrayInputFinished();
}
/**
* \fn void UserApi::createUsersWithListInput(const QList<User> &user)
* 'createUsersWithListInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] user QList<User> [required]
*/
/**
* \fn template < Functor, > void UserApi::createUsersWithListInput(const QList<User> &user, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'createUsersWithListInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* createUsersWithListInput(user, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] user QList<User> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::createUsersWithListInputCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by createUsersWithListInputFinished() or
* being returned as a callback parameter of createUsersWithListInput() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::createUsersWithListInputWithDataImpl(const QList<User> &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUsersWithListInput() operation request.
* @param[in] user QList<User> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::createUsersWithListInputWithDataImpl(const QList<User> &user, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"createUsersWithListInput"_s);
QString fullPath = u"/user/createWithList"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
QOAIHttpRequestInput input(fullPath, "POST"_L1);
input.headers().replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QJsonDocument doc(::QtOpenApiCommon::toJsonValue(user).toArray());
QByteArray bytes = doc.toJson(QJsonDocument::Compact);
input.setRequestBody(bytes);
}
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
createUsersWithListInputCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit createUsersWithListInputErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::createUsersWithListInputCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUsersWithListInputFinished();
}
/**
* \fn void UserApi::deleteUser(const User &username)
* 'deleteUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username User [required]
*/
/**
* \fn template < Functor, > void UserApi::deleteUser(const User &username, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'deleteUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* deleteUser(username, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username User [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::deleteUserCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by deleteUserFinished() or
* being returned as a callback parameter of deleteUser() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::deleteUserWithDataImpl(const User &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the deleteUser() operation request.
* @param[in] username User [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::deleteUserWithDataImpl(const User &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"deleteUser"_s);
QString fullPath = u"/user/{username}"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
{
QString usernamePathParam = u"{%1}"_s.arg(u"username"_s);
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, true || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"sv.empty() ? "simple" : "simple";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString = opts.prefix + serializeJsonValue(username.asJsonValue(), opts);
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
paramString.chop(1);
fullPath.replace(usernamePathParam, paramString);
}
QOAIHttpRequestInput input(fullPath, "DELETE"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
deleteUserCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit deleteUserErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::deleteUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit deleteUserFinished();
}
/**
* \fn void UserApi::getUserByName(const QMap<QString, qint32> &username)
* 'getUserByName' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username QMap<QString, qint32> [required]
*/
/**
* \fn template < Functor, > void UserApi::getUserByName(const QMap<QString, qint32> &username, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getUserByName' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* getUserByName(username, this, [&](const QRestReply &reply, const User &summary) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username QMap<QString, qint32> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::getUserByNameCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getUserByNameFinished() or
* being returned as a callback parameter of getUserByName() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::getUserByNameWithDataImpl(const QMap<QString, qint32> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getUserByName() operation request.
* @param[in] username QMap<QString, qint32> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::getUserByNameWithDataImpl(const QMap<QString, qint32> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"getUserByName"_s);
QString fullPath = u"/user/{username}"_s;
{
QString usernamePathParam = u"{%1}"_s.arg(u"username"_s);
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || true);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"sv.empty() ? "simple" : "simple";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString.append(serializeMapValue(username, opts));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
paramString.chop(1);
fullPath.replace(usernamePathParam, paramString);
}
QOAIHttpRequestInput input(fullPath, "GET"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
getUserByNameCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getUserByNameErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
User empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::getUserByNameCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
- const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
+ QOAIHttpResponseParseParameters responseData;
+ responseData.m_fileConflictPolicy = fileConflictPolicy();
+ responseData.m_safetyThresholdSize = decompressedSafetyCheckThreshold();
+ const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory(), responseData);
User output(response);
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit getUserByNameFinished(output);
}
/**
* \fn void UserApi::loginUser(const QtOpenApiCommon::OptionalParameter<QString> &username = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QString> &password = QtOpenApiCommon::OptionalParameter<QString>())
* 'loginUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username QString [optional]
* @param[in] password QString [optional]
*/
/**
* \fn template < Functor, > void UserApi::loginUser(const QtOpenApiCommon::OptionalParameter<QString> &username = QtOpenApiCommon::OptionalParameter<QString>(), const QtOpenApiCommon::OptionalParameter<QString> &password = QtOpenApiCommon::OptionalParameter<QString>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'loginUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* loginUser(username, password, this, [&](const QRestReply &reply, const QString &summary) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username QString [optional]
* @param[in] password QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::loginUserCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by loginUserFinished() or
* being returned as a callback parameter of loginUser() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::loginUserWithDataImpl(const QtOpenApiCommon::OptionalParameter<QString> &username, const QtOpenApiCommon::OptionalParameter<QString> &password, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the loginUser() operation request.
* @param[in] username QString [optional]
* @param[in] password QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::loginUserWithDataImpl(const QtOpenApiCommon::OptionalParameter<QString> &username, const QtOpenApiCommon::OptionalParameter<QString> &password, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"loginUser"_s);
QString fullPath = u"/user/login"_s;
int queryParamCounter = 0;
{
[[maybe_unused]] QString paramString;
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, true);
SerializationOptions opts;
opts.style = "form"sv.empty() ? "form" : "form";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
paramString = opts.suffix;
if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
if (username.hasValue()) {
if (queryParamCounter > 0)
fullPath.append(u'&');
fullPath.append(opts.suffix + QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(username.value())));
queryParamCounter++;
} else if (username.isNull()) {
if (queryParamCounter > 0)
fullPath.append(u'&');
// style=form && explode=true && non-object => 'username' isn't used in serialization
// style=form && explode=true && empty object => need to be 'username='
if (opts.style == "form")
fullPath.append(u"username="_s);
else
fullPath.append(opts.suffix);
queryParamCounter++;
}
}
{
[[maybe_unused]] QString paramString;
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, true);
SerializationOptions opts;
opts.style = "form"sv.empty() ? "form" : "form";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"password"_s), flags);
opts.flags = flags;
paramString = opts.suffix;
if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
if (password.hasValue()) {
if (queryParamCounter > 0)
fullPath.append(u'&');
fullPath.append(opts.suffix + QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(password.value())));
queryParamCounter++;
} else if (password.isNull()) {
if (queryParamCounter > 0)
fullPath.append(u'&');
// style=form && explode=true && non-object => 'password' isn't used in serialization
// style=form && explode=true && empty object => need to be 'password='
if (opts.style == "form")
fullPath.append(u"password="_s);
else
fullPath.append(opts.suffix);
queryParamCounter++;
}
}
QOAIHttpRequestInput input(fullPath, "GET"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
loginUserCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit loginUserErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QString empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::loginUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
- const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
+ QOAIHttpResponseParseParameters responseData;
+ responseData.m_fileConflictPolicy = fileConflictPolicy();
+ responseData.m_safetyThresholdSize = decompressedSafetyCheckThreshold();
+ const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory(), responseData);
QString output;
const bool ok = ::QtOpenApiCommon::fromByteArray(response, output);
if (!ok)
qWarning("%s: Failed to convert the response to QString.", Q_FUNC_INFO);
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit loginUserFinished(output);
}
/**
* \fn void UserApi::logoutUser(const QJsonValue &username)
* 'logoutUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username QJsonValue [required]
*/
/**
* \fn template < Functor, > void UserApi::logoutUser(const QJsonValue &username, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'logoutUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* logoutUser(username, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username QJsonValue [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::logoutUserCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by logoutUserFinished() or
* being returned as a callback parameter of logoutUser() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::logoutUserWithDataImpl(const QJsonValue &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the logoutUser() operation request.
* @param[in] username QJsonValue [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::logoutUserWithDataImpl(const QJsonValue &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"logoutUser"_s);
QString fullPath = u"/user/logout"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
int queryParamCounter = 0;
{
[[maybe_unused]] QString paramString;
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, username.type() == QJsonValue::Object);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, true);
SerializationOptions opts;
opts.style = "form"sv.empty() ? "form" : "form";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append(u'&');
const QJsonValue::Type paramType = username.type();
if (paramType != QJsonValue::Object) {
if (opts.style == "deepObject") {
qWarning("Be aware that 'deepObject' style is only valid for parameters of "
"type 'object'. The generated result will not conform to the OpenAPI "
"standard.");
} else if (paramType != QJsonValue::Array
&& (opts.style == "pipeDelimited"
|| opts.style == "spaceDelimited")) {
qWarning("Be aware that '%s' style is invalid for primitive parameters. "
"The generated result will not conform to the OpenAPI standard.",
opts.style.c_str());
}
}
paramString = serializeJsonValue(username, opts);
fullPath.append(paramString);
queryParamCounter++;
}
}
QOAIHttpRequestInput input(fullPath, "GET"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
logoutUserCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit logoutUserErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::logoutUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit logoutUserFinished();
}
/**
* \fn void UserApi::updateUser(const QString &username, const User &body)
* 'updateUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username QString [required]
* @param[in] body User [required]
*/
/**
* \fn template < Functor, > void UserApi::updateUser(const QString &username, const User &body, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'updateUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
*
* \attention Use the operation with following parameters in the callback:
* \code {c++}
* updateUser(username, body, this, [&](const QRestReply &reply, const User &summary) { if (reply.isSuccess()) ... });
* \endcode
* @param[in] username QString [required]
* @param[in] body User [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void UserApi::updateUserCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by updateUserFinished() or
* being returned as a callback parameter of updateUser() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn void UserApi::updateUserWithDataImpl(const QString &username, const User &body, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updateUser() operation request.
* @param[in] username QString [required]
* @param[in] body User [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void UserApi::updateUserWithDataImpl(const QString &username, const User &body, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
QtPrivate::SlotObjUniquePtr slotPtr(slot);
setBaseServerUrl(u"updateUser"_s);
QString fullPath = u"/user/{username}"_s;
if (const auto key = apiKey("api_key"_L1); key.has_value()) {
setHeader("api_key"_L1, *key);
}
{
QString usernamePathParam = u"{%1}"_s.arg(u"username"_s);
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"sv.empty() ? "simple" : "simple";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"username"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenApiCommon::toStringValue(username));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
if ((paramString == opts.prefix + opts.suffix) && opts.style == "matrix")
paramString.chop(1);
fullPath.replace(usernamePathParam, paramString);
}
int queryParamCounter = 0;
{
[[maybe_unused]] QString paramString;
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, true || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, true);
SerializationOptions opts;
opts.style = "form"sv.empty() ? "form" : "form";
opts.prefix = getParamStylePrefix(opts.style);
opts.delimiter = getParamStyleDelimiter(opts.style, flags);
opts.assignOperator = getParamStyleAssignOperator(opts.style, flags);
opts.suffix = getParamStyleSuffix(opts.style, QUrl::toPercentEncoding(u"body"_s), flags);
opts.flags = flags;
paramString = opts.suffix;
if ((fullPath.indexOf(u'?') != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append(u'&');
paramString = serializeJsonValue(body.asJsonValue(), opts);
// style=form && explode=true && non-object => 'body' isn't used in serialization
// style=form && explode=true && empty object => need to be 'body='
if (paramString.isEmpty() && opts.style == "form")
paramString = u"body="_s;
fullPath.append(paramString);
queryParamCounter++;
}
}
QOAIHttpRequestInput input(fullPath, "PUT"_L1);
QByteArray requestContent;
QNetworkRequest request
= QOAIHttpRequestWorker::getNetworkRequest(input, requestContent,
networkRequestFactory(),
responseCompressionEnabled(),
requestCompressionEnabled());
QNetworkReply *reply = execute(input, request, requestContent);
if (reply != nullptr) {
reply->setParent(this);
setCallerInfo(reply, QOAICallerInfo{context, QtPrivate::SlotObjSharedPtr(std::move(slotPtr))});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
updateUserCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit updateUserErrorOccurred(reply->error(), reply->errorString());
QOAICallerInfo callerInfo = takeCallerInfo(reply);
if (callerInfo.slot) {
User empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void UserApi::updateUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
- const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory());
+ QOAIHttpResponseParseParameters responseData;
+ responseData.m_fileConflictPolicy = fileConflictPolicy();
+ responseData.m_safetyThresholdSize = decompressedSafetyCheckThreshold();
+ const QByteArray response = QOAIHttpRequestWorker::parseResponse(reply, workingDirectory(), responseData);
User output(response);
// Check if callback is provided
QOAICallerInfo callerInfo = takeCallerInfo(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject.get()) : nullptr;
callerInfo.slot->call(context, argv);
}
emit updateUserFinished(output);
}
} // namespace QtOpenAPI