Revision control

- /**
- * Qt Quick Demo - RESTful API client
- *
- * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
- * https://openapi-generator.tech
- * Do not edit the class manually.
- */
-
- #include "OAIUsersApi.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 {
-
- OAIUsersApi::OAIUsersApi(QObject *parent)
- : OAIBaseApi(parent)
- {
- initializeServerConfigs();
- }
-
- OAIUsersApi::~OAIUsersApi()
- {
- }
-
- void OAIUsersApi::initializeServerConfigs()
- {
- //Default server
- QList<OAIServerConfiguration> defaultConf = QList<OAIServerConfiguration>();
- //varying endpoint server
- defaultConf.append(OAIServerConfiguration(
- QUrl("https://reqres.in/api"),
- "Public REST API test service",
- QMap<QString, OAIServerVariable>()));
- defaultConf.append(OAIServerConfiguration(
- QUrl("http://127.0.0.1:49425/api"),
- "Qt-based REST API server",
- QMap<QString, OAIServerVariable>()));
- m_serverConfigs.insert("getUserById", defaultConf);
- m_serverIndices.insert("getUserById", 0);
- m_serverConfigs.insert("getUsersByPage", defaultConf);
- m_serverIndices.insert("getUsersByPage", 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 OAIUsersApi::getUserById(const qint64 &id)
- * 'getUserById' operation sends the request to a server.
- * The request parameters are defined by a specification file.
-
- * @param[in] id qint64 [required]
- */
-
- /**
- * \fn template < Functor, > void OAIUsersApi::getUserById(const qint64 &id, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
- * 'getUserById' 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++}
- * getUserById(id, 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 getUserByIdWithDataImpl() in derived class.
- * The virtual getUserByIdWithDataImpl() is being called by the template
- * function.
-
- * @param[in] id qint64 [required]
- * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
- * @param[in] callback Functor && [optional]
- */
-
- /**
- * \fn void OAIUsersApi::getUserByIdCallback(const QRestReply &reply)
- * Processes a \a reply response from a server.
- * The result of processed data is emitted by getUserByIdFinished() or
- * being returned as a callback parameter of getUserById() request.
- * @param[in] reply const QRestReply &
- */
-
- /**
- * \fn virtual void OAIUsersApi::getUserByIdWithDataImpl(const qint64 &id, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- * Implements the getUserById() operation request.
- * \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
- * and can be overloaded for mocking getUserById() operation calls.
-
- * @param[in] id qint64 [required]
- * @param[in] context const QObject * [optional]
- * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
- */
- void OAIUsersApi::getUserByIdWithDataImpl(const qint64 &id, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- {
- const QUrl serverUrl = m_serverConfigs["getUserById"][m_serverIndices.value("getUserById")].serverUrl();
- QString fullPath = "/users/{id}";
- m_networkFactory->setBaseUrl(serverUrl);
- {
- QString idPathParam = QString("{%1}").arg("id");
-
- 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"id"_s), flags);
- opts.flags = flags;
- QString paramString = opts.prefix + opts.suffix;
- paramString += QUrl::toPercentEncoding(::OpenAPI::toStringValue(id));
- // In case style=matrix and paramString is empty due to any reasons,
- // we serialize it like undefined value and delete '='.
- // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
- if ((paramString == opts.prefix + opts.suffix) && QString("simple") == "matrix"_L1)
- paramString.chop(1);
- fullPath.replace(idPathParam, 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] {
- getUserByIdCallback(QRestReply(reply));
- });
- connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
- if (reply) {
- emit getUserByIdErrorOccurred(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 OAIUsersApi::getUserByIdCallback(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 getUserByIdFinished(output);
- }
-
- /**
- * \fn virtual void OAIUsersApi::getUsersByPage(const ::OpenAPI::OptionalParam<qint32> &page = ::OpenAPI::OptionalParam<qint32>())
- * 'getUsersByPage' operation sends the request to a server.
- * The request parameters are defined by a specification file.
-
- * @param[in] page qint32 [optional]
- */
-
- /**
- * \fn template < Functor, > void OAIUsersApi::getUsersByPage(const ::OpenAPI::OptionalParam<qint32> &page = ::OpenAPI::OptionalParam<qint32>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
- * 'getUsersByPage' 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++}
- * getUsersByPage(page, this, [&](const QRestReply &reply, const OAIUserPage &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 getUsersByPageWithDataImpl() in derived class.
- * The virtual getUsersByPageWithDataImpl() is being called by the template
- * function.
-
- * @param[in] page qint32 [optional]
- * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
- * @param[in] callback Functor && [optional]
- */
-
- /**
- * \fn void OAIUsersApi::getUsersByPageCallback(const QRestReply &reply)
- * Processes a \a reply response from a server.
- * The result of processed data is emitted by getUsersByPageFinished() or
- * being returned as a callback parameter of getUsersByPage() request.
- * @param[in] reply const QRestReply &
- */
-
- /**
- * \fn virtual void OAIUsersApi::getUsersByPageWithDataImpl(const ::OpenAPI::OptionalParam<qint32> &page, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- * Implements the getUsersByPage() operation request.
- * \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
- * and can be overloaded for mocking getUsersByPage() operation calls.
-
- * @param[in] page qint32 [optional]
- * @param[in] context const QObject * [optional]
- * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
- */
- void OAIUsersApi::getUsersByPageWithDataImpl(const ::OpenAPI::OptionalParam<qint32> &page, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- {
- const QUrl serverUrl = m_serverConfigs["getUsersByPage"][m_serverIndices.value("getUsersByPage")].serverUrl();
- QString fullPath = "/users";
- 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"page"_s), flags);
- opts.flags = flags;
- paramString = opts.suffix;
- if ((fullPath.indexOf("?") != fullPath.size() - 1) && (queryParamCounter == 0))
- fullPath.append(opts.prefix);
- if (page.hasValue()) {
- if (queryParamCounter > 0)
- fullPath.append("&");
- fullPath.append(opts.suffix + QUrl::toPercentEncoding(::OpenAPI::toStringValue(page.value())));
- queryParamCounter++;
- } else if (page.isNull()) {
- if (queryParamCounter > 0)
- fullPath.append("&");
- // style=form && explode=true && non-object => 'page' isn't used in serialization
- // style=form && explode=true && empty object => need to be 'page='
- // see https://spec.openapis.org/oas/v3.1.1.html#style-values
- if (opts.style == "form")
- fullPath.append(u"page="_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] {
- getUsersByPageCallback(QRestReply(reply));
- });
- connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
- if (reply) {
- emit getUsersByPageErrorOccurred(reply->error(), reply->errorString());
- OAICallerInfo callerInfo = m_callerData.take(reply);
- if (callerInfo.slot) {
- OAIUserPage 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 OAIUsersApi::getUsersByPageCallback(const QRestReply &reply)
- {
- auto netReply = reply.networkReply();
- if (netReply)
- netReply->disconnect(this);
- if (!reply.isSuccess())
- return;
-
- const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
- OAIUserPage 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 getUsersByPageFinished(output);
- }
-
- /**
- * \fn virtual void OAIUsersApi::loginUser(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest = ::OpenAPI::OptionalParam<OAITestOperation_request>())
- * 'loginUser' operation sends the request to a server.
- * The request parameters are defined by a specification file.
-
- * @param[in] oAITestOperationRequest OAITestOperation_request [optional]
- */
-
- /**
- * \fn template < Functor, > void OAIUsersApi::loginUser(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest = ::OpenAPI::OptionalParam<OAITestOperation_request>(), 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(oAITestOperationRequest, 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 loginUserWithDataImpl() in derived class.
- * The virtual loginUserWithDataImpl() is being called by the template
- * function.
-
- * @param[in] oAITestOperationRequest OAITestOperation_request [optional]
- * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
- * @param[in] callback Functor && [optional]
- */
-
- /**
- * \fn void OAIUsersApi::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 OAIUsersApi::loginUserWithDataImpl(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest, 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] oAITestOperationRequest OAITestOperation_request [optional]
- * @param[in] context const QObject * [optional]
- * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
- */
- void OAIUsersApi::loginUserWithDataImpl(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- {
- const QUrl serverUrl = m_serverConfigs["loginUser"][m_serverIndices.value("loginUser")].serverUrl();
- QString fullPath = "/login";
- m_networkFactory->setBaseUrl(serverUrl);
-
- // set m_testOperationPath for serialization tests
- m_testOperationPath = fullPath;
- OAIHttpRequestInput input(fullPath, "POST");
- input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
- if (oAITestOperationRequest.hasValue()) {
- QByteArray output = oAITestOperationRequest.value().asJson().toUtf8();
- input.m_requestBody.append(output);
- } else if (oAITestOperationRequest.isNull()) {
- input.m_requestBody.append("null");
- }
- 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) {
- QRestReply restRepl(reply);
- void *argv[] = { nullptr, &restRepl };
- QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
- callerInfo.slot->call(context, argv);
- }
- }
- });
- }
- }
-
- void OAIUsersApi::loginUserCallback(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 loginUserFinished();
- }
-
- /**
- * \fn virtual void OAIUsersApi::logoutUser()
- * 'logoutUser' operation sends the request to a server.
- * The request parameters are defined by a specification file.
-
- */
-
- /**
- * \fn template < Functor, > void OAIUsersApi::logoutUser(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(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] context const ContextTypeForFunctor< Functor > * [optional]
- * @param[in] callback Functor && [optional]
- */
-
- /**
- * \fn void OAIUsersApi::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 OAIUsersApi::logoutUserWithDataImpl(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] context const QObject * [optional]
- * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
- */
- void OAIUsersApi::logoutUserWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
- {
- const QUrl serverUrl = m_serverConfigs["logoutUser"][m_serverIndices.value("logoutUser")].serverUrl();
- QString fullPath = "/logout";
- m_networkFactory->setBaseUrl(serverUrl);
-
- // 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] {
- 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 OAIUsersApi::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 OAIUsersApi::updateUser(const qint64 &id, const ::OpenAPI::OptionalParam<OAIUpdateUser_request> &oAIUpdateUserRequest = ::OpenAPI::OptionalParam<OAIUpdateUser_request>())
- * 'updateUser' operation sends the request to a server.
- * The request parameters are defined by a specification file.
-
- * @param[in] id qint64 [required]
- * @param[in] oAIUpdateUserRequest OAIUpdateUser_request [optional]
- */
-
- /**
- * \fn template < Functor, > void OAIUsersApi::updateUser(const qint64 &id, const ::OpenAPI::OptionalParam<OAIUpdateUser_request> &oAIUpdateUserRequest = ::OpenAPI::OptionalParam<OAIUpdateUser_request>(), 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(id, oAIUpdateUserRequest, 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 updateUserWithDataImpl() in derived class.
- * The virtual updateUserWithDataImpl() is being called by the template
- * function.
-
- * @param[in] id qint64 [required]
- * @param[in] oAIUpdateUserRequest OAIUpdateUser_request [optional]
- * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
- * @param[in] callback Functor && [optional]
- */
-
- /**
- * \fn void OAIUsersApi::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 OAIUsersApi::updateUserWithDataImpl(const qint64 &id, const ::OpenAPI::OptionalParam<OAIUpdateUser_request> &oAIUpdateUserRequest, 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] id qint64 [required]
- * @param[in] oAIUpdateUserRequest OAIUpdateUser_request [optional]
- * @param[in] context const QObject * [optional]
- * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
- */
- void OAIUsersApi::updateUserWithDataImpl(const qint64 &id, const ::OpenAPI::OptionalParam<OAIUpdateUser_request> &oAIUpdateUserRequest, const QObject *context, QtPrivate::QSlotObjectBase *slot)
- {
- const QUrl serverUrl = m_serverConfigs["updateUser"][m_serverIndices.value("updateUser")].serverUrl();
- QString fullPath = "/users/{id}";
- m_networkFactory->setBaseUrl(serverUrl);
- {
- QString idPathParam = QString("{%1}").arg("id");
-
- 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"id"_s), flags);
- opts.flags = flags;
- QString paramString = opts.prefix + opts.suffix;
- paramString += QUrl::toPercentEncoding(::OpenAPI::toStringValue(id));
- // In case style=matrix and paramString is empty due to any reasons,
- // we serialize it like undefined value and delete '='.
- // Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
- if ((paramString == opts.prefix + opts.suffix) && QString("simple") == "matrix"_L1)
- paramString.chop(1);
- fullPath.replace(idPathParam, paramString);
- }
-
- // set m_testOperationPath for serialization tests
- m_testOperationPath = fullPath;
- OAIHttpRequestInput input(fullPath, "PATCH");
- input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
- if (oAIUpdateUserRequest.hasValue()) {
- QByteArray output = oAIUpdateUserRequest.value().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] {
- 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) {
- QRestReply restRepl(reply);
- void *argv[] = { nullptr, &restRepl };
- QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
- callerInfo.slot->call(context, argv);
- }
- }
- });
- }
- }
-
- void OAIUsersApi::updateUserCallback(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 updateUserFinished();
- }
-
- } // namespace OpenAPI