diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache index 73b525dcc94c..2a51b5f1d87a 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/api-body.mustache @@ -344,6 +344,21 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} else fullPath.append("?"); {{^isPrimitiveType}} + {{#isEnum}} + // For enum parameters, use direct string serialization instead of object iteration + QString enumValue = {{paramName}}{{^required}}.value(){{/required}}.asJson(); + if (!enumValue.isEmpty()) { + fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append("=").append(QUrl::toPercentEncoding(enumValue)); + } + {{/isEnum}} + {{#isEnumRef}} + // For enum reference parameters, use direct string serialization instead of object iteration + QString enumValue = {{paramName}}{{^required}}.value(){{/required}}.asJson(); + if (!enumValue.isEmpty()) { + fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append("=").append(QUrl::toPercentEncoding(enumValue)); + } + {{/isEnumRef}} + {{^isEnum}}{{^isEnumRef}} QString paramString = (queryStyle == "form" && {{isExplode}}) ? "" : (queryStyle == "form" && !({{isExplode}})) ? "{{baseName}}"+querySuffix : ""; QJsonObject parameter = {{paramName}}{{^required}}.value(){{/required}}.asJsonObject(); qint32 count = 0; @@ -390,6 +405,7 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}} count++; } fullPath.append(paramString); + {{/isEnumRef}}{{/isEnum}} {{/isPrimitiveType}}{{#isPrimitiveType}} fullPath.append(QUrl::toPercentEncoding("{{baseName}}")).append(querySuffix).append(QUrl::toPercentEncoding(::{{cppNamespace}}::toStringValue({{paramName}}{{^required}}.stringValue(){{/required}}))); {{/isPrimitiveType}} diff --git a/modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml b/modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml index ea98eb54e123..d5022849ce5c 100644 --- a/modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml +++ b/modules/openapi-generator/src/test/resources/3_0/cpp-qt/petstore.yaml @@ -572,6 +572,35 @@ paths: description: Invalid username supplied "404": description: User not found + "/fake/enum_inline_or_ref": + get: + tags: + - fake + summary: fake endpoint to test enum (inline or ref) + description: "" + operationId: get_enum_inline_or_ref + parameters: + - name: enum_inline + in: query + description: Enum status inline + schema: + type: string + enum: + - placed + - approved + - delivered + - name: enum_ref + in: query + description: Enum status + schema: + $ref: "#/components/schemas/EnumStatus" + responses: + "200": + description: successful operation + "400": + description: Invalid username supplied + "404": + description: User not found servers: - url: http://petstore.swagger.io/v2 - url: http://localhost:8080/v2 @@ -610,6 +639,13 @@ components: name: api_key in: header schemas: + EnumStatus: + type: string + description: Order Status + enum: + - placed + - approved + - delivered Order: title: Pet Order description: An order for a pets from the pet store diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/FILES b/samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/FILES index 08a3d055d2e4..2c3f246b35cc 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/FILES +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/.openapi-generator/FILES @@ -6,6 +6,10 @@ client/PFXApiResponse.h client/PFXCategory.cpp client/PFXCategory.h client/PFXEnum.h +client/PFXEnumStatus.cpp +client/PFXEnumStatus.h +client/PFXFakeApi.cpp +client/PFXFakeApi.h client/PFXHelpers.cpp client/PFXHelpers.h client/PFXHttpFileElement.cpp diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt b/samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt index 938da937a9cf..b7f29952d04d 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.5) project(cpp-qt-petstore) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/README.md b/samples/client/petstore/cpp-qt-addDownloadProgress/README.md index 55e5efcb2724..b8fdc80bfc3c 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/README.md +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/README.md @@ -27,13 +27,14 @@ example.h: ```c++ #include -#include "../client/PFXPetApi.h" +#include "../client/PFXFakeApi.h" using namespace test_namespace; class Example : public QObject { Q_OBJECT - PFXPet create(); + QString create(); + PFXEnumStatus create(); public Q_SLOTS: void exampleFunction1(); }; @@ -43,32 +44,43 @@ public Q_SLOTS: example.cpp: ```c++ -#include "../client/PFXPetApi.h" +#include "../client/PFXFakeApi.h" #include "example.h" #include #include -PFXPet Example::create(){ - PFXPet obj; +QString Example::create(){ + QString obj; +PFXEnumStatus Example::create(){ + PFXEnumStatus obj; return obj; } void Example::exampleFunction1(){ - PFXPetApi apiInstance; + PFXFakeApi apiInstance; - //OAuth Authentication supported right now + QEventLoop loop; + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignal, [&]() { + loop.quit(); + }); + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignalE, [&](QNetworkReply::NetworkError, QString error_str) { + qDebug() << "Error happened while issuing request : " << error_str; + loop.quit(); + }); + + QString enum_inline = create(); // QString | Enum status inline QEventLoop loop; - connect(&apiInstance, &PFXPetApi::addPetSignal, [&]() { + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignal, [&]() { loop.quit(); }); - connect(&apiInstance, &PFXPetApi::addPetSignalE, [&](QNetworkReply::NetworkError, QString error_str) { + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); - PFXPet pfx_pet = create(); // PFXPet | Pet object that needs to be added to the store - apiInstance.addPet(pfx_pet); + PFXEnumStatus enum_ref = create(); // PFXEnumStatus | Enum status + apiInstance.getEnumInlineOrRef(enum_inlineenum_ref); QTimer::singleShot(5000, &loop, &QEventLoop::quit); loop.exec(); } diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/CMakeLists.txt b/samples/client/petstore/cpp-qt-addDownloadProgress/client/CMakeLists.txt index 51c19e891bd8..2908a8ddc507 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/CMakeLists.txt @@ -13,11 +13,13 @@ include(CMakePackageConfigHelpers) add_library(${PROJECT_NAME} PFXApiResponse.h PFXCategory.h + PFXEnumStatus.h PFXOrder.h PFXPet.h PFXTag.h PFXTestAnyType.h PFXUser.h + PFXFakeApi.h PFXPetApi.h PFXPrimitivesApi.h PFXStoreApi.h @@ -32,11 +34,13 @@ add_library(${PROJECT_NAME} PFXOauth.h PFXApiResponse.cpp PFXCategory.cpp + PFXEnumStatus.cpp PFXOrder.cpp PFXPet.cpp PFXTag.cpp PFXTestAnyType.cpp PFXUser.cpp + PFXFakeApi.cpp PFXPetApi.cpp PFXPrimitivesApi.cpp PFXStoreApi.cpp diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.cpp new file mode 100644 index 000000000000..da7f6d388a38 --- /dev/null +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.cpp @@ -0,0 +1,104 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#include "PFXEnumStatus.h" + +#include +#include +#include +#include + +#include "PFXHelpers.h" + +namespace test_namespace { + +PFXEnumStatus::PFXEnumStatus(QString json) { + this->initializeModel(); + this->fromJson(json); +} + +PFXEnumStatus::PFXEnumStatus() { + this->initializeModel(); +} + +PFXEnumStatus::~PFXEnumStatus() {} + +void PFXEnumStatus::initializeModel() { + + m_value_isSet = false; + m_value_isValid = false; + m_value = ePFXEnumStatus::INVALID_VALUE_OPENAPI_GENERATED; +} + +void PFXEnumStatus::fromJson(QString jsonString) { + + if ( jsonString.compare("placed", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::PLACED; + m_value_isSet = m_value_isValid = true; + } + else if ( jsonString.compare("approved", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::APPROVED; + m_value_isSet = m_value_isValid = true; + } + else if ( jsonString.compare("delivered", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::DELIVERED; + m_value_isSet = m_value_isValid = true; + } +} + +void PFXEnumStatus::fromJsonValue(QJsonValue json) { +fromJson(json.toString()); +} + +QString PFXEnumStatus::asJson() const { + + QString val; + switch (m_value){ + case ePFXEnumStatus::PLACED: + val = "placed"; + break; + case ePFXEnumStatus::APPROVED: + val = "approved"; + break; + case ePFXEnumStatus::DELIVERED: + val = "delivered"; + break; + default: + break; + } + return val; +} + +QJsonValue PFXEnumStatus::asJsonValue() const { + + return QJsonValue(asJson()); +} + + +PFXEnumStatus::ePFXEnumStatus PFXEnumStatus::getValue() const { + return m_value; +} + +void PFXEnumStatus::setValue(const PFXEnumStatus::ePFXEnumStatus& value){ + m_value = value; + m_value_isSet = true; +} +bool PFXEnumStatus::isSet() const { + + return m_value_isSet; +} + +bool PFXEnumStatus::isValid() const { + // only required properties are required for the object to be considered valid + return m_value_isValid; +} + +} // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.h new file mode 100644 index 000000000000..10d787b9e4d9 --- /dev/null +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXEnumStatus.h @@ -0,0 +1,63 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/* + * PFXEnumStatus.h + * + * Order Status + */ + +#ifndef PFXEnumStatus_H +#define PFXEnumStatus_H + +#include + + +#include "PFXEnum.h" +#include "PFXObject.h" + +namespace test_namespace { + +class PFXEnumStatus : public PFXEnum { +public: + PFXEnumStatus(); + PFXEnumStatus(QString json); + ~PFXEnumStatus() override; + + QString asJson() const override; + QJsonValue asJsonValue() const override; + void fromJsonValue(QJsonValue json) override; + void fromJson(QString jsonString) override; + + enum class ePFXEnumStatus { + INVALID_VALUE_OPENAPI_GENERATED = 0, + PLACED, + APPROVED, + DELIVERED + }; + PFXEnumStatus::ePFXEnumStatus getValue() const; + void setValue(const PFXEnumStatus::ePFXEnumStatus& value); + virtual bool isSet() const override; + virtual bool isValid() const override; + +private: + void initializeModel(); + + ePFXEnumStatus m_value; + bool m_value_isSet; + bool m_value_isValid; +}; + +} // namespace test_namespace + +Q_DECLARE_METATYPE(test_namespace::PFXEnumStatus) + +#endif // PFXEnumStatus_H diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp new file mode 100644 index 000000000000..41b2f6793212 --- /dev/null +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.cpp @@ -0,0 +1,366 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#include "PFXFakeApi.h" +#include "PFXServerConfiguration.h" +#include +#include + +namespace test_namespace { + +PFXFakeApi::PFXFakeApi(const int timeOut) + : _timeOut(timeOut), + _manager(nullptr), + _isResponseCompressionEnabled(false), + _isRequestCompressionEnabled(false) { + initializeServerConfigs(); +} + +PFXFakeApi::~PFXFakeApi() { +} + +void PFXFakeApi::initializeServerConfigs() { + //Default server + QList defaultConf = QList(); + //varying endpoint server + defaultConf.append(PFXServerConfiguration( + QUrl("http://petstore.swagger.io/v2"), + "No description provided", + QMap())); + defaultConf.append(PFXServerConfiguration( + QUrl("http://localhost:8080/v2"), + "No description provided", + QMap())); + _serverConfigs.insert("getEnumInlineOrRef", defaultConf); + _serverIndices.insert("getEnumInlineOrRef", 0); +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int PFXFakeApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value) { + auto it = _serverConfigs.find(operation); + if (it != _serverConfigs.end() && serverIndex < it.value().size()) { + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void PFXFakeApi::setServerIndex(const QString &operation, int serverIndex) { + if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) { + _serverIndices[operation] = serverIndex; + } +} + +void PFXFakeApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { + _apiKeys.insert(apiKeyName, apiKey); +} + +void PFXFakeApi::setBearerToken(const QString &token) { + _bearerToken = token; +} + +void PFXFakeApi::setUsername(const QString &username) { + _username = username; +} + +void PFXFakeApi::setPassword(const QString &password) { + _password = password; +} + + +void PFXFakeApi::setTimeOut(const int timeOut) { + _timeOut = timeOut; +} + +void PFXFakeApi::setWorkingDirectory(const QString &path) { + _workingDirectory = path; +} + +void PFXFakeApi::setNetworkAccessManager(QNetworkAccessManager* manager) { + _manager = manager; +} + +/** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int PFXFakeApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { + if (_serverConfigs.contains(operation)) { + _serverConfigs[operation].append(PFXServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + } else { + return -1; + } +} + +/** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXFakeApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables)); + } +} + +/** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXFakeApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); +} + +void PFXFakeApi::addHeaders(const QString &key, const QString &value) { + _defaultHeaders.insert(key, value); +} + +void PFXFakeApi::enableRequestCompression() { + _isRequestCompressionEnabled = true; +} + +void PFXFakeApi::enableResponseCompression() { + _isResponseCompressionEnabled = true; +} + +void PFXFakeApi::abortRequests() { + Q_EMIT abortRequestsSignal(); +} + +QString PFXFakeApi::getParamStylePrefix(const QString &style) { + if (style == "matrix") { + return ";"; + } else if (style == "label") { + return "."; + } else if (style == "form") { + return "&"; + } else if (style == "simple") { + return ""; + } else if (style == "spaceDelimited") { + return "&"; + } else if (style == "pipeDelimited") { + return "&"; + } else { + return "none"; + } +} + +QString PFXFakeApi::getParamStyleSuffix(const QString &style) { + if (style == "matrix") { + return "="; + } else if (style == "label") { + return ""; + } else if (style == "form") { + return "="; + } else if (style == "simple") { + return ""; + } else if (style == "spaceDelimited") { + return "="; + } else if (style == "pipeDelimited") { + return "="; + } else { + return "none"; + } +} + +QString PFXFakeApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) { + + if (style == "matrix") { + return (isExplode) ? ";" + name + "=" : ","; + + } else if (style == "label") { + return (isExplode) ? "." : ","; + + } else if (style == "form") { + return (isExplode) ? "&" + name + "=" : ","; + + } else if (style == "simple") { + return ","; + } else if (style == "spaceDelimited") { + return (isExplode) ? "&" + name + "=" : " "; + + } else if (style == "pipeDelimited") { + return (isExplode) ? "&" + name + "=" : "|"; + + } else if (style == "deepObject") { + return (isExplode) ? "&" : "none"; + + } else { + return "none"; + } +} + +void PFXFakeApi::getEnumInlineOrRef(const ::test_namespace::OptionalParam &enum_inline, const ::test_namespace::OptionalParam &enum_ref) { + QString fullPath = QString(_serverConfigs["getEnumInlineOrRef"][_serverIndices.value("getEnumInlineOrRef")].URL()+"/fake/enum_inline_or_ref"); + + QString queryPrefix, querySuffix, queryDelimiter, queryStyle; + if (enum_inline.hasValue()) + { + queryStyle = "form"; + if (queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "enum_inline", true); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + + fullPath.append(QUrl::toPercentEncoding("enum_inline")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(enum_inline.stringValue()))); + } + if (enum_ref.hasValue()) + { + queryStyle = "form"; + if (queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "enum_ref", true); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + // For enum reference parameters, use direct string serialization instead of object iteration + QString enumValue = enum_ref.value().asJson(); + if (!enumValue.isEmpty()) { + fullPath.append(QUrl::toPercentEncoding("enum_ref")).append("=").append(QUrl::toPercentEncoding(enumValue)); + } + + } + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); + PFXHttpRequestInput input(fullPath, "GET"); + + + for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { + input.headers.insert(keyValueIt->first, keyValueIt->second); + } + + connect(worker, &PFXHttpRequestWorker::downloadProgress, this, &PFXFakeApi::getEnumInlineOrRefProgress); + connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXFakeApi::getEnumInlineOrRefCallback); + connect(this, &PFXFakeApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, this, [this] { + if (findChildren().count() == 0) { + Q_EMIT allPendingRequestsCompleted(); + } + }); + + worker->execute(&input); +} + +void PFXFakeApi::getEnumInlineOrRefCallback(PFXHttpRequestWorker *worker) { + QString error_str = worker->error_str; + QNetworkReply::NetworkError error_type = worker->error_type; + + if (worker->error_type != QNetworkReply::NoError) { + error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); + } + worker->deleteLater(); + + if (worker->error_type == QNetworkReply::NoError) { + Q_EMIT getEnumInlineOrRefSignal(); + Q_EMIT getEnumInlineOrRefSignalFull(worker); + } else { + +#if defined(_MSC_VER) +// For MSVC +#pragma warning(push) +#pragma warning(disable : 4996) +#elif defined(__clang__) +// For Clang +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +// For GCC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + + Q_EMIT getEnumInlineOrRefSignalE(error_type, error_str); + Q_EMIT getEnumInlineOrRefSignalEFull(worker, error_type, error_str); + +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + + Q_EMIT getEnumInlineOrRefSignalError(error_type, error_str); + Q_EMIT getEnumInlineOrRefSignalErrorFull(worker, error_type, error_str); + } +} + +void PFXFakeApi::tokenAvailable(){ + + oauthToken token; + switch (_OauthMethod) { + case 1: //implicit flow + token = _implicitFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _implicitFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 2: //authorization flow + token = _authFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _authFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 3: //client credentials flow + token = _credentialFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _credentialFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 4: //resource owner password flow + token = _passwordFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _credentialFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + default: + qDebug() << "No Oauth method set!"; + break; + } +} +} // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h new file mode 100644 index 000000000000..51bb33fc716d --- /dev/null +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXFakeApi.h @@ -0,0 +1,114 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#ifndef PFX_PFXFakeApi_H +#define PFX_PFXFakeApi_H + +#include "PFXHelpers.h" +#include "PFXHttpRequest.h" +#include "PFXServerConfiguration.h" +#include "PFXOauth.h" + +#include "PFXEnumStatus.h" +#include + +#include +#include +#include +#include +#include + +namespace test_namespace { + +class PFXFakeApi : public QObject { + Q_OBJECT + +public: + PFXFakeApi(const int timeOut = 0); + ~PFXFakeApi(); + + void initializeServerConfigs(); + int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); + void setServerIndex(const QString &operation, int serverIndex); + void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); + void setUsername(const QString &username); + void setPassword(const QString &password); + void setTimeOut(const int timeOut); + void setWorkingDirectory(const QString &path); + void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void addHeaders(const QString &key, const QString &value); + void enableRequestCompression(); + void enableResponseCompression(); + void abortRequests(); + QString getParamStylePrefix(const QString &style); + QString getParamStyleSuffix(const QString &style); + QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode); + + /** + * @param[in] enum_inline QString [optional] + * @param[in] enum_ref PFXEnumStatus [optional] + */ + virtual void getEnumInlineOrRef(const ::test_namespace::OptionalParam &enum_inline = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &enum_ref = ::test_namespace::OptionalParam()); + + +private: + QMap _serverIndices; + QMap> _serverConfigs; + QMap _apiKeys; + QString _bearerToken; + QString _username; + QString _password; + int _timeOut; + QString _workingDirectory; + QNetworkAccessManager* _manager; + QMap _defaultHeaders; + bool _isResponseCompressionEnabled; + bool _isRequestCompressionEnabled; + PFXHttpRequestInput _latestInput; + PFXHttpRequestWorker *_latestWorker; + QStringList _latestScope; + OauthCode _authFlow; + OauthImplicit _implicitFlow; + OauthCredentials _credentialFlow; + OauthPassword _passwordFlow; + int _OauthMethod = 0; + + void getEnumInlineOrRefCallback(PFXHttpRequestWorker *worker); + +Q_SIGNALS: + + void getEnumInlineOrRefSignal(); + + void getEnumInlineOrRefProgress(qint64 bytesReceived, qint64 bytesTotal); + + void getEnumInlineOrRefSignalFull(PFXHttpRequestWorker *worker); + + Q_DECL_DEPRECATED_X("Use getEnumInlineOrRefSignalError() instead") + void getEnumInlineOrRefSignalE(QNetworkReply::NetworkError error_type, QString error_str); + void getEnumInlineOrRefSignalError(QNetworkReply::NetworkError error_type, const QString &error_str); + + Q_DECL_DEPRECATED_X("Use getEnumInlineOrRefSignalErrorFull() instead") + void getEnumInlineOrRefSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); + void getEnumInlineOrRefSignalErrorFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, const QString &error_str); + + void abortRequestsSignal(); + void allPendingRequestsCompleted(); + +public Q_SLOTS: + void tokenAvailable(); +}; + +} // namespace test_namespace +#endif diff --git a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXclient.pri b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXclient.pri index dc65e65de723..c23036722a42 100644 --- a/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXclient.pri +++ b/samples/client/petstore/cpp-qt-addDownloadProgress/client/PFXclient.pri @@ -4,12 +4,14 @@ HEADERS += \ # Models $${PWD}/PFXApiResponse.h \ $${PWD}/PFXCategory.h \ + $${PWD}/PFXEnumStatus.h \ $${PWD}/PFXOrder.h \ $${PWD}/PFXPet.h \ $${PWD}/PFXTag.h \ $${PWD}/PFXTestAnyType.h \ $${PWD}/PFXUser.h \ # APIs + $${PWD}/PFXFakeApi.h \ $${PWD}/PFXPetApi.h \ $${PWD}/PFXPrimitivesApi.h \ $${PWD}/PFXStoreApi.h \ @@ -28,12 +30,14 @@ SOURCES += \ # Models $${PWD}/PFXApiResponse.cpp \ $${PWD}/PFXCategory.cpp \ + $${PWD}/PFXEnumStatus.cpp \ $${PWD}/PFXOrder.cpp \ $${PWD}/PFXPet.cpp \ $${PWD}/PFXTag.cpp \ $${PWD}/PFXTestAnyType.cpp \ $${PWD}/PFXUser.cpp \ # APIs + $${PWD}/PFXFakeApi.cpp \ $${PWD}/PFXPetApi.cpp \ $${PWD}/PFXPrimitivesApi.cpp \ $${PWD}/PFXStoreApi.cpp \ diff --git a/samples/client/petstore/cpp-qt/.openapi-generator/FILES b/samples/client/petstore/cpp-qt/.openapi-generator/FILES index 08a3d055d2e4..2c3f246b35cc 100644 --- a/samples/client/petstore/cpp-qt/.openapi-generator/FILES +++ b/samples/client/petstore/cpp-qt/.openapi-generator/FILES @@ -6,6 +6,10 @@ client/PFXApiResponse.h client/PFXCategory.cpp client/PFXCategory.h client/PFXEnum.h +client/PFXEnumStatus.cpp +client/PFXEnumStatus.h +client/PFXFakeApi.cpp +client/PFXFakeApi.h client/PFXHelpers.cpp client/PFXHelpers.h client/PFXHttpFileElement.cpp diff --git a/samples/client/petstore/cpp-qt/CMakeLists.txt b/samples/client/petstore/cpp-qt/CMakeLists.txt index 938da937a9cf..b7f29952d04d 100644 --- a/samples/client/petstore/cpp-qt/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.2) +cmake_minimum_required(VERSION 3.5) project(cpp-qt-petstore) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/samples/client/petstore/cpp-qt/README.md b/samples/client/petstore/cpp-qt/README.md index 55e5efcb2724..b8fdc80bfc3c 100644 --- a/samples/client/petstore/cpp-qt/README.md +++ b/samples/client/petstore/cpp-qt/README.md @@ -27,13 +27,14 @@ example.h: ```c++ #include -#include "../client/PFXPetApi.h" +#include "../client/PFXFakeApi.h" using namespace test_namespace; class Example : public QObject { Q_OBJECT - PFXPet create(); + QString create(); + PFXEnumStatus create(); public Q_SLOTS: void exampleFunction1(); }; @@ -43,32 +44,43 @@ public Q_SLOTS: example.cpp: ```c++ -#include "../client/PFXPetApi.h" +#include "../client/PFXFakeApi.h" #include "example.h" #include #include -PFXPet Example::create(){ - PFXPet obj; +QString Example::create(){ + QString obj; +PFXEnumStatus Example::create(){ + PFXEnumStatus obj; return obj; } void Example::exampleFunction1(){ - PFXPetApi apiInstance; + PFXFakeApi apiInstance; - //OAuth Authentication supported right now + QEventLoop loop; + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignal, [&]() { + loop.quit(); + }); + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignalE, [&](QNetworkReply::NetworkError, QString error_str) { + qDebug() << "Error happened while issuing request : " << error_str; + loop.quit(); + }); + + QString enum_inline = create(); // QString | Enum status inline QEventLoop loop; - connect(&apiInstance, &PFXPetApi::addPetSignal, [&]() { + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignal, [&]() { loop.quit(); }); - connect(&apiInstance, &PFXPetApi::addPetSignalE, [&](QNetworkReply::NetworkError, QString error_str) { + connect(&apiInstance, &PFXFakeApi::getEnumInlineOrRefSignalE, [&](QNetworkReply::NetworkError, QString error_str) { qDebug() << "Error happened while issuing request : " << error_str; loop.quit(); }); - PFXPet pfx_pet = create(); // PFXPet | Pet object that needs to be added to the store - apiInstance.addPet(pfx_pet); + PFXEnumStatus enum_ref = create(); // PFXEnumStatus | Enum status + apiInstance.getEnumInlineOrRef(enum_inlineenum_ref); QTimer::singleShot(5000, &loop, &QEventLoop::quit); loop.exec(); } diff --git a/samples/client/petstore/cpp-qt/client/CMakeLists.txt b/samples/client/petstore/cpp-qt/client/CMakeLists.txt index 51c19e891bd8..2908a8ddc507 100644 --- a/samples/client/petstore/cpp-qt/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt/client/CMakeLists.txt @@ -13,11 +13,13 @@ include(CMakePackageConfigHelpers) add_library(${PROJECT_NAME} PFXApiResponse.h PFXCategory.h + PFXEnumStatus.h PFXOrder.h PFXPet.h PFXTag.h PFXTestAnyType.h PFXUser.h + PFXFakeApi.h PFXPetApi.h PFXPrimitivesApi.h PFXStoreApi.h @@ -32,11 +34,13 @@ add_library(${PROJECT_NAME} PFXOauth.h PFXApiResponse.cpp PFXCategory.cpp + PFXEnumStatus.cpp PFXOrder.cpp PFXPet.cpp PFXTag.cpp PFXTestAnyType.cpp PFXUser.cpp + PFXFakeApi.cpp PFXPetApi.cpp PFXPrimitivesApi.cpp PFXStoreApi.cpp diff --git a/samples/client/petstore/cpp-qt/client/PFXEnumStatus.cpp b/samples/client/petstore/cpp-qt/client/PFXEnumStatus.cpp new file mode 100644 index 000000000000..da7f6d388a38 --- /dev/null +++ b/samples/client/petstore/cpp-qt/client/PFXEnumStatus.cpp @@ -0,0 +1,104 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#include "PFXEnumStatus.h" + +#include +#include +#include +#include + +#include "PFXHelpers.h" + +namespace test_namespace { + +PFXEnumStatus::PFXEnumStatus(QString json) { + this->initializeModel(); + this->fromJson(json); +} + +PFXEnumStatus::PFXEnumStatus() { + this->initializeModel(); +} + +PFXEnumStatus::~PFXEnumStatus() {} + +void PFXEnumStatus::initializeModel() { + + m_value_isSet = false; + m_value_isValid = false; + m_value = ePFXEnumStatus::INVALID_VALUE_OPENAPI_GENERATED; +} + +void PFXEnumStatus::fromJson(QString jsonString) { + + if ( jsonString.compare("placed", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::PLACED; + m_value_isSet = m_value_isValid = true; + } + else if ( jsonString.compare("approved", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::APPROVED; + m_value_isSet = m_value_isValid = true; + } + else if ( jsonString.compare("delivered", Qt::CaseInsensitive) == 0) { + m_value = ePFXEnumStatus::DELIVERED; + m_value_isSet = m_value_isValid = true; + } +} + +void PFXEnumStatus::fromJsonValue(QJsonValue json) { +fromJson(json.toString()); +} + +QString PFXEnumStatus::asJson() const { + + QString val; + switch (m_value){ + case ePFXEnumStatus::PLACED: + val = "placed"; + break; + case ePFXEnumStatus::APPROVED: + val = "approved"; + break; + case ePFXEnumStatus::DELIVERED: + val = "delivered"; + break; + default: + break; + } + return val; +} + +QJsonValue PFXEnumStatus::asJsonValue() const { + + return QJsonValue(asJson()); +} + + +PFXEnumStatus::ePFXEnumStatus PFXEnumStatus::getValue() const { + return m_value; +} + +void PFXEnumStatus::setValue(const PFXEnumStatus::ePFXEnumStatus& value){ + m_value = value; + m_value_isSet = true; +} +bool PFXEnumStatus::isSet() const { + + return m_value_isSet; +} + +bool PFXEnumStatus::isValid() const { + // only required properties are required for the object to be considered valid + return m_value_isValid; +} + +} // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt/client/PFXEnumStatus.h b/samples/client/petstore/cpp-qt/client/PFXEnumStatus.h new file mode 100644 index 000000000000..10d787b9e4d9 --- /dev/null +++ b/samples/client/petstore/cpp-qt/client/PFXEnumStatus.h @@ -0,0 +1,63 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/* + * PFXEnumStatus.h + * + * Order Status + */ + +#ifndef PFXEnumStatus_H +#define PFXEnumStatus_H + +#include + + +#include "PFXEnum.h" +#include "PFXObject.h" + +namespace test_namespace { + +class PFXEnumStatus : public PFXEnum { +public: + PFXEnumStatus(); + PFXEnumStatus(QString json); + ~PFXEnumStatus() override; + + QString asJson() const override; + QJsonValue asJsonValue() const override; + void fromJsonValue(QJsonValue json) override; + void fromJson(QString jsonString) override; + + enum class ePFXEnumStatus { + INVALID_VALUE_OPENAPI_GENERATED = 0, + PLACED, + APPROVED, + DELIVERED + }; + PFXEnumStatus::ePFXEnumStatus getValue() const; + void setValue(const PFXEnumStatus::ePFXEnumStatus& value); + virtual bool isSet() const override; + virtual bool isValid() const override; + +private: + void initializeModel(); + + ePFXEnumStatus m_value; + bool m_value_isSet; + bool m_value_isValid; +}; + +} // namespace test_namespace + +Q_DECLARE_METATYPE(test_namespace::PFXEnumStatus) + +#endif // PFXEnumStatus_H diff --git a/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp b/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp new file mode 100644 index 000000000000..e31b35d4b66c --- /dev/null +++ b/samples/client/petstore/cpp-qt/client/PFXFakeApi.cpp @@ -0,0 +1,366 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#include "PFXFakeApi.h" +#include "PFXServerConfiguration.h" +#include +#include + +namespace test_namespace { + +PFXFakeApi::PFXFakeApi(const int timeOut) + : _timeOut(timeOut), + _manager(nullptr), + _isResponseCompressionEnabled(false), + _isRequestCompressionEnabled(false) { + initializeServerConfigs(); +} + +PFXFakeApi::~PFXFakeApi() { +} + +void PFXFakeApi::initializeServerConfigs() { + //Default server + QList defaultConf = QList(); + //varying endpoint server + defaultConf.append(PFXServerConfiguration( + QUrl("http://petstore.swagger.io/v2"), + "No description provided", + QMap())); + defaultConf.append(PFXServerConfiguration( + QUrl("http://localhost:8080/v2"), + "No description provided", + QMap())); + _serverConfigs.insert("getEnumInlineOrRef", defaultConf); + _serverIndices.insert("getEnumInlineOrRef", 0); +} + +/** +* returns 0 on success and -1, -2 or -3 on failure. +* -1 when the variable does not exist and -2 if the value is not defined in the enum and -3 if the operation or server index is not found +*/ +int PFXFakeApi::setDefaultServerValue(int serverIndex, const QString &operation, const QString &variable, const QString &value) { + auto it = _serverConfigs.find(operation); + if (it != _serverConfigs.end() && serverIndex < it.value().size()) { + return _serverConfigs[operation][serverIndex].setDefaultValue(variable,value); + } + return -3; +} +void PFXFakeApi::setServerIndex(const QString &operation, int serverIndex) { + if (_serverIndices.contains(operation) && serverIndex < _serverConfigs.find(operation).value().size()) { + _serverIndices[operation] = serverIndex; + } +} + +void PFXFakeApi::setApiKey(const QString &apiKeyName, const QString &apiKey) { + _apiKeys.insert(apiKeyName, apiKey); +} + +void PFXFakeApi::setBearerToken(const QString &token) { + _bearerToken = token; +} + +void PFXFakeApi::setUsername(const QString &username) { + _username = username; +} + +void PFXFakeApi::setPassword(const QString &password) { + _password = password; +} + + +void PFXFakeApi::setTimeOut(const int timeOut) { + _timeOut = timeOut; +} + +void PFXFakeApi::setWorkingDirectory(const QString &path) { + _workingDirectory = path; +} + +void PFXFakeApi::setNetworkAccessManager(QNetworkAccessManager* manager) { + _manager = manager; +} + +/** + * Appends a new ServerConfiguration to the config map for a specific operation. + * @param operation The id to the target operation. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + * returns the index of the new server config on success and -1 if the operation is not found + */ +int PFXFakeApi::addServerConfiguration(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { + if (_serverConfigs.contains(operation)) { + _serverConfigs[operation].append(PFXServerConfiguration( + url, + description, + variables)); + return _serverConfigs[operation].size()-1; + } else { + return -1; + } +} + +/** + * Appends a new ServerConfiguration to the config map for a all operations and sets the index to that server. + * @param url A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXFakeApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap &variables) { + for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) { + setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables)); + } +} + +/** + * Appends a new ServerConfiguration to the config map for an operations and sets the index to that server. + * @param URL A string that contains the URL of the server + * @param description A String that describes the server + * @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template. + */ +void PFXFakeApi::setNewServer(const QString &operation, const QUrl &url, const QString &description, const QMap &variables) { + setServerIndex(operation, addServerConfiguration(operation, url, description, variables)); +} + +void PFXFakeApi::addHeaders(const QString &key, const QString &value) { + _defaultHeaders.insert(key, value); +} + +void PFXFakeApi::enableRequestCompression() { + _isRequestCompressionEnabled = true; +} + +void PFXFakeApi::enableResponseCompression() { + _isResponseCompressionEnabled = true; +} + +void PFXFakeApi::abortRequests() { + Q_EMIT abortRequestsSignal(); +} + +QString PFXFakeApi::getParamStylePrefix(const QString &style) { + if (style == "matrix") { + return ";"; + } else if (style == "label") { + return "."; + } else if (style == "form") { + return "&"; + } else if (style == "simple") { + return ""; + } else if (style == "spaceDelimited") { + return "&"; + } else if (style == "pipeDelimited") { + return "&"; + } else { + return "none"; + } +} + +QString PFXFakeApi::getParamStyleSuffix(const QString &style) { + if (style == "matrix") { + return "="; + } else if (style == "label") { + return ""; + } else if (style == "form") { + return "="; + } else if (style == "simple") { + return ""; + } else if (style == "spaceDelimited") { + return "="; + } else if (style == "pipeDelimited") { + return "="; + } else { + return "none"; + } +} + +QString PFXFakeApi::getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode) { + + if (style == "matrix") { + return (isExplode) ? ";" + name + "=" : ","; + + } else if (style == "label") { + return (isExplode) ? "." : ","; + + } else if (style == "form") { + return (isExplode) ? "&" + name + "=" : ","; + + } else if (style == "simple") { + return ","; + } else if (style == "spaceDelimited") { + return (isExplode) ? "&" + name + "=" : " "; + + } else if (style == "pipeDelimited") { + return (isExplode) ? "&" + name + "=" : "|"; + + } else if (style == "deepObject") { + return (isExplode) ? "&" : "none"; + + } else { + return "none"; + } +} + +void PFXFakeApi::getEnumInlineOrRef(const ::test_namespace::OptionalParam &enum_inline, const ::test_namespace::OptionalParam &enum_ref) { + QString fullPath = QString(_serverConfigs["getEnumInlineOrRef"][_serverIndices.value("getEnumInlineOrRef")].URL()+"/fake/enum_inline_or_ref"); + + QString queryPrefix, querySuffix, queryDelimiter, queryStyle; + if (enum_inline.hasValue()) + { + queryStyle = "form"; + if (queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "enum_inline", true); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + + fullPath.append(QUrl::toPercentEncoding("enum_inline")).append(querySuffix).append(QUrl::toPercentEncoding(::test_namespace::toStringValue(enum_inline.stringValue()))); + } + if (enum_ref.hasValue()) + { + queryStyle = "form"; + if (queryStyle == "") + queryStyle = "form"; + queryPrefix = getParamStylePrefix(queryStyle); + querySuffix = getParamStyleSuffix(queryStyle); + queryDelimiter = getParamStyleDelimiter(queryStyle, "enum_ref", true); + if (fullPath.indexOf("?") > 0) + fullPath.append(queryPrefix); + else + fullPath.append("?"); + // For enum reference parameters, use direct string serialization instead of object iteration + QString enumValue = enum_ref.value().asJson(); + if (!enumValue.isEmpty()) { + fullPath.append(QUrl::toPercentEncoding("enum_ref")).append("=").append(QUrl::toPercentEncoding(enumValue)); + } + + } + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); + PFXHttpRequestInput input(fullPath, "GET"); + + + for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { + input.headers.insert(keyValueIt->first, keyValueIt->second); + } + + + connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXFakeApi::getEnumInlineOrRefCallback); + connect(this, &PFXFakeApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, this, [this] { + if (findChildren().count() == 0) { + Q_EMIT allPendingRequestsCompleted(); + } + }); + + worker->execute(&input); +} + +void PFXFakeApi::getEnumInlineOrRefCallback(PFXHttpRequestWorker *worker) { + QString error_str = worker->error_str; + QNetworkReply::NetworkError error_type = worker->error_type; + + if (worker->error_type != QNetworkReply::NoError) { + error_str = QString("%1, %2").arg(worker->error_str, QString(worker->response)); + } + worker->deleteLater(); + + if (worker->error_type == QNetworkReply::NoError) { + Q_EMIT getEnumInlineOrRefSignal(); + Q_EMIT getEnumInlineOrRefSignalFull(worker); + } else { + +#if defined(_MSC_VER) +// For MSVC +#pragma warning(push) +#pragma warning(disable : 4996) +#elif defined(__clang__) +// For Clang +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +// For GCC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + + Q_EMIT getEnumInlineOrRefSignalE(error_type, error_str); + Q_EMIT getEnumInlineOrRefSignalEFull(worker, error_type, error_str); + +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif + + Q_EMIT getEnumInlineOrRefSignalError(error_type, error_str); + Q_EMIT getEnumInlineOrRefSignalErrorFull(worker, error_type, error_str); + } +} + +void PFXFakeApi::tokenAvailable(){ + + oauthToken token; + switch (_OauthMethod) { + case 1: //implicit flow + token = _implicitFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _implicitFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 2: //authorization flow + token = _authFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _authFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 3: //client credentials flow + token = _credentialFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _credentialFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + case 4: //resource owner password flow + token = _passwordFlow.getToken(_latestScope.join(" ")); + if(token.isValid()){ + _latestInput.headers.insert("Authorization", "Bearer " + token.getToken()); + _latestWorker->execute(&_latestInput); + }else{ + _credentialFlow.removeToken(_latestScope.join(" ")); + qDebug() << "Could not retrieve a valid token"; + } + break; + default: + qDebug() << "No Oauth method set!"; + break; + } +} +} // namespace test_namespace diff --git a/samples/client/petstore/cpp-qt/client/PFXFakeApi.h b/samples/client/petstore/cpp-qt/client/PFXFakeApi.h new file mode 100644 index 000000000000..0b4e100065ad --- /dev/null +++ b/samples/client/petstore/cpp-qt/client/PFXFakeApi.h @@ -0,0 +1,113 @@ +/** + * OpenAPI Petstore + * This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + * + * The version of the OpenAPI document: 1.0.0 + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +#ifndef PFX_PFXFakeApi_H +#define PFX_PFXFakeApi_H + +#include "PFXHelpers.h" +#include "PFXHttpRequest.h" +#include "PFXServerConfiguration.h" +#include "PFXOauth.h" + +#include "PFXEnumStatus.h" +#include + +#include +#include +#include +#include +#include + +namespace test_namespace { + +class PFXFakeApi : public QObject { + Q_OBJECT + +public: + PFXFakeApi(const int timeOut = 0); + ~PFXFakeApi(); + + void initializeServerConfigs(); + int setDefaultServerValue(int serverIndex,const QString &operation, const QString &variable,const QString &val); + void setServerIndex(const QString &operation, int serverIndex); + void setApiKey(const QString &apiKeyName, const QString &apiKey); + void setBearerToken(const QString &token); + void setUsername(const QString &username); + void setPassword(const QString &password); + void setTimeOut(const int timeOut); + void setWorkingDirectory(const QString &path); + void setNetworkAccessManager(QNetworkAccessManager* manager); + int addServerConfiguration(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServerForAllOperations(const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void setNewServer(const QString &operation, const QUrl &url, const QString &description = "", const QMap &variables = QMap()); + void addHeaders(const QString &key, const QString &value); + void enableRequestCompression(); + void enableResponseCompression(); + void abortRequests(); + QString getParamStylePrefix(const QString &style); + QString getParamStyleSuffix(const QString &style); + QString getParamStyleDelimiter(const QString &style, const QString &name, bool isExplode); + + /** + * @param[in] enum_inline QString [optional] + * @param[in] enum_ref PFXEnumStatus [optional] + */ + virtual void getEnumInlineOrRef(const ::test_namespace::OptionalParam &enum_inline = ::test_namespace::OptionalParam(), const ::test_namespace::OptionalParam &enum_ref = ::test_namespace::OptionalParam()); + + +private: + QMap _serverIndices; + QMap> _serverConfigs; + QMap _apiKeys; + QString _bearerToken; + QString _username; + QString _password; + int _timeOut; + QString _workingDirectory; + QNetworkAccessManager* _manager; + QMap _defaultHeaders; + bool _isResponseCompressionEnabled; + bool _isRequestCompressionEnabled; + PFXHttpRequestInput _latestInput; + PFXHttpRequestWorker *_latestWorker; + QStringList _latestScope; + OauthCode _authFlow; + OauthImplicit _implicitFlow; + OauthCredentials _credentialFlow; + OauthPassword _passwordFlow; + int _OauthMethod = 0; + + void getEnumInlineOrRefCallback(PFXHttpRequestWorker *worker); + +Q_SIGNALS: + + void getEnumInlineOrRefSignal(); + + + void getEnumInlineOrRefSignalFull(PFXHttpRequestWorker *worker); + + Q_DECL_DEPRECATED_X("Use getEnumInlineOrRefSignalError() instead") + void getEnumInlineOrRefSignalE(QNetworkReply::NetworkError error_type, QString error_str); + void getEnumInlineOrRefSignalError(QNetworkReply::NetworkError error_type, const QString &error_str); + + Q_DECL_DEPRECATED_X("Use getEnumInlineOrRefSignalErrorFull() instead") + void getEnumInlineOrRefSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); + void getEnumInlineOrRefSignalErrorFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, const QString &error_str); + + void abortRequestsSignal(); + void allPendingRequestsCompleted(); + +public Q_SLOTS: + void tokenAvailable(); +}; + +} // namespace test_namespace +#endif diff --git a/samples/client/petstore/cpp-qt/client/PFXclient.pri b/samples/client/petstore/cpp-qt/client/PFXclient.pri index dc65e65de723..c23036722a42 100644 --- a/samples/client/petstore/cpp-qt/client/PFXclient.pri +++ b/samples/client/petstore/cpp-qt/client/PFXclient.pri @@ -4,12 +4,14 @@ HEADERS += \ # Models $${PWD}/PFXApiResponse.h \ $${PWD}/PFXCategory.h \ + $${PWD}/PFXEnumStatus.h \ $${PWD}/PFXOrder.h \ $${PWD}/PFXPet.h \ $${PWD}/PFXTag.h \ $${PWD}/PFXTestAnyType.h \ $${PWD}/PFXUser.h \ # APIs + $${PWD}/PFXFakeApi.h \ $${PWD}/PFXPetApi.h \ $${PWD}/PFXPrimitivesApi.h \ $${PWD}/PFXStoreApi.h \ @@ -28,12 +30,14 @@ SOURCES += \ # Models $${PWD}/PFXApiResponse.cpp \ $${PWD}/PFXCategory.cpp \ + $${PWD}/PFXEnumStatus.cpp \ $${PWD}/PFXOrder.cpp \ $${PWD}/PFXPet.cpp \ $${PWD}/PFXTag.cpp \ $${PWD}/PFXTestAnyType.cpp \ $${PWD}/PFXUser.cpp \ # APIs + $${PWD}/PFXFakeApi.cpp \ $${PWD}/PFXPetApi.cpp \ $${PWD}/PFXPrimitivesApi.cpp \ $${PWD}/PFXStoreApi.cpp \