Revision control

Copy as Markdown

/**
* Compression Test
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "QtOAITestApi.h"
#include "QtOAIServerConfiguration.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 QtOpenAPI {
QtOAITestApi::QtOAITestApi(QObject *parent)
: QtOAIBaseApi(parent)
{
initializeServerConfigs();
}
QtOAITestApi::~QtOAITestApi()
{
}
void QtOAITestApi::initializeServerConfigs()
{
//Default server
QList<QtOAIServerConfiguration> defaultConf = QList<QtOAIServerConfiguration>();
//varying endpoint server
defaultConf.append(QtOAIServerConfiguration(
"No description provided",
QMap<QString, QtOAIServerVariable>()));
m_serverConfigs.insert("dummyOperation", defaultConf);
m_serverIndices.insert("dummyOperation", 0);
}
/**
* \fn virtual void QtOAITestApi::dummyOperation()
* 'dummyOperation' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::dummyOperation(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'dummyOperation' 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++}
* dummyOperation(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 dummyOperationWithDataImpl() in derived class.
* The virtual dummyOperationWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::dummyOperationCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by dummyOperationFinished() or
* being returned as a callback parameter of dummyOperation() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::dummyOperationWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the dummyOperation() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking dummyOperation() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::dummyOperationWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["dummyOperation"][m_serverIndices.value("dummyOperation")].serverUrl();
QString fullPath = "/compression/dummy";
m_networkFactory->setBaseUrl(serverUrl);
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "POST");
QNetworkRequest request
= QtOAIHttpRequestWorker::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, QtOAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
dummyOperationCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit dummyOperationErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo 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 QtOAITestApi::dummyOperationCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QString output;
const bool ok = ::QtOpenAPI::fromByteArray(response, output);
if (!ok)
qWarning("%s: Failed to convert the response to QString.", Q_FUNC_INFO);
// Check if callback is provided
QtOAICallerInfo 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 dummyOperationFinished(output);
}
} // namespace QtOpenAPI