Revision control

Copy as Markdown

/**
* OpenAPI Petstore
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "OAIUserApi.h"
#include "OAIServerConfiguration.h"
#include <QtCore/qanystringview.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>
using namespace Qt::StringLiterals;
namespace OpenAPI {
OAIUserApi::OAIUserApi(QObject *parent)
: OAIBaseApi(parent)
{
initializeServerConfigs();
}
OAIUserApi::~OAIUserApi()
{
}
void OAIUserApi::initializeServerConfigs()
{
//Default server
QList<OAIServerConfiguration> defaultConf = QList<OAIServerConfiguration>();
//varying endpoint server
defaultConf.append(OAIServerConfiguration(
"No description provided",
QMap<QString, OAIServerVariable>()));
m_serverConfigs.insert("createInQueryMap", defaultConf);
m_serverIndices.insert("createInQueryMap", 0);
m_serverConfigs.insert("createUser", defaultConf);
m_serverIndices.insert("createUser", 0);
m_serverConfigs.insert("createUsersWithArrayInput", defaultConf);
m_serverIndices.insert("createUsersWithArrayInput", 0);
m_serverConfigs.insert("createUsersWithListInput", defaultConf);
m_serverIndices.insert("createUsersWithListInput", 0);
m_serverConfigs.insert("deleteUser", defaultConf);
m_serverIndices.insert("deleteUser", 0);
m_serverConfigs.insert("getUserByName", defaultConf);
m_serverIndices.insert("getUserByName", 0);
m_serverConfigs.insert("loginUser", defaultConf);
m_serverIndices.insert("loginUser", 0);
m_serverConfigs.insert("logoutUser", defaultConf);
m_serverIndices.insert("logoutUser", 0);
m_serverConfigs.insert("updateUser", defaultConf);
m_serverIndices.insert("updateUser", 0);
}
/**
* \fn virtual void OAIUserApi::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 OAIUserApi::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
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual createInQueryMapWithDataImpl() in derived class.
* The virtual createInQueryMapWithDataImpl() is being called by the template
* function.
* @param[in] username QMap<QString, QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::createInQueryMapWithDataImpl(const QMap<QString, QString> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createInQueryMap() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking createInQueryMap() operation calls.
* @param[in] username QMap<QString, QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::createInQueryMapWithDataImpl(const QMap<QString, QString> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["createInQueryMap"][m_serverIndices.value("createInQueryMap")].serverUrl();
QString fullPath = "/user/createInQueryMap";
m_networkFactory->setBaseUrl(serverUrl);
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"_L1.isEmpty() ? "form"_L1 : "form"_L1;
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("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
if (opts.style == "deepObject"_L1) {
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(::OpenAPI::toStringValue(value)));
index++;
}
} else {
paramString.append(serializeMapValue(username, opts));
}
fullPath.append(paramString);
queryParamCounter++;
}
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::createInQueryMapCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createInQueryMapFinished();
}
/**
* \fn virtual void OAIUserApi::createUser(const OAIUser &oAIUser)
* 'createUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIUser OAIUser [required]
*/
/**
* \fn template < Functor, > void OAIUserApi::createUser(const OAIUser &oAIUser, 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(oAIUser, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual createUserWithDataImpl() in derived class.
* The virtual createUserWithDataImpl() is being called by the template
* function.
* @param[in] oAIUser OAIUser [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::createUserWithDataImpl(const OAIUser &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUser() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking createUser() operation calls.
* @param[in] oAIUser OAIUser [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::createUserWithDataImpl(const OAIUser &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["createUser"][m_serverIndices.value("createUser")].serverUrl();
QString fullPath = "/user";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QByteArray output = oAIUser.asJson().toUtf8();
input.m_requestBody.append(output);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::createUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUserFinished();
}
/**
* \fn virtual void OAIUserApi::createUsersWithArrayInput(const QList<OAIUser> &oAIUser)
* 'createUsersWithArrayInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIUser QList<OAIUser> [required]
*/
/**
* \fn template < Functor, > void OAIUserApi::createUsersWithArrayInput(const QList<OAIUser> &oAIUser, 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(oAIUser, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual createUsersWithArrayInputWithDataImpl() in derived class.
* The virtual createUsersWithArrayInputWithDataImpl() is being called by the template
* function.
* @param[in] oAIUser QList<OAIUser> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::createUsersWithArrayInputWithDataImpl(const QList<OAIUser> &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUsersWithArrayInput() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking createUsersWithArrayInput() operation calls.
* @param[in] oAIUser QList<OAIUser> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::createUsersWithArrayInputWithDataImpl(const QList<OAIUser> &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["createUsersWithArrayInput"][m_serverIndices.value("createUsersWithArrayInput")].serverUrl();
QString fullPath = "/user/createWithArray";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QJsonDocument doc(::OpenAPI::toJsonValue(oAIUser).toArray());
QByteArray bytes = doc.toJson(QJsonDocument::Compact);
input.m_requestBody.append(bytes);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::createUsersWithArrayInputCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUsersWithArrayInputFinished();
}
/**
* \fn virtual void OAIUserApi::createUsersWithListInput(const QList<OAIUser> &oAIUser)
* 'createUsersWithListInput' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIUser QList<OAIUser> [required]
*/
/**
* \fn template < Functor, > void OAIUserApi::createUsersWithListInput(const QList<OAIUser> &oAIUser, 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(oAIUser, this, [&](const QRestReply &reply) { if (reply.isSuccess()) ... });
* \endcode
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual createUsersWithListInputWithDataImpl() in derived class.
* The virtual createUsersWithListInputWithDataImpl() is being called by the template
* function.
* @param[in] oAIUser QList<OAIUser> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::createUsersWithListInputWithDataImpl(const QList<OAIUser> &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the createUsersWithListInput() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking createUsersWithListInput() operation calls.
* @param[in] oAIUser QList<OAIUser> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::createUsersWithListInputWithDataImpl(const QList<OAIUser> &oAIUser, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["createUsersWithListInput"][m_serverIndices.value("createUsersWithListInput")].serverUrl();
QString fullPath = "/user/createWithList";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QJsonDocument doc(::OpenAPI::toJsonValue(oAIUser).toArray());
QByteArray bytes = doc.toJson(QJsonDocument::Compact);
input.m_requestBody.append(bytes);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::createUsersWithListInputCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit createUsersWithListInputFinished();
}
/**
* \fn virtual void OAIUserApi::deleteUser(const OAIUser &username)
* 'deleteUser' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] username OAIUser [required]
*/
/**
* \fn template < Functor, > void OAIUserApi::deleteUser(const OAIUser &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
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual deleteUserWithDataImpl() in derived class.
* The virtual deleteUserWithDataImpl() is being called by the template
* function.
* @param[in] username OAIUser [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::deleteUserWithDataImpl(const OAIUser &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the deleteUser() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking deleteUser() operation calls.
* @param[in] username OAIUser [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::deleteUserWithDataImpl(const OAIUser &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["deleteUser"][m_serverIndices.value("deleteUser")].serverUrl();
QString fullPath = "/user/{username}";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
{
QString usernamePathParam = QString("{%1}").arg("username");
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, true || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"_L1.isEmpty() ? "simple"_L1 : "simple"_L1;
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(QJsonValue(username.asJsonObject()), 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) && QString("simple") == "matrix"_L1)
paramString.chop(1);
fullPath.replace(usernamePathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "DELETE");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::deleteUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit deleteUserFinished();
}
/**
* \fn virtual void OAIUserApi::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 OAIUserApi::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 OAIUser &summary) { if (reply.isSuccess()) ... });
* \endcode
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual getUserByNameWithDataImpl() in derived class.
* The virtual getUserByNameWithDataImpl() is being called by the template
* function.
* @param[in] username QMap<QString, qint32> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::getUserByNameWithDataImpl(const QMap<QString, qint32> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getUserByName() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking getUserByName() operation calls.
* @param[in] username QMap<QString, qint32> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::getUserByNameWithDataImpl(const QMap<QString, qint32> &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["getUserByName"][m_serverIndices.value("getUserByName")].serverUrl();
QString fullPath = "/user/{username}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString usernamePathParam = QString("{%1}").arg("username");
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || true);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"_L1.isEmpty() ? "simple"_L1 : "simple"_L1;
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) && QString("simple") == "matrix"_L1)
paramString.chop(1);
fullPath.replace(usernamePathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIUser empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::getUserByNameCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIUser output(response);
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit getUserByNameFinished(output);
}
/**
* \fn virtual void OAIUserApi::loginUser(const ::OpenAPI::OptionalParam<QString> &username = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<QString> &password = ::OpenAPI::OptionalParam<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 OAIUserApi::loginUser(const ::OpenAPI::OptionalParam<QString> &username = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<QString> &password = ::OpenAPI::OptionalParam<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
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual loginUserWithDataImpl() in derived class.
* The virtual loginUserWithDataImpl() is being called by the template
* function.
* @param[in] username QString [optional]
* @param[in] password QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::loginUserWithDataImpl(const ::OpenAPI::OptionalParam<QString> &username, const ::OpenAPI::OptionalParam<QString> &password, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the loginUser() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking loginUser() operation calls.
* @param[in] username QString [optional]
* @param[in] password QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::loginUserWithDataImpl(const ::OpenAPI::OptionalParam<QString> &username, const ::OpenAPI::OptionalParam<QString> &password, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["loginUser"][m_serverIndices.value("loginUser")].serverUrl();
QString fullPath = "/user/login";
m_networkFactory->setBaseUrl(serverUrl);
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"_L1.isEmpty() ? "form"_L1 : "form"_L1;
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("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
if (username.hasValue()) {
if (queryParamCounter > 0)
fullPath.append("&");
fullPath.append(opts.suffix + QUrl::toPercentEncoding(::OpenAPI::toStringValue(username.value())));
queryParamCounter++;
} else if (username.isNull()) {
if (queryParamCounter > 0)
fullPath.append("&");
// 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"_L1.isEmpty() ? "form"_L1 : "form"_L1;
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("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
if (password.hasValue()) {
if (queryParamCounter > 0)
fullPath.append("&");
fullPath.append(opts.suffix + QUrl::toPercentEncoding(::OpenAPI::toStringValue(password.value())));
queryParamCounter++;
} else if (password.isNull()) {
if (queryParamCounter > 0)
fullPath.append("&");
// 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++;
}
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QString empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::loginUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QString output;
const bool ok = ::OpenAPI::fromByteArray(response, output);
if (!ok)
qWarning("%s: Failed to convert the response to QString.", Q_FUNC_INFO);
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit loginUserFinished(output);
}
/**
* \fn virtual void OAIUserApi::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 OAIUserApi::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
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual logoutUserWithDataImpl() in derived class.
* The virtual logoutUserWithDataImpl() is being called by the template
* function.
* @param[in] username QJsonValue [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::logoutUserWithDataImpl(const QJsonValue &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the logoutUser() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking logoutUser() operation calls.
* @param[in] username QJsonValue [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::logoutUserWithDataImpl(const QJsonValue &username, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["logoutUser"][m_serverIndices.value("logoutUser")].serverUrl();
QString fullPath = "/user/logout";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
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"_L1.isEmpty() ? "form"_L1 : "form"_L1;
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("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
const QJsonValue::Type paramType = username.type();
if (paramType != QJsonValue::Object) {
if (opts.style == "deepObject"_L1) {
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"_L1
|| opts.style == "spaceDelimited"_L1)) {
qWarning("Be aware that '%s' style is invalid for primitive parameters. "
"The generated result will not conform to the OpenAPI standard.",
qPrintable(opts.style));
}
}
paramString = serializeJsonValue(username, opts);
fullPath.append(paramString);
queryParamCounter++;
}
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::logoutUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit logoutUserFinished();
}
/**
* \fn virtual void OAIUserApi::updateUser(const QString &username, const OAIUser &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 OAIUser [required]
*/
/**
* \fn template < Functor, > void OAIUserApi::updateUser(const QString &username, const OAIUser &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 OAIUser &summary) { if (reply.isSuccess()) ... });
* \endcode
* \note The template function can not be virtual in C++17.
* If you want to use 'makeOperationsVirtual' option for mocking API,
* please override virtual updateUserWithDataImpl() in derived class.
* The virtual updateUserWithDataImpl() is being called by the template
* function.
* @param[in] username QString [required]
* @param[in] body OAIUser [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIUserApi::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 virtual void OAIUserApi::updateUserWithDataImpl(const QString &username, const OAIUser &body, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updateUser() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking updateUser() operation calls.
* @param[in] username QString [required]
* @param[in] body OAIUser [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIUserApi::updateUserWithDataImpl(const QString &username, const OAIUser &body, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["updateUser"][m_serverIndices.value("updateUser")].serverUrl();
QString fullPath = "/user/{username}";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, m_apiKeys.find("api_key"_L1).value());
}
{
QString usernamePathParam = QString("{%1}").arg("username");
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, true);
flags.setFlag(SerializationFlag::Explode, false);
SerializationOptions opts;
opts.style = "simple"_L1.isEmpty() ? "simple"_L1 : "simple"_L1;
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(::OpenAPI::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) && QString("simple") == "matrix"_L1)
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"_L1.isEmpty() ? "form"_L1 : "form"_L1;
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("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
const QJsonObject parameter = body.asJsonObject();
paramString = serializeJsonValue(QJsonValue(parameter), 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++;
}
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "PUT");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
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());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIUser empty;
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl, &empty };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIUserApi::updateUserCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIUser output(response);
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply), &output };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit updateUserFinished(output);
}
} // namespace OpenAPI