diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache index 86b1d5affeb..71d4bfdc05c 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/CMakeLists.txt.mustache @@ -12,8 +12,8 @@ else () endif () find_package(Qt5Core REQUIRED) -find_package(Qt5Network REQUIRED){{#authMethods}}{{#isOAuth}} -find_package(Qt5Gui REQUIRED){{/isOAuth}}{{/authMethods}}{{#contentCompression}} +find_package(Qt5Network REQUIRED) +find_package(Qt5Gui REQUIRED){{#contentCompression}} find_package(ZLIB REQUIRED){{/contentCompression}} add_library(${PROJECT_NAME} @@ -34,8 +34,9 @@ add_library(${PROJECT_NAME} {{prefix}}HttpFileElement.cpp {{prefix}}Oauth.cpp ) -target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network{{#authMethods}}{{#isOAuth}} Qt5::Gui{{/isOAuth}}{{/authMethods}}{{#contentCompression}} ${ZLIB_LIBRARIES}{{/contentCompression}}) +target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Gui{{#contentCompression}} ${ZLIB_LIBRARIES}{{/contentCompression}}) if(NOT APPLE) + find_package(OpenSSL REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto) endif() 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 02c3c879cf0..31a65231d9c 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 @@ -820,7 +820,12 @@ void {{classname}}::{{nickname}}Callback({{prefix}}HttpRequestWorker *worker) { foreach (QJsonValue obj, jsonArray) { {{{returnBaseType}}} val; ::{{cppNamespace}}::fromJsonValue(val, obj); + {{#uniqueItems}} + output.insert(val); + {{/uniqueItems}} + {{^uniqueItems}} output.append(val); + {{/uniqueItems}} } {{/isArray}} {{^isArray}} diff --git a/modules/openapi-generator/src/main/resources/cpp-qt-client/object.mustache b/modules/openapi-generator/src/main/resources/cpp-qt-client/object.mustache index 7a68ecc6f74..40a967d517c 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt-client/object.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt-client/object.mustache @@ -50,6 +50,14 @@ private: QJsonObject jObj; }; +inline bool operator==(const {{prefix}}Object& left, const {{prefix}}Object& right){ + return (left.asJsonObject() == right.asJsonObject()); +} + +inline uint qHash(const {{prefix}}Object& obj, uint seed = 0) noexcept{ + return qHash(obj.asJsonObject(), seed); +} + {{#cppNamespaceDeclarations}} } // namespace {{this}} {{/cppNamespaceDeclarations}} 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 7a2627ee86f..2ebd0f893dc 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 @@ -50,6 +50,19 @@ paths: - petstore_auth: - write:pets - read:pets + /pet/all: + get: + summary: Get all pets in an array + operationId: allPets + tags: + - pet + responses: + '200': + description: An array of all pets + content: + application/json: + schema: + $ref: '#/components/schemas/PetArray' /pet/findByStatus: get: tags: @@ -678,6 +691,12 @@ components: - sold xml: name: Pet + PetArray: + title: An Array of pets + type: array + items: + $ref: '#/components/schemas/Pet' + uniqueItems: true ApiResponse: title: An uploaded response description: Describes the result of uploading an image resource diff --git a/samples/client/petstore/cpp-qt/client/CMakeLists.txt b/samples/client/petstore/cpp-qt/client/CMakeLists.txt index 29b96a13aae..5cec7564176 100644 --- a/samples/client/petstore/cpp-qt/client/CMakeLists.txt +++ b/samples/client/petstore/cpp-qt/client/CMakeLists.txt @@ -32,6 +32,7 @@ add_library(${PROJECT_NAME} ) target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Network Qt5::Gui) if(NOT APPLE) + find_package(OpenSSL REQUIRED) target_link_libraries(${PROJECT_NAME} PRIVATE ssl crypto) endif() diff --git a/samples/client/petstore/cpp-qt/client/PFXObject.h b/samples/client/petstore/cpp-qt/client/PFXObject.h index c4be9917a32..e30bee0fd46 100644 --- a/samples/client/petstore/cpp-qt/client/PFXObject.h +++ b/samples/client/petstore/cpp-qt/client/PFXObject.h @@ -58,6 +58,14 @@ private: QJsonObject jObj; }; +inline bool operator==(const PFXObject& left, const PFXObject& right){ + return (left.asJsonObject() == right.asJsonObject()); +} + +inline uint qHash(const PFXObject& obj, uint seed = 0) noexcept{ + return qHash(obj.asJsonObject(), seed); +} + } // namespace test_namespace Q_DECLARE_METATYPE(test_namespace::PFXObject) diff --git a/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp index 584b77042dd..e75cc6afe3c 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt/client/PFXPetApi.cpp @@ -37,6 +37,8 @@ void PFXPetApi::initializeServerConfigs() { QMap())); _serverConfigs.insert("addPet", defaultConf); _serverIndices.insert("addPet", 0); + _serverConfigs.insert("allPets", defaultConf); + _serverIndices.insert("allPets", 0); _serverConfigs.insert("deletePet", defaultConf); _serverIndices.insert("deletePet", 0); _serverConfigs.insert("findPetsByStatus", defaultConf); @@ -318,6 +320,64 @@ void PFXPetApi::addPetCallback(PFXHttpRequestWorker *worker) { } } +void PFXPetApi::allPets() { + QString fullPath = QString(_serverConfigs["allPets"][_serverIndices.value("allPets")].URL()+"/pet/all"); + + PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this, _manager); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); + PFXHttpRequestInput input(fullPath, "GET"); + + +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) { + input.headers.insert(keyValueIt->first, keyValueIt->second); + } +#else + for (auto key : _defaultHeaders.keys()) { + input.headers.insert(key, _defaultHeaders[key]); + } +#endif + + connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::allPetsCallback); + connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater); + connect(worker, &QObject::destroyed, this, [this]() { + if (findChildren().count() == 0) { + emit allPendingRequestsCompleted(); + } + }); + + worker->execute(&input); +} + +void PFXPetApi::allPetsCallback(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)); + } + QSet output; + QString json(worker->response); + QByteArray array(json.toStdString().c_str()); + QJsonDocument doc = QJsonDocument::fromJson(array); + QJsonArray jsonArray = doc.array(); + foreach (QJsonValue obj, jsonArray) { + PFXPet val; + ::test_namespace::fromJsonValue(val, obj); + output.insert(val); + } + worker->deleteLater(); + + if (worker->error_type == QNetworkReply::NoError) { + emit allPetsSignal(output); + emit allPetsSignalFull(worker, output); + } else { + emit allPetsSignalE(output, error_type, error_str); + emit allPetsSignalEFull(worker, error_type, error_str); + } +} + void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::OptionalParam &api_key) { QString fullPath = QString(_serverConfigs["deletePet"][_serverIndices.value("deletePet")].URL()+"/pet/{petId}"); diff --git a/samples/client/petstore/cpp-qt/client/PFXPetApi.h b/samples/client/petstore/cpp-qt/client/PFXPetApi.h index 0f05e6cb746..004050016f9 100644 --- a/samples/client/petstore/cpp-qt/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt/client/PFXPetApi.h @@ -20,6 +20,7 @@ #include "PFXApiResponse.h" #include "PFXHttpFileElement.h" #include "PFXPet.h" +#include #include #include @@ -63,6 +64,9 @@ public: */ void addPet(const PFXPet &pfx_pet); + + void allPets(); + /** * @param[in] pet_id qint64 [required] * @param[in] api_key QString [optional] @@ -127,6 +131,7 @@ private: int _OauthMethod = 0; void addPetCallback(PFXHttpRequestWorker *worker); + void allPetsCallback(PFXHttpRequestWorker *worker); void deletePetCallback(PFXHttpRequestWorker *worker); void findPetsByStatusCallback(PFXHttpRequestWorker *worker); void findPetsByTagsCallback(PFXHttpRequestWorker *worker); @@ -138,6 +143,7 @@ private: signals: void addPetSignal(); + void allPetsSignal(QSet summary); void deletePetSignal(); void findPetsByStatusSignal(QList summary); void findPetsByTagsSignal(QList summary); @@ -147,6 +153,7 @@ signals: void uploadFileSignal(PFXApiResponse summary); void addPetSignalFull(PFXHttpRequestWorker *worker); + void allPetsSignalFull(PFXHttpRequestWorker *worker, QSet summary); void deletePetSignalFull(PFXHttpRequestWorker *worker); void findPetsByStatusSignalFull(PFXHttpRequestWorker *worker, QList summary); void findPetsByTagsSignalFull(PFXHttpRequestWorker *worker, QList summary); @@ -156,6 +163,7 @@ signals: void uploadFileSignalFull(PFXHttpRequestWorker *worker, PFXApiResponse summary); void addPetSignalE(QNetworkReply::NetworkError error_type, QString error_str); + void allPetsSignalE(QSet summary, QNetworkReply::NetworkError error_type, QString error_str); void deletePetSignalE(QNetworkReply::NetworkError error_type, QString error_str); void findPetsByStatusSignalE(QList summary, QNetworkReply::NetworkError error_type, QString error_str); void findPetsByTagsSignalE(QList summary, QNetworkReply::NetworkError error_type, QString error_str); @@ -165,6 +173,7 @@ signals: void uploadFileSignalE(PFXApiResponse summary, QNetworkReply::NetworkError error_type, QString error_str); void addPetSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); + void allPetsSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void deletePetSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void findPetsByStatusSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str); void findPetsByTagsSignalEFull(PFXHttpRequestWorker *worker, QNetworkReply::NetworkError error_type, QString error_str);