Revision control

/**
* OpenAPI Petstore
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "QtOAIPetApi.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 {
QtOAIPetApi::QtOAIPetApi(QObject *parent)
: QtOAIBaseApi(parent)
{
initializeServerConfigs();
}
QtOAIPetApi::~QtOAIPetApi()
{
}
void QtOAIPetApi::initializeServerConfigs()
{
//Default server
QList<QtOAIServerConfiguration> defaultConf = QList<QtOAIServerConfiguration>();
//varying endpoint server
defaultConf.append(QtOAIServerConfiguration(
"No description provided",
QMap<QString, QtOAIServerVariable>()));
m_serverConfigs.insert("addPet", defaultConf);
m_serverIndices.insert("addPet", 0);
m_serverConfigs.insert("deletePet", defaultConf);
m_serverIndices.insert("deletePet", 0);
m_serverConfigs.insert("findPetsByAgeAndPatience", defaultConf);
m_serverIndices.insert("findPetsByAgeAndPatience", 0);
m_serverConfigs.insert("findPetsByStatus", defaultConf);
m_serverIndices.insert("findPetsByStatus", 0);
m_serverConfigs.insert("findPetsByTags", defaultConf);
m_serverIndices.insert("findPetsByTags", 0);
m_serverConfigs.insert("findPetsImageById", defaultConf);
m_serverIndices.insert("findPetsImageById", 0);
m_serverConfigs.insert("getJsonFile", defaultConf);
m_serverIndices.insert("getJsonFile", 0);
m_serverConfigs.insert("getPetById", defaultConf);
m_serverIndices.insert("getPetById", 0);
m_serverConfigs.insert("updatePet", defaultConf);
m_serverIndices.insert("updatePet", 0);
m_serverConfigs.insert("updatePetWithForm", defaultConf);
m_serverIndices.insert("updatePetWithForm", 0);
m_serverConfigs.insert("uploadFile", defaultConf);
m_serverIndices.insert("uploadFile", 0);
}
/**
* \fn virtual void QtOAIPetApi::addPet(const QtOAIPet &qtOAIPet)
* 'addPet' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] qtOAIPet QtOAIPet [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::addPet(const QtOAIPet &qtOAIPet, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'addPet' 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++}
* addPet(qtOAIPet, this, [&](const QRestReply &reply, const QtOAIPet &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 addPetWithDataImpl() in derived class.
* The virtual addPetWithDataImpl() is being called by the template
* function.
* @param[in] qtOAIPet QtOAIPet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::addPetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by addPetFinished() or
* being returned as a callback parameter of addPet() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::addPetWithDataImpl(const QtOAIPet &qtOAIPet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the addPet() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking addPet() operation calls.
* @param[in] qtOAIPet QtOAIPet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::addPetWithDataImpl(const QtOAIPet &qtOAIPet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["addPet"][m_serverIndices.value("addPet")].serverUrl();
QString fullPath = "/pet";
m_networkFactory->setBaseUrl(serverUrl);
if (!m_username.isEmpty() && !m_password.isEmpty()) {
QByteArray b64;
b64.append(m_username.toUtf8() + ":" + m_password.toUtf8());
setHeader(QHttpHeaders::WellKnownHeader::Authorization, QAnyStringView("Basic "_L1 + b64.toBase64()));
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QByteArray output = qtOAIPet.asJson().toUtf8();
input.m_requestBody.append(output);
}
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] {
addPetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit addPetErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIPet 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 QtOAIPetApi::addPetCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIPet 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 addPetFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::deletePet(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &apiKey = ::QtOpenAPI::OptionalParam<QString>())
* 'deletePet' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::deletePet(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &apiKey = ::QtOpenAPI::OptionalParam<QString>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'deletePet' 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++}
* deletePet(petId, apiKey, 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 deletePetWithDataImpl() in derived class.
* The virtual deletePetWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::deletePetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by deletePetFinished() or
* being returned as a callback parameter of deletePet() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::deletePetWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &apiKey, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the deletePet() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking deletePet() operation calls.
* @param[in] petId qint64 [required]
* @param[in] apiKey QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::deletePetWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &apiKey, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["deletePet"][m_serverIndices.value("deletePet")].serverUrl();
QString fullPath = "/pet/{petId}";
m_networkFactory->setBaseUrl(serverUrl);
if (!m_bearerToken.isEmpty())
setHeader(QHttpHeaders::WellKnownHeader::Authorization, QAnyStringView("Bearer "_L1 + m_bearerToken));
{
QString petIdPathParam = QString("{%1}").arg("petId");
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"petId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId));
// 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(petIdPathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "DELETE");
if (apiKey.hasValue())
{
SerializationFlags flags;
flags.setFlag(SerializationFlag::Object, false || false);
flags.setFlag(SerializationFlag::NeedPercentEncoding, false);
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, u"api_key"_s, flags);
opts.flags = flags;
const QString headerString = toStringValue(apiKey.value());
if (!headerString.isEmpty())
input.m_headers.replaceOrAppend("api_key"_L1, QAnyStringView(headerString));
}
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] {
deletePetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit deletePetErrorOccurred(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 QtOAIPetApi::deletePetCallback(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 deletePetFinished();
}
/**
* \fn virtual void QtOAIPetApi::findPetsByAgeAndPatience(const QList<qint32> &petData)
* 'findPetsByAgeAndPatience' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petData QList<qint32> [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::findPetsByAgeAndPatience(const QList<qint32> &petData, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsByAgeAndPatience' 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++}
* findPetsByAgeAndPatience(petData, this, [&](const QRestReply &reply, const QList<QtOAIPet> &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 findPetsByAgeAndPatienceWithDataImpl() in derived class.
* The virtual findPetsByAgeAndPatienceWithDataImpl() is being called by the template
* function.
* @param[in] petData QList<qint32> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::findPetsByAgeAndPatienceCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByAgeAndPatienceFinished() or
* being returned as a callback parameter of findPetsByAgeAndPatience() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::findPetsByAgeAndPatienceWithDataImpl(const QList<qint32> &petData, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByAgeAndPatience() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking findPetsByAgeAndPatience() operation calls.
* @param[in] petData QList<qint32> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::findPetsByAgeAndPatienceWithDataImpl(const QList<qint32> &petData, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["findPetsByAgeAndPatience"][m_serverIndices.value("findPetsByAgeAndPatience")].serverUrl();
QString fullPath = "/pet/findPetsByAgeAndPatience/{petData}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString petDataPathParam = QString("{%1}").arg("petData");
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"petData"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString = opts.prefix + serializeArrayValue(petData, opts);
// 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(petDataPathParam, 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] {
findPetsByAgeAndPatienceCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByAgeAndPatienceErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<QtOAIPet> 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 QtOAIPetApi::findPetsByAgeAndPatienceCallback(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<QtOAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
QtOAIPet val;
const bool ok = ::QtOpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to QtOAIPet.", 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 findPetsByAgeAndPatienceFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::findPetsByStatus(const QList<QString> &status)
* 'findPetsByStatus' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] status QList<QString> [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::findPetsByStatus(const QList<QString> &status, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsByStatus' 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++}
* findPetsByStatus(status, this, [&](const QRestReply &reply, const QList<QtOAIPet> &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 findPetsByStatusWithDataImpl() in derived class.
* The virtual findPetsByStatusWithDataImpl() is being called by the template
* function.
* @param[in] status QList<QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::findPetsByStatusCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByStatusFinished() or
* being returned as a callback parameter of findPetsByStatus() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::findPetsByStatusWithDataImpl(const QList<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByStatus() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking findPetsByStatus() operation calls.
* @param[in] status QList<QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::findPetsByStatusWithDataImpl(const QList<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["findPetsByStatus"][m_serverIndices.value("findPetsByStatus")].serverUrl();
QString fullPath = "/pet/findByStatus";
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, false);
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"status"_s), flags);
opts.flags = flags;
if ((fullPath.indexOf("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
fullPath.append(serializeArrayValue(status, opts));
queryParamCounter++;
}
}
// 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] {
findPetsByStatusCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByStatusErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<QtOAIPet> 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 QtOAIPetApi::findPetsByStatusCallback(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<QtOAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
QtOAIPet val;
const bool ok = ::QtOpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to QtOAIPet.", 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 findPetsByStatusFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::findPetsByTags(const QList<QString> &tags)
* \deprecated 'findPetsByTags' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] tags QList<QString> [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::findPetsByTags(const QList<QString> &tags, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* \deprecated 'findPetsByTags' 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++}
* findPetsByTags(tags, this, [&](const QRestReply &reply, const QList<QtOAIPet> &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 findPetsByTagsWithDataImpl() in derived class.
* The virtual findPetsByTagsWithDataImpl() is being called by the template
* function.
* @param[in] tags QList<QString> [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::findPetsByTagsCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsByTagsFinished() or
* being returned as a callback parameter of findPetsByTags() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::findPetsByTagsWithDataImpl(const QList<QString> &tags, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsByTags() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking findPetsByTags() operation calls.
* @param[in] tags QList<QString> [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::findPetsByTagsWithDataImpl(const QList<QString> &tags, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["findPetsByTags"][m_serverIndices.value("findPetsByTags")].serverUrl();
QString fullPath = "/pet/findByTags";
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, false);
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"tags"_s), flags);
opts.flags = flags;
if ((fullPath.indexOf("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
fullPath.append(serializeArrayValue(tags, opts));
queryParamCounter++;
}
}
// 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] {
findPetsByTagsCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByTagsErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<QtOAIPet> 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 QtOAIPetApi::findPetsByTagsCallback(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<QtOAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
QtOAIPet val;
const bool ok = ::QtOpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to QtOAIPet.", 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 findPetsByTagsFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::findPetsImageById(const qint64 &petId)
* 'findPetsImageById' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::findPetsImageById(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'findPetsImageById' 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++}
* findPetsImageById(petId, 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 findPetsImageByIdWithDataImpl() in derived class.
* The virtual findPetsImageByIdWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::findPetsImageByIdCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by findPetsImageByIdFinished() or
* being returned as a callback parameter of findPetsImageById() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::findPetsImageByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the findPetsImageById() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking findPetsImageById() operation calls.
* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::findPetsImageByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["findPetsImageById"][m_serverIndices.value("findPetsImageById")].serverUrl();
QString fullPath = "/pet/findPetsImageById";
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"petId"_s), flags);
opts.flags = flags;
paramString = opts.suffix;
if ((fullPath.indexOf("?") != fullPath.size() - 1) && (queryParamCounter == 0))
fullPath.append(opts.prefix);
{
if (queryParamCounter > 0)
fullPath.append("&");
fullPath.append(opts.suffix + QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId)));
queryParamCounter++;
}
}
// 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] {
findPetsImageByIdCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsImageByIdErrorOccurred(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 QtOAIPetApi::findPetsImageByIdCallback(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 findPetsImageByIdFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::getJsonFile(const qint64 &petId)
* 'getJsonFile' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::getJsonFile(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getJsonFile' 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++}
* getJsonFile(petId, 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 getJsonFileWithDataImpl() in derived class.
* The virtual getJsonFileWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::getJsonFileCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getJsonFileFinished() or
* being returned as a callback parameter of getJsonFile() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::getJsonFileWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getJsonFile() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking getJsonFile() operation calls.
* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::getJsonFileWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["getJsonFile"][m_serverIndices.value("getJsonFile")].serverUrl();
QString fullPath = "/pet/{petId}/uploadImage";
m_networkFactory->setBaseUrl(serverUrl);
{
QString petIdPathParam = QString("{%1}").arg("petId");
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"petId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId));
// 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(petIdPathParam, 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] {
getJsonFileCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getJsonFileErrorOccurred(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 QtOAIPetApi::getJsonFileCallback(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 getJsonFileFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::getPetById(const qint64 &petId)
* 'getPetById' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::getPetById(const qint64 &petId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getPetById' 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++}
* getPetById(petId, this, [&](const QRestReply &reply, const QtOAIPet &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 getPetByIdWithDataImpl() in derived class.
* The virtual getPetByIdWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::getPetByIdCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getPetByIdFinished() or
* being returned as a callback parameter of getPetById() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::getPetByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getPetById() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking getPetById() operation calls.
* @param[in] petId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::getPetByIdWithDataImpl(const qint64 &petId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["getPetById"][m_serverIndices.value("getPetById")].serverUrl();
QString fullPath = "/pet/{petId}";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key"_L1)) {
setHeader("api_key"_L1, QAnyStringView(m_apiKeys.find("api_key"_L1).value()));
}
{
QString petIdPathParam = QString("{%1}").arg("petId");
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"petId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId));
// 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(petIdPathParam, 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] {
getPetByIdCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getPetByIdErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIPet 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 QtOAIPetApi::getPetByIdCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIPet 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 getPetByIdFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::updatePet(const QtOAIPet &qtOAIPet)
* 'updatePet' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] qtOAIPet QtOAIPet [required]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::updatePet(const QtOAIPet &qtOAIPet, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'updatePet' 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++}
* updatePet(qtOAIPet, this, [&](const QRestReply &reply, const QtOAIPet &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 updatePetWithDataImpl() in derived class.
* The virtual updatePetWithDataImpl() is being called by the template
* function.
* @param[in] qtOAIPet QtOAIPet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::updatePetCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by updatePetFinished() or
* being returned as a callback parameter of updatePet() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::updatePetWithDataImpl(const QtOAIPet &qtOAIPet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updatePet() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking updatePet() operation calls.
* @param[in] qtOAIPet QtOAIPet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::updatePetWithDataImpl(const QtOAIPet &qtOAIPet, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["updatePet"][m_serverIndices.value("updatePet")].serverUrl();
QString fullPath = "/pet";
m_networkFactory->setBaseUrl(serverUrl);
if (m_apiKeys.contains("api_key_query")) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("api_key_query=").append(m_apiKeys.find("api_key_query").value());
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "PUT");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QByteArray output = qtOAIPet.asJson().toUtf8();
input.m_requestBody.append(output);
}
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] {
updatePetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit updatePetErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIPet 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 QtOAIPetApi::updatePetCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIPet 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 updatePetFinished(output);
}
/**
* \fn virtual void QtOAIPetApi::updatePetWithForm(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &name = ::QtOpenAPI::OptionalParam<QString>(), const ::QtOpenAPI::OptionalParam<QString> &status = ::QtOpenAPI::OptionalParam<QString>())
* 'updatePetWithForm' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::updatePetWithForm(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &name = ::QtOpenAPI::OptionalParam<QString>(), const ::QtOpenAPI::OptionalParam<QString> &status = ::QtOpenAPI::OptionalParam<QString>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'updatePetWithForm' 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++}
* updatePetWithForm(petId, name, status, 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 updatePetWithFormWithDataImpl() in derived class.
* The virtual updatePetWithFormWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::updatePetWithFormCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by updatePetWithFormFinished() or
* being returned as a callback parameter of updatePetWithForm() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &name, const ::QtOpenAPI::OptionalParam<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the updatePetWithForm() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking updatePetWithForm() operation calls.
* @param[in] petId qint64 [required]
* @param[in] name QString [optional]
* @param[in] status QString [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &name, const ::QtOpenAPI::OptionalParam<QString> &status, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["updatePetWithForm"][m_serverIndices.value("updatePetWithForm")].serverUrl();
QString fullPath = "/pet/{petId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString petIdPathParam = QString("{%1}").arg("petId");
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"petId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId));
// 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(petIdPathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/x-www-form-urlencoded"_L1);
input.setFormData(true);
input.addVarLayout(input.m_httpMethod == "GET"_L1 || input.m_httpMethod == "HEAD"_L1
? ADDRESS : URL_ENCODED);
if (name.hasValue()) {
QString contentType;
using VT = std::decay_t<decltype(name.value())>;
input.addFieldHeaders(u"name"_s, addContentField<VT>(contentType));
input.addVar(u"name"_s, ::QtOpenAPI::serializeMediaTypeContentField(contentType, name.value()));
}
if (status.hasValue()) {
QString contentType;
using VT = std::decay_t<decltype(status.value())>;
input.addFieldHeaders(u"status"_s, addContentField<VT>(contentType));
input.addVar(u"status"_s, ::QtOpenAPI::serializeMediaTypeContentField(contentType, status.value()));
}
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] {
updatePetWithFormCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit updatePetWithFormErrorOccurred(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 QtOAIPetApi::updatePetWithFormCallback(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 updatePetWithFormFinished();
}
/**
* \fn virtual void QtOAIPetApi::uploadFile(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &additionalMetadata = ::QtOpenAPI::OptionalParam<QString>(), const ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement> &file = ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement>())
* 'uploadFile' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QtOAIHttpFileElement [optional]
*/
/**
* \fn template < Functor, > void QtOAIPetApi::uploadFile(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &additionalMetadata = ::QtOpenAPI::OptionalParam<QString>(), const ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement> &file = ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement>(), const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'uploadFile' 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++}
* uploadFile(petId, additionalMetadata, file, this, [&](const QRestReply &reply, const QtOAIApiResponse &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 uploadFileWithDataImpl() in derived class.
* The virtual uploadFileWithDataImpl() is being called by the template
* function.
* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QtOAIHttpFileElement [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void QtOAIPetApi::uploadFileCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by uploadFileFinished() or
* being returned as a callback parameter of uploadFile() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void QtOAIPetApi::uploadFileWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &additionalMetadata, const ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement> &file, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the uploadFile() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking uploadFile() operation calls.
* @param[in] petId qint64 [required]
* @param[in] additionalMetadata QString [optional]
* @param[in] file QtOAIHttpFileElement [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void QtOAIPetApi::uploadFileWithDataImpl(const qint64 &petId, const ::QtOpenAPI::OptionalParam<QString> &additionalMetadata, const ::QtOpenAPI::OptionalParam<QtOAIHttpFileElement> &file, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["uploadFile"][m_serverIndices.value("uploadFile")].serverUrl();
QString fullPath = "/pet/{petId}/uploadImage";
m_networkFactory->setBaseUrl(serverUrl);
{
QString petIdPathParam = QString("{%1}").arg("petId");
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"petId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::QtOpenAPI::toStringValue(petId));
// 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(petIdPathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
QtOAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "multipart/form-data"_L1);
input.setFormData(true);
input.addVarLayout(MULTIPART);
if (additionalMetadata.hasValue()) {
QString contentType;
using VT = std::decay_t<decltype(additionalMetadata.value())>;
input.addFieldHeaders(u"additionalMetadata"_s, addContentField<VT>(contentType));
input.addVar(u"additionalMetadata"_s, ::QtOpenAPI::serializeMediaTypeContentField(contentType, additionalMetadata.value()));
}
if (file.hasValue()) {
QString contentType;
- input.addFile("file", file.value().filename(), file.value().requestFilename(), contentType);
+ input.addFile("file", file.value().filename(), contentType);
}
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] {
uploadFileCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit uploadFileErrorOccurred(reply->error(), reply->errorString());
QtOAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QtOAIApiResponse 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 QtOAIPetApi::uploadFileCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = QtOAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QtOAIApiResponse 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 uploadFileFinished(output);
}
} // namespace QtOpenAPI