Revision control
/**
* OpenAPI Petstore
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "OAIPetApi.h"
#include "OAIServerConfiguration.h"
#include <QtCore/qanystringview.h>
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#include <QtNetwork/qhttpmultipart.h>
#include <QtNetwork/qnetworkaccessmanager.h>
#include <QtNetwork/qnetworkreply.h>
#include <QtNetwork/qnetworkrequestfactory.h>
#include <QtNetwork/qrestaccessmanager.h>
using namespace Qt::StringLiterals;
namespace OpenAPI {
OAIPetApi::OAIPetApi(QObject *parent)
: OAIBaseApi(parent)
{
initializeServerConfigs();
}
OAIPetApi::~OAIPetApi()
{
}
void OAIPetApi::initializeServerConfigs()
{
//Default server
QList<OAIServerConfiguration> defaultConf = QList<OAIServerConfiguration>();
//varying endpoint server
defaultConf.append(OAIServerConfiguration(
QUrl("http://127.0.0.1:19080/v2"),
"No description provided",
QMap<QString, OAIServerVariable>()));
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 OAIPetApi::addPet(const OAIPet &oAIPet)
* 'addPet' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIPet OAIPet [required]
*/
/**
* \fn template < Functor, > void OAIPetApi::addPet(const OAIPet &oAIPet, 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(oAIPet, this, [&](const QRestReply &reply, const OAIPet &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] oAIPet OAIPet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIPetApi::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 OAIPetApi::addPetWithDataImpl(const OAIPet &oAIPet, 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] oAIPet OAIPet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIPetApi::addPetWithDataImpl(const OAIPet &oAIPet, 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()));
+ setHeader(QHttpHeaders::WellKnownHeader::Authorization, "Basic "_L1 + b64.toBase64());
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "POST");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QByteArray output = oAIPet.asJson().toUtf8();
input.m_requestBody.append(output);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
addPetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit addPetErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIPet 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 OAIPetApi::addPetCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIPet output(response);
// Check if callback is provided
OAICallerInfo 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 OAIPetApi::deletePet(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &apiKey = ::OpenAPI::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 OAIPetApi::deletePet(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &apiKey = ::OpenAPI::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 OAIPetApi::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 OAIPetApi::deletePetWithDataImpl(const qint64 &petId, const ::OpenAPI::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 OAIPetApi::deletePetWithDataImpl(const qint64 &petId, const ::OpenAPI::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));
+ setHeader(QHttpHeaders::WellKnownHeader::Authorization, "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(::OpenAPI::toStringValue(petId));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput 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));
+ input.m_headers.replaceOrAppend("api_key"_L1, headerString);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
deletePetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit deletePetErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIPetApi::deletePetCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit deletePetFinished();
}
/**
* \fn virtual void OAIPetApi::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 OAIPetApi::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<OAIPet> &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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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 '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
findPetsByAgeAndPatienceCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByAgeAndPatienceErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<OAIPet> 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 OAIPetApi::findPetsByAgeAndPatienceCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QList<OAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
OAIPet val;
const bool ok = ::OpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to OAIPet.", 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
OAICallerInfo 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 OAIPetApi::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 OAIPetApi::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<OAIPet> &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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
findPetsByStatusCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByStatusErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<OAIPet> 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 OAIPetApi::findPetsByStatusCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QList<OAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
OAIPet val;
const bool ok = ::OpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to OAIPet.", 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
OAICallerInfo 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 OAIPetApi::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 OAIPetApi::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<OAIPet> &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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
findPetsByTagsCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsByTagsErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QList<OAIPet> 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 OAIPetApi::findPetsByTagsCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QList<OAIPet> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isArray()) {
const QJsonArray jsonArray = doc.array();
for (const QJsonValue &obj : jsonArray) {
OAIPet val;
const bool ok = ::OpenAPI::fromJsonValue(val, obj);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to OAIPet.", 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
OAICallerInfo 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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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(::OpenAPI::toStringValue(petId)));
queryParamCounter++;
}
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
findPetsImageByIdCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit findPetsImageByIdErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo 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 OAIPetApi::findPetsImageByIdCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QString output;
const bool ok = ::OpenAPI::fromByteArray(response, output);
if (!ok)
qWarning("%s: Failed to convert the response to QString.", Q_FUNC_INFO);
// Check if callback is provided
OAICallerInfo 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 OAIPetApi::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 OAIPetApi::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 OAIHttpFileElement &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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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(::OpenAPI::toStringValue(petId));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
getJsonFileCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getJsonFileErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIHttpFileElement 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 OAIPetApi::getJsonFileCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
QMap<QString, OAIHttpFileElement> responseFiles;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory, &responseFiles);
OAIHttpFileElement output = OAIHttpRequestWorker::getHttpFileElement(responseFiles);
// Check if callback is provided
OAICallerInfo 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 OAIPetApi::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 OAIPetApi::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 OAIPet &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 OAIPetApi::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 OAIPetApi::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 OAIPetApi::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()));
+ setHeader("api_key"_L1, 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(::OpenAPI::toStringValue(petId));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput input(fullPath, "GET");
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
getPetByIdCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getPetByIdErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIPet 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 OAIPetApi::getPetByIdCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIPet output(response);
// Check if callback is provided
OAICallerInfo 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 OAIPetApi::updatePet(const OAIPet &oAIPet)
* 'updatePet' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIPet OAIPet [required]
*/
/**
* \fn template < Functor, > void OAIPetApi::updatePet(const OAIPet &oAIPet, 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(oAIPet, this, [&](const QRestReply &reply, const OAIPet &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] oAIPet OAIPet [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIPetApi::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 OAIPetApi::updatePetWithDataImpl(const OAIPet &oAIPet, 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] oAIPet OAIPet [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIPetApi::updatePetWithDataImpl(const OAIPet &oAIPet, 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;
OAIHttpRequestInput input(fullPath, "PUT");
input.m_headers.replaceOrAppend(QHttpHeaders::WellKnownHeader::ContentType, "application/json"_L1);
{
QByteArray output = oAIPet.asJson().toUtf8();
input.m_requestBody.append(output);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
updatePetCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit updatePetErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIPet 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 OAIPetApi::updatePetCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIPet output(response);
// Check if callback is provided
OAICallerInfo 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 OAIPetApi::updatePetWithForm(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &name = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<QString> &status = ::OpenAPI::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 OAIPetApi::updatePetWithForm(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &name = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<QString> &status = ::OpenAPI::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 OAIPetApi::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 OAIPetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &name, const ::OpenAPI::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 OAIPetApi::updatePetWithFormWithDataImpl(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &name, const ::OpenAPI::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(::OpenAPI::toStringValue(petId));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput 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, ::OpenAPI::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, ::OpenAPI::serializeMediaTypeContentField(contentType, status.value()));
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
updatePetWithFormCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit updatePetWithFormErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QRestReply restRepl(reply);
void *argv[] = { nullptr, &restRepl };
QObject *context = callerInfo.contextObject ? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
}
});
}
}
void OAIPetApi::updatePetWithFormCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
// Check if callback is provided
OAICallerInfo callerInfo = m_callerData.take(netReply);
if (callerInfo.slot) {
void *argv[] = { nullptr, const_cast<QRestReply*>(&reply) };
QObject *context = callerInfo.contextObject
? const_cast<QObject*>(callerInfo.contextObject) : nullptr;
callerInfo.slot->call(context, argv);
}
emit updatePetWithFormFinished();
}
/**
* \fn virtual void OAIPetApi::uploadFile(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &additionalMetadata = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<OAIHttpFileElement> &file = ::OpenAPI::OptionalParam<OAIHttpFileElement>())
* '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 OAIHttpFileElement [optional]
*/
/**
* \fn template < Functor, > void OAIPetApi::uploadFile(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &additionalMetadata = ::OpenAPI::OptionalParam<QString>(), const ::OpenAPI::OptionalParam<OAIHttpFileElement> &file = ::OpenAPI::OptionalParam<OAIHttpFileElement>(), 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 OAIApiResponse &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 OAIHttpFileElement [optional]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIPetApi::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 OAIPetApi::uploadFileWithDataImpl(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &additionalMetadata, const ::OpenAPI::OptionalParam<OAIHttpFileElement> &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 OAIHttpFileElement [optional]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIPetApi::uploadFileWithDataImpl(const qint64 &petId, const ::OpenAPI::OptionalParam<QString> &additionalMetadata, const ::OpenAPI::OptionalParam<OAIHttpFileElement> &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(::OpenAPI::toStringValue(petId));
// In case style=matrix and paramString is empty due to any reasons,
// we serialize it like undefined value and delete '='.
// Described here: https://spec.openapis.org/oas/v3.1.1.html#style-values
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;
OAIHttpRequestInput 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, ::OpenAPI::serializeMediaTypeContentField(contentType, additionalMetadata.value()));
}
if (file.hasValue()) {
QString contentType;
input.addFile("file", file.value().filename(), contentType);
}
QNetworkRequest request
= OAIHttpRequestWorker::getNetworkRequest(input, m_requestContent, m_networkFactory,
m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
QNetworkReply *reply = execute(input, request, m_requestContent);
if (reply != nullptr) {
reply->setParent(this);
m_callerData.insert(reply, OAICallerInfo{context, slot});
connect(reply, &QNetworkReply::finished, this, [this, reply] {
uploadFileCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit uploadFileErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIApiResponse 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 OAIPetApi::uploadFileCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIApiResponse output(response);
// Check if callback is provided
OAICallerInfo 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 OpenAPI