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/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:9080/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, [&](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("{");
+ orderIdPathParam.append("orderId").append("}");
+ QString pathPrefix, pathSuffix, pathDelimiter;
+ QString pathStyle = "simple";
+ if (pathStyle == "")
+ pathStyle = "simple";
+ pathPrefix = getParamStylePrefix(pathStyle);
+ pathSuffix = getParamStyleSuffix(pathStyle);
+ pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
+
+ QString paramString = (pathStyle == "matrix") ? pathPrefix + "orderId" + pathSuffix : pathPrefix;
+ fullPath.replace(orderIdPathParam, QUrl::toPercentEncoding(paramString + ::OpenAPI::toStringValue(orderId)));
+
+ OAIHttpRequestInput input(fullPath, "DELETE");
+ QByteArray requestContent;
+ QNetworkRequest request
+ = OAIHttpRequestWorker::getNetworkRequest(input, requestContent, m_networkFactory,
+ m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
+ QNetworkReply *reply = execute(input, request, 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)
+ disconnect(netReply, nullptr, nullptr, nullptr);
+ 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, [&](QRestReply &reply, 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()));
+ }
+
+
+ OAIHttpRequestInput input(fullPath, "GET");
+ QByteArray requestContent;
+ QNetworkRequest request
+ = OAIHttpRequestWorker::getNetworkRequest(input, requestContent, m_networkFactory,
+ m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
+ QNetworkReply *reply = execute(input, request, 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)
+ disconnect(netReply, nullptr, nullptr, nullptr);
+ if (!reply.isSuccess())
+ return;
+
+ const QByteArray &response = OAIHttpRequestWorker::parseResponse(reply, m_workingDirectory);
+ QMap<QString, qint32> output;
+ QByteArray array(response.toStdString().c_str());
+ QJsonDocument doc = QJsonDocument::fromJson(array);
+ QJsonObject obj = doc.object();
+ for (const QString &key : obj.keys()) {
+ qint32 val;
+ ::OpenAPI::fromJsonValue(val, obj[key]);
+ output.insert(key, val);
+ }
+ // 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, [&](QRestReply &reply, 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("{");
+ orderIdPathParam.append("orderId").append("}");
+ QString pathPrefix, pathSuffix, pathDelimiter;
+ QString pathStyle = "simple";
+ if (pathStyle == "")
+ pathStyle = "simple";
+ pathPrefix = getParamStylePrefix(pathStyle);
+ pathSuffix = getParamStyleSuffix(pathStyle);
+ pathDelimiter = getParamStyleDelimiter(pathStyle, "orderId", false);
+
+ QString paramString = (pathStyle == "matrix") ? pathPrefix + "orderId" + pathSuffix : pathPrefix;
+ fullPath.replace(orderIdPathParam, QUrl::toPercentEncoding(paramString + ::OpenAPI::toStringValue(orderId)));
+
+ OAIHttpRequestInput input(fullPath, "GET");
+ QByteArray requestContent;
+ QNetworkRequest request
+ = OAIHttpRequestWorker::getNetworkRequest(input, requestContent, m_networkFactory,
+ m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
+ QNetworkReply *reply = execute(input, request, 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)
+ disconnect(netReply, nullptr, nullptr, nullptr);
+ 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, [&](QRestReply &reply, 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);
+
+ OAIHttpRequestInput input(fullPath, "POST");
+ {
+
+ QByteArray output = oAIOrder.asJson().toUtf8();
+ input.m_requestBody.append(output);
+ }
+ QByteArray requestContent;
+ QNetworkRequest request
+ = OAIHttpRequestWorker::getNetworkRequest(input, requestContent, m_networkFactory,
+ m_isResponseCompressionEnabled, m_isRequestCompressionEnabled);
+ QNetworkReply *reply = execute(input, request, 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)
+ disconnect(netReply, nullptr, nullptr, nullptr);
+ 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