Revision control
/**
* OpenAPI Petstore
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* Do not edit the class manually.
*/
#include "OAIStoreApi.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 {
OAIStoreApi::OAIStoreApi(QObject *parent)
: OAIBaseApi(parent)
{
initializeServerConfigs();
}
OAIStoreApi::~OAIStoreApi()
{
}
void OAIStoreApi::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("deleteOrder", defaultConf);
m_serverIndices.insert("deleteOrder", 0);
m_serverConfigs.insert("getInventory", defaultConf);
m_serverIndices.insert("getInventory", 0);
m_serverConfigs.insert("getOrderById", defaultConf);
m_serverIndices.insert("getOrderById", 0);
m_serverConfigs.insert("placeOrder", defaultConf);
m_serverIndices.insert("placeOrder", 0);
}
/**
* \fn virtual void OAIStoreApi::deleteOrder(const QString &orderId)
* 'deleteOrder' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] orderId QString [required]
*/
/**
* \fn template < Functor, > void OAIStoreApi::deleteOrder(const QString &orderId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'deleteOrder' 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++}
* deleteOrder(orderId, 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 deleteOrderWithDataImpl() in derived class.
* The virtual deleteOrderWithDataImpl() is being called by the template
* function.
* @param[in] orderId QString [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIStoreApi::deleteOrderCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by deleteOrderFinished() or
* being returned as a callback parameter of deleteOrder() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void OAIStoreApi::deleteOrderWithDataImpl(const QString &orderId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the deleteOrder() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking deleteOrder() operation calls.
* @param[in] orderId QString [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIStoreApi::deleteOrderWithDataImpl(const QString &orderId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["deleteOrder"][m_serverIndices.value("deleteOrder")].serverUrl();
QString fullPath = "/store/order/{orderId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString orderIdPathParam = QString("{%1}").arg("orderId");
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"orderId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::OpenAPI::toStringValue(orderId));
// 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(orderIdPathParam, paramString);
}
// set m_testOperationPath for serialization tests
m_testOperationPath = fullPath;
OAIHttpRequestInput input(fullPath, "DELETE");
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] {
deleteOrderCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit deleteOrderErrorOccurred(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 OAIStoreApi::deleteOrderCallback(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 deleteOrderFinished();
}
/**
* \fn virtual void OAIStoreApi::getInventory()
* 'getInventory' operation sends the request to a server.
* The request parameters are defined by a specification file.
*/
/**
* \fn template < Functor, > void OAIStoreApi::getInventory(const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getInventory' 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++}
* getInventory(this, [&](const QRestReply &reply, const QMap<QString, qint32> &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 getInventoryWithDataImpl() in derived class.
* The virtual getInventoryWithDataImpl() is being called by the template
* function.
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIStoreApi::getInventoryCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getInventoryFinished() or
* being returned as a callback parameter of getInventory() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void OAIStoreApi::getInventoryWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getInventory() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking getInventory() operation calls.
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIStoreApi::getInventoryWithDataImpl(const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["getInventory"][m_serverIndices.value("getInventory")].serverUrl();
QString fullPath = "/store/inventory";
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());
}
// 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] {
getInventoryCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getInventoryErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
QMap<QString, qint32> 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 OAIStoreApi::getInventoryCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
QMap<QString, qint32> output;
const QJsonDocument doc = QJsonDocument::fromJson(response);
if (!doc.isNull() && doc.isObject()) {
const QJsonObject obj = doc.object();
for (const QString &key : obj.keys()) {
qint32 val;
const bool ok = ::OpenAPI::fromJsonValue(val, obj[key]);
if (!ok)
qWarning("%s: Failed to convert QJsonValue to qint32.", Q_FUNC_INFO);
output.insert(key, val);
}
} else {
qWarning("%s: Failed to parse the response as a JSON object.", Q_FUNC_INFO);
}
// Check if callback is provided
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 getInventoryFinished(output);
}
/**
* \fn virtual void OAIStoreApi::getOrderById(const qint64 &orderId)
* 'getOrderById' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] orderId qint64 [required]
*/
/**
* \fn template < Functor, > void OAIStoreApi::getOrderById(const qint64 &orderId, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'getOrderById' 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++}
* getOrderById(orderId, this, [&](const QRestReply &reply, const OAIOrder &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 getOrderByIdWithDataImpl() in derived class.
* The virtual getOrderByIdWithDataImpl() is being called by the template
* function.
* @param[in] orderId qint64 [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIStoreApi::getOrderByIdCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by getOrderByIdFinished() or
* being returned as a callback parameter of getOrderById() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void OAIStoreApi::getOrderByIdWithDataImpl(const qint64 &orderId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the getOrderById() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking getOrderById() operation calls.
* @param[in] orderId qint64 [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIStoreApi::getOrderByIdWithDataImpl(const qint64 &orderId, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["getOrderById"][m_serverIndices.value("getOrderById")].serverUrl();
QString fullPath = "/store/order/{orderId}";
m_networkFactory->setBaseUrl(serverUrl);
{
QString orderIdPathParam = QString("{%1}").arg("orderId");
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"orderId"_s), flags);
opts.flags = flags;
QString paramString = opts.prefix + opts.suffix;
paramString += QUrl::toPercentEncoding(::OpenAPI::toStringValue(orderId));
// 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(orderIdPathParam, 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] {
getOrderByIdCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit getOrderByIdErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIOrder 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 OAIStoreApi::getOrderByIdCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIOrder 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 getOrderByIdFinished(output);
}
/**
* \fn virtual void OAIStoreApi::placeOrder(const OAIOrder &oAIOrder)
* 'placeOrder' operation sends the request to a server.
* The request parameters are defined by a specification file.
* @param[in] oAIOrder OAIOrder [required]
*/
/**
* \fn template < Functor, > void OAIStoreApi::placeOrder(const OAIOrder &oAIOrder, const ContextTypeForFunctor< Functor > *context = nullptr, Functor &&callback = (){})
* 'placeOrder' 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++}
* placeOrder(oAIOrder, this, [&](const QRestReply &reply, const OAIOrder &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 placeOrderWithDataImpl() in derived class.
* The virtual placeOrderWithDataImpl() is being called by the template
* function.
* @param[in] oAIOrder OAIOrder [required]
* @param[in] context const ContextTypeForFunctor< Functor > * [optional]
* @param[in] callback Functor && [optional]
*/
/**
* \fn void OAIStoreApi::placeOrderCallback(const QRestReply &reply)
* Processes a \a reply response from a server.
* The result of processed data is emitted by placeOrderFinished() or
* being returned as a callback parameter of placeOrder() request.
* @param[in] reply const QRestReply &
*/
/**
* \fn virtual void OAIStoreApi::placeOrderWithDataImpl(const OAIOrder &oAIOrder, const QObject *context, QtPrivate::QSlotObjectBase *slot)
* Implements the placeOrder() operation request.
* \note If 'makeOperationsVirtual' option is true, this function is declared as virtual
* and can be overloaded for mocking placeOrder() operation calls.
* @param[in] oAIOrder OAIOrder [required]
* @param[in] context const QObject * [optional]
* @param[in] slot QtPrivate::QSlotObjectBase * [optional]
*/
void OAIStoreApi::placeOrderWithDataImpl(const OAIOrder &oAIOrder, const QObject *context, QtPrivate::QSlotObjectBase *slot)
{
const QUrl serverUrl = m_serverConfigs["placeOrder"][m_serverIndices.value("placeOrder")].serverUrl();
QString fullPath = "/store/order";
m_networkFactory->setBaseUrl(serverUrl);
// 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 = oAIOrder.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] {
placeOrderCallback(QRestReply(reply));
});
connect(reply, &QNetworkReply::errorOccurred, this, [this, reply] {
if (reply) {
emit placeOrderErrorOccurred(reply->error(), reply->errorString());
OAICallerInfo callerInfo = m_callerData.take(reply);
if (callerInfo.slot) {
OAIOrder 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 OAIStoreApi::placeOrderCallback(const QRestReply &reply)
{
auto netReply = reply.networkReply();
if (netReply)
netReply->disconnect(this);
if (!reply.isSuccess())
return;
const QByteArray response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
OAIOrder 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 placeOrderFinished(output);
}
} // namespace OpenAPI