Revision control

/**
* Qt Quick Demo - RESTful API client
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "OAIRegisterApi.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 {
OAIRegisterApi::OAIRegisterApi(QObject *parent)
: OAIBaseApi(parent)
{
initializeServerConfigs();
}
OAIRegisterApi::~OAIRegisterApi()
{
}
void OAIRegisterApi::initializeServerConfigs()
{
//Default server
QList<OAIServerConfiguration> defaultConf = QList<OAIServerConfiguration>();
//varying endpoint server
defaultConf.append(OAIServerConfiguration(
"Public REST API test service",
QMap<QString, OAIServerVariable>()));
defaultConf.append(OAIServerConfiguration(
"Qt-based REST API server",
QMap<QString, OAIServerVariable>()));
m_serverConfigs.insert("registerPost", defaultConf);
m_serverIndices.insert("registerPost", 0);
}
/**
* \fn virtual void OAIRegisterApi::registerPost(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest = ::OpenAPI::OptionalParam<OAITestOperation_request>())
* 'registerPost' 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 OAIRegisterApi::registerPost(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest = ::OpenAPI::OptionalParam<OAITestOperation_request>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'registerPost' 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++}
* registerPost(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 registerPostWithDataImpl() in derived class.
* The virtual registerPostWithDataImpl() 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 OAIRegisterApi::registerPostCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by registerPostFinished() or
* being returned as a callback parameter of registerPost() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void OAIRegisterApi::registerPostWithDataImpl(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the registerPost() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking registerPost() operation calls.
* @param[in] oAITestOperationRequest OAITestOperation_request [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIRegisterApi::registerPostWithDataImpl(const ::OpenAPI::OptionalParam<OAITestOperation_request> &oAITestOperationRequest, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["registerPost"][m_serverIndices.value("registerPost")].serverUrl();
QString fullPath = "/register";
m_networkFactory->setBaseUrl(serverUrl);
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
if (oAITestOperationRequest.hasValue()) {
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
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] {
registerPostCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit registerPostErrorOccurred(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 OAIRegisterApi::registerPostCallback(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 registerPostFinished();
}
} // namespace OpenAPI