Revision control

Copy as Markdown

/**
* Responses 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("applicationJsonObjectResponse", defaultConf);
m_serverIndices.insert("applicationJsonObjectResponse", 0);
m_serverConfigs.insert("applicationJsonStringResponse", defaultConf);
m_serverIndices.insert("applicationJsonStringResponse", 0);
m_serverConfigs.insert("textPlainStringResponse", defaultConf);
m_serverIndices.insert("textPlainStringResponse", 0);
}
/**
* \fn virtual void QtOAITestApi::applicationJsonObjectResponse()
* 'applicationJsonObjectResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationJsonObjectResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationJsonObjectResponse' 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++}
* applicationJsonObjectResponse(this, [&](const QRestReply &reply, const QtOAIApplicationJsonObjectResponse_200_response &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 applicationJsonObjectResponseWithDataImpl() in derived class.
* The virtual applicationJsonObjectResponseWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationJsonObjectResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationJsonObjectResponseFinished() or
* being returned as a callback parameter of applicationJsonObjectResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationJsonObjectResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationJsonObjectResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationJsonObjectResponse() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationJsonObjectResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationJsonObjectResponse"][m_serverIndices.value("applicationJsonObjectResponse")].serverUrl();
QString fullPath = "/response/application/json/object";
m_networkFactory->setBaseUrl(serverUrl);
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "GET");
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] {
applicationJsonObjectResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationJsonObjectResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIApplicationJsonObjectResponse_200_response 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::applicationJsonObjectResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIApplicationJsonObjectResponse_200_response output(response);
// 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 applicationJsonObjectResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::applicationJsonStringResponse()
* 'applicationJsonStringResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationJsonStringResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationJsonStringResponse' 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++}
* applicationJsonStringResponse(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 applicationJsonStringResponseWithDataImpl() in derived class.
* The virtual applicationJsonStringResponseWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationJsonStringResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationJsonStringResponseFinished() or
* being returned as a callback parameter of applicationJsonStringResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationJsonStringResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationJsonStringResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationJsonStringResponse() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationJsonStringResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationJsonStringResponse"][m_serverIndices.value("applicationJsonStringResponse")].serverUrl();
QString fullPath = "/response/application/json/string";
m_networkFactory->setBaseUrl(serverUrl);
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "GET");
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] {
applicationJsonStringResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationJsonStringResponseErrorOccurred(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::applicationJsonStringResponseCallback(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 applicationJsonStringResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::textPlainStringResponse()
* 'textPlainStringResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::textPlainStringResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'textPlainStringResponse' 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++}
* textPlainStringResponse(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 textPlainStringResponseWithDataImpl() in derived class.
* The virtual textPlainStringResponseWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::textPlainStringResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by textPlainStringResponseFinished() or
* being returned as a callback parameter of textPlainStringResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::textPlainStringResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the textPlainStringResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking textPlainStringResponse() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::textPlainStringResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["textPlainStringResponse"][m_serverIndices.value("textPlainStringResponse")].serverUrl();
QString fullPath = "/response/text/plain/string";
m_networkFactory->setBaseUrl(serverUrl);
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "GET");
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] {
textPlainStringResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit textPlainStringResponseErrorOccurred(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::textPlainStringResponseCallback(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 textPlainStringResponseFinished(output);
}
} // namespace QtOpenAPI