Revision control

/**
* 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("applicationEncodedPdfSaveResponse", defaultConf);
m_serverIndices.insert("applicationEncodedPdfSaveResponse", 0);
+ m_serverConfigs.insert("applicationJsonArrayResponse", defaultConf);
+ m_serverIndices.insert("applicationJsonArrayResponse", 0);
m_serverConfigs.insert("applicationJsonEncodedObjectResponse", defaultConf);
m_serverIndices.insert("applicationJsonEncodedObjectResponse", 0);
+ m_serverConfigs.insert("applicationJsonMapResponse", defaultConf);
+ m_serverIndices.insert("applicationJsonMapResponse", 0);
m_serverConfigs.insert("applicationJsonStringResponse", defaultConf);
m_serverIndices.insert("applicationJsonStringResponse", 0);
m_serverConfigs.insert("applicationOctetStreamResponse", defaultConf);
m_serverIndices.insert("applicationOctetStreamResponse", 0);
m_serverConfigs.insert("applicationPdfInlineResponse", defaultConf);
m_serverIndices.insert("applicationPdfInlineResponse", 0);
m_serverConfigs.insert("applicationPdfSaveResponse", defaultConf);
m_serverIndices.insert("applicationPdfSaveResponse", 0);
m_serverConfigs.insert("emptyResponse", defaultConf);
m_serverIndices.insert("emptyResponse", 0);
m_serverConfigs.insert("inlineImageResponse", defaultConf);
m_serverIndices.insert("inlineImageResponse", 0);
m_serverConfigs.insert("saveImageResponse", defaultConf);
m_serverIndices.insert("saveImageResponse", 0);
m_serverConfigs.insert("textPlainStringResponse", defaultConf);
m_serverIndices.insert("textPlainStringResponse", 0);
}
/**
* \fn virtual void QtOAITestApi::applicationEncodedPdfSaveResponse(const QString &fileId)
* 'applicationEncodedPdfSaveResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] fileId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationEncodedPdfSaveResponse(const QString &fileId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationEncodedPdfSaveResponse' 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++}
* applicationEncodedPdfSaveResponse(fileId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 applicationEncodedPdfSaveResponseWithDataImpl() in derived class.
* The virtual applicationEncodedPdfSaveResponseWithDataImpl() is being called by the template
* function.
* @param[in] fileId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationEncodedPdfSaveResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationEncodedPdfSaveResponseFinished() or
* being returned as a callback parameter of applicationEncodedPdfSaveResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationEncodedPdfSaveResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationEncodedPdfSaveResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationEncodedPdfSaveResponse() operation calls.
* @param[in] fileId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationEncodedPdfSaveResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationEncodedPdfSaveResponse"][m_serverIndices.value("applicationEncodedPdfSaveResponse")].serverUrl();
QString fullPath = "/response/application/pdf/save/encoded/{fileId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString fileIdPathParam = QString("{%1}").arg("fileId");
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"fileId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(fileId));
// 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(fileIdPathParam, paramString);
}
// 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] {
applicationEncodedPdfSaveResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationEncodedPdfSaveResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::applicationEncodedPdfSaveResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 applicationEncodedPdfSaveResponseFinished(output);
}
+ /**
+ * \fn virtual void QtOAITestApi::applicationJsonArrayResponse()
+ * 'applicationJsonArrayResponse' operation sends the request to a server.
+ * The request parameters are defined by a specification file.
+
+ */
+
+ /**
+ * \fn template < Functor, > void QtOAITestApi::applicationJsonArrayResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
+ * 'applicationJsonArrayResponse' 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++}
+ * applicationJsonArrayResponse(this, [&](const QRestReply &reply, const QList<QtOAIUser> &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 applicationJsonArrayResponseWithDataImpl() in derived class.
+ * The virtual applicationJsonArrayResponseWithDataImpl() is being called by the template
+ * function.
+
+ * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
+ * @param[in] callback Functor && [optional]
+ */
+
+ /**
+ * \fn void QtOAITestApi::applicationJsonArrayResponseCallback(const QRestReply &reply)
+ * Processes a \a reply response from a server.
+ * The result of processed data is emitted by applicationJsonArrayResponseFinished() or
+ * being returned as a callback parameter of applicationJsonArrayResponse() request.
+ * @param[in] reply const QRestReply &
+ */
+
+ /**
+ * \fn virtual void QtOAITestApi::applicationJsonArrayResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
+ * Implements the applicationJsonArrayResponse() operation request.
+ * \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
+ * and can be overloaded for mocking applicationJsonArrayResponse() operation calls.
+
+ * @param[in] context const QObject * [optional]
+ * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
+ */
+ void QtOAITestApi::applicationJsonArrayResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
+ {
+ const QUrl serverUrl = m_serverConfigs["applicationJsonArrayResponse"][m_serverIndices.value("applicationJsonArrayResponse")].serverUrl();
+ QString fullPath = "/response/application/json/array";
+ 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] {
+ applicationJsonArrayResponseCallback(QRestReply(reply));
+ });
+ connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
+ if (reply) {
+ emit applicationJsonArrayResponseErrorOccurred(reply->error(), reply->errorString());
+ QtOAICallerInfo callerInfo = m_callerData.take(reply);
+ if (callerInfo.slot) {
+ QList<QtOAIUser> 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::applicationJsonArrayResponseCallback(const QRestReply &reply)
+ {
+ auto netReply = reply.networkReply();
+ if (netReply)
+ netReply->disconnect(this);
+ if (!reply.isSuccess())
+ return;
+
+ const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
+ QList<QtOAIUser> output;
+ const QJsonDocument doc = QJsonDocument::fromJson(response);
+ if (!doc.isNull() && doc.isArray()) {
+ const QJsonArray jsonArray = doc.array();
+ for (const QJsonValue &obj : jsonArray) {
+ QtOAIUser val;
+ const bool ok = ::QtOpenAPI::fromJsonValue(val, obj);
+ if (!ok)
+ qWarning("%s: Failed to convert QJsonValue to QtOAIUser.", Q_FUNC_INFO);
+ output.append(val);
+ }
+ } else {
+ qWarning("%s: Failed to parse the response as a JSON array.", 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 applicationJsonArrayResponseFinished(output);
+ }
+
/**
* \fn virtual void QtOAITestApi::applicationJsonEncodedObjectResponse()
* 'applicationJsonEncodedObjectResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationJsonEncodedObjectResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationJsonEncodedObjectResponse' 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++}
* applicationJsonEncodedObjectResponse(this, [&](const QRestReply &reply, const QtOAIApplicationJsonEncodedObjectResponse_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 applicationJsonEncodedObjectResponseWithDataImpl() in derived class.
* The virtual applicationJsonEncodedObjectResponseWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationJsonEncodedObjectResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationJsonEncodedObjectResponseFinished() or
* being returned as a callback parameter of applicationJsonEncodedObjectResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationJsonEncodedObjectResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationJsonEncodedObjectResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationJsonEncodedObjectResponse() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationJsonEncodedObjectResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationJsonEncodedObjectResponse"][m_serverIndices.value("applicationJsonEncodedObjectResponse")].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] {
applicationJsonEncodedObjectResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationJsonEncodedObjectResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIApplicationJsonEncodedObjectResponse_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::applicationJsonEncodedObjectResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIApplicationJsonEncodedObjectResponse_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 applicationJsonEncodedObjectResponseFinished(output);
}
+ /**
+ * \fn virtual void QtOAITestApi::applicationJsonMapResponse()
+ * 'applicationJsonMapResponse' operation sends the request to a server.
+ * The request parameters are defined by a specification file.
+
+ */
+
+ /**
+ * \fn template < Functor, > void QtOAITestApi::applicationJsonMapResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
+ * 'applicationJsonMapResponse' 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++}
+ * applicationJsonMapResponse(this, [&](const QRestReply &reply, const QMap<QString, QtOAIUser> &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 applicationJsonMapResponseWithDataImpl() in derived class.
+ * The virtual applicationJsonMapResponseWithDataImpl() is being called by the template
+ * function.
+
+ * @param[in] context const ContextTypeForFunctor< Functor > * [optional]
+ * @param[in] callback Functor && [optional]
+ */
+
+ /**
+ * \fn void QtOAITestApi::applicationJsonMapResponseCallback(const QRestReply &reply)
+ * Processes a \a reply response from a server.
+ * The result of processed data is emitted by applicationJsonMapResponseFinished() or
+ * being returned as a callback parameter of applicationJsonMapResponse() request.
+ * @param[in] reply const QRestReply &
+ */
+
+ /**
+ * \fn virtual void QtOAITestApi::applicationJsonMapResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
+ * Implements the applicationJsonMapResponse() operation request.
+ * \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
+ * and can be overloaded for mocking applicationJsonMapResponse() operation calls.
+
+ * @param[in] context const QObject * [optional]
+ * @param[in] slot QtPrivate::QSlotObjectBase * [optional]
+ */
+ void QtOAITestApi::applicationJsonMapResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
+ {
+ const QUrl serverUrl = m_serverConfigs["applicationJsonMapResponse"][m_serverIndices.value("applicationJsonMapResponse")].serverUrl();
+ QString fullPath = "/response/application/json/map";
+ 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] {
+ applicationJsonMapResponseCallback(QRestReply(reply));
+ });
+ connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
+ if (reply) {
+ emit applicationJsonMapResponseErrorOccurred(reply->error(), reply->errorString());
+ QtOAICallerInfo callerInfo = m_callerData.take(reply);
+ if (callerInfo.slot) {
+ QMap<QString, QtOAIUser> 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::applicationJsonMapResponseCallback(const QRestReply &reply)
+ {
+ auto netReply = reply.networkReply();
+ if (netReply)
+ netReply->disconnect(this);
+ if (!reply.isSuccess())
+ return;
+
+ const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
+ QMap<QString, QtOAIUser> output;
+ const QJsonDocument doc = QJsonDocument::fromJson(response);
+ if (!doc.isNull() && doc.isObject()) {
+ const QJsonObject obj = doc.object();
+ for (const QString &key : obj.keys()) {
+ QtOAIUser val;
+ const bool ok = ::QtOpenAPI::fromJsonValue(val, obj[key]);
+ if (!ok)
+ qWarning("%s: Failed to convert QJsonValue to QtOAIUser.", Q_FUNC_INFO);
+ output.insert(key, val);
+ }
+ } else {
+ qWarning("%s: Failed to parse the response as a JSON object.", 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 applicationJsonMapResponseFinished(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::applicationOctetStreamResponse(const QString &fileId)
* 'applicationOctetStreamResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] fileId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationOctetStreamResponse(const QString &fileId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationOctetStreamResponse' 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++}
* applicationOctetStreamResponse(fileId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 applicationOctetStreamResponseWithDataImpl() in derived class.
* The virtual applicationOctetStreamResponseWithDataImpl() is being called by the template
* function.
* @param[in] fileId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationOctetStreamResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationOctetStreamResponseFinished() or
* being returned as a callback parameter of applicationOctetStreamResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationOctetStreamResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationOctetStreamResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationOctetStreamResponse() operation calls.
* @param[in] fileId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationOctetStreamResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationOctetStreamResponse"][m_serverIndices.value("applicationOctetStreamResponse")].serverUrl();
QString fullPath = "/response/application/octet-stream/{fileId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString fileIdPathParam = QString("{%1}").arg("fileId");
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"fileId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(fileId));
// 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(fileIdPathParam, paramString);
}
// 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] {
applicationOctetStreamResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationOctetStreamResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::applicationOctetStreamResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 applicationOctetStreamResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::applicationPdfInlineResponse(const QString &fileId)
* 'applicationPdfInlineResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] fileId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationPdfInlineResponse(const QString &fileId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationPdfInlineResponse' 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++}
* applicationPdfInlineResponse(fileId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 applicationPdfInlineResponseWithDataImpl() in derived class.
* The virtual applicationPdfInlineResponseWithDataImpl() is being called by the template
* function.
* @param[in] fileId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationPdfInlineResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationPdfInlineResponseFinished() or
* being returned as a callback parameter of applicationPdfInlineResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationPdfInlineResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationPdfInlineResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationPdfInlineResponse() operation calls.
* @param[in] fileId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationPdfInlineResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationPdfInlineResponse"][m_serverIndices.value("applicationPdfInlineResponse")].serverUrl();
QString fullPath = "/response/application/pdf/inline/{fileId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString fileIdPathParam = QString("{%1}").arg("fileId");
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"fileId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(fileId));
// 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(fileIdPathParam, paramString);
}
// 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] {
applicationPdfInlineResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationPdfInlineResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::applicationPdfInlineResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 applicationPdfInlineResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::applicationPdfSaveResponse(const QString &fileId)
* 'applicationPdfSaveResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] fileId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::applicationPdfSaveResponse(const QString &fileId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'applicationPdfSaveResponse' 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++}
* applicationPdfSaveResponse(fileId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 applicationPdfSaveResponseWithDataImpl() in derived class.
* The virtual applicationPdfSaveResponseWithDataImpl() is being called by the template
* function.
* @param[in] fileId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::applicationPdfSaveResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by applicationPdfSaveResponseFinished() or
* being returned as a callback parameter of applicationPdfSaveResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::applicationPdfSaveResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the applicationPdfSaveResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking applicationPdfSaveResponse() operation calls.
* @param[in] fileId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::applicationPdfSaveResponseWithDataImpl(const QString &fileId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["applicationPdfSaveResponse"][m_serverIndices.value("applicationPdfSaveResponse")].serverUrl();
QString fullPath = "/response/application/pdf/save/{fileId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString fileIdPathParam = QString("{%1}").arg("fileId");
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"fileId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(fileId));
// 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(fileIdPathParam, paramString);
}
// 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] {
applicationPdfSaveResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit applicationPdfSaveResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::applicationPdfSaveResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 applicationPdfSaveResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::emptyResponse()
* 'emptyResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void QtOAITestApi::emptyResponse(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'emptyResponse' 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++}
* emptyResponse(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 emptyResponseWithDataImpl() in derived class.
* The virtual emptyResponseWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::emptyResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by emptyResponseFinished() or
* being returned as a callback parameter of emptyResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::emptyResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the emptyResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking emptyResponse() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::emptyResponseWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["emptyResponse"][m_serverIndices.value("emptyResponse")].serverUrl();
QString fullPath = "/response/empty";
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] {
emptyResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit emptyResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo 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 QtOAITestApi::emptyResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
QtOAICallerInfo 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 emptyResponseFinished();
}
/**
* \fn virtual void QtOAITestApi::inlineImageResponse(const QString &imageId)
* 'inlineImageResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] imageId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::inlineImageResponse(const QString &imageId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'inlineImageResponse' 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++}
* inlineImageResponse(imageId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 inlineImageResponseWithDataImpl() in derived class.
* The virtual inlineImageResponseWithDataImpl() is being called by the template
* function.
* @param[in] imageId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::inlineImageResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by inlineImageResponseFinished() or
* being returned as a callback parameter of inlineImageResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::inlineImageResponseWithDataImpl(const QString &imageId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the inlineImageResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking inlineImageResponse() operation calls.
* @param[in] imageId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::inlineImageResponseWithDataImpl(const QString &imageId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["inlineImageResponse"][m_serverIndices.value("inlineImageResponse")].serverUrl();
QString fullPath = "/response/image/inline/{imageId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString imageIdPathParam = QString("{%1}").arg("imageId");
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"imageId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(imageId));
// 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(imageIdPathParam, paramString);
}
// 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] {
inlineImageResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit inlineImageResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::inlineImageResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 inlineImageResponseFinished(output);
}
/**
* \fn virtual void QtOAITestApi::saveImageResponse(const QString &imageId)
* 'saveImageResponse' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] imageId QString [required]
*/
/**
* \fn template < Functor, > void QtOAITestApi::saveImageResponse(const QString &imageId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'saveImageResponse' 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++}
* saveImageResponse(imageId, this, [&](const QRestReply &reply, const QtOAIHttpFileElement &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 saveImageResponseWithDataImpl() in derived class.
* The virtual saveImageResponseWithDataImpl() is being called by the template
* function.
* @param[in] imageId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAITestApi::saveImageResponseCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by saveImageResponseFinished() or
* being returned as a callback parameter of saveImageResponse() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAITestApi::saveImageResponseWithDataImpl(const QString &imageId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the saveImageResponse() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking saveImageResponse() operation calls.
* @param[in] imageId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAITestApi::saveImageResponseWithDataImpl(const QString &imageId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["saveImageResponse"][m_serverIndices.value("saveImageResponse")].serverUrl();
QString fullPath = "/response/image/save/{imageId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString imageIdPathParam = QString("{%1}").arg("imageId");
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"imageId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(imageId));
// 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(imageIdPathParam, paramString);
}
// 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] {
saveImageResponseCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit saveImageResponseErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIHttpFileElement 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::saveImageResponseCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, QtOAIHttpFileElement> responseFiles;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
QtOAIHttpFileElement output = QtOAIHttpRequestWorker::getHttpFileElement(responseFiles);
// 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 saveImageResponseFinished(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