From 1b7973404d948df7b7d2e1efd89fe602b338e951 Mon Sep 17 00:00:00 2001 From: philicious Date: Fri, 10 Jun 2016 13:06:53 +0200 Subject: [PATCH 1/6] added missing data-type handlers for QDate and QDateTime in Qt5/CPP helpers --- .../resources/qt5cpp/helpers-body.mustache | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache index 6b439996724d..dfa28c8b3bff 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -53,6 +53,46 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { qDebug() << "Can't set value because the target pointer is NULL"; } } + else if (QStringLiteral("QDateTime").compare(type) == 0) { + QDateTime **val = static_cast(value); + + if(val != NULL) { + if(!obj.isNull()) { + // create a new value and return + delete *val; + *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); + return; + } + else { + // set target to NULL + delete *val; + *val = NULL; + } + } + else { + qDebug() << "Can't set value because the target pointer is NULL"; + } + } + else if (QStringLiteral("QDate").compare(type) == 0) { + QDate **val = static_cast(value); + + if(val != NULL) { + if(!obj.isNull()) { + // create a new value and return + delete *val; + *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); + return; + } + else { + // set target to NULL + delete *val; + *val = NULL; + } + } + else { + qDebug() << "Can't set value because the target pointer is NULL"; + } + } else if(type.startsWith("SWG") && obj.isObject()) { // complex type QJsonObject jsonObj = obj.toObject(); @@ -104,6 +144,21 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); output->append((void*)&val); } + else if(QStringLiteral("QString").compare(complexType) == 0) { + QString val; + setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("QDate").compare(complexType) == 0) { + QDate val; + setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("QDateTime").compare(complexType) == 0) { + QDateTime val; + setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); + output->append((void*)&val); + } } } QList **val = static_cast**>(value); @@ -139,23 +194,31 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { } else if(QStringLiteral("qint32").compare(type) == 0) { qint32* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint64").compare(type) == 0) { qint64* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("bool").compare(type) == 0) { bool* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("float").compare(type) == 0) { float* str = static_cast(value); - output->insert(name, QJsonValue((double)*str)); + output->insert(name, QJsonValue((double)*str)); } else if(QStringLiteral("double").compare(type) == 0) { double* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); + } + else if(QStringLiteral("QDate").compare(type) == 0) { + QDate* date = static_cast(value); + output->insert(name, QJsonValue(date->toString(Qt::ISODate))); + } + else if(QStringLiteral("QDateTime").compare(type) == 0) { + QDateTime* datetime = static_cast(value); + output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); } } From 8fab73fff6a117da7bb67087985a6efeb49091fa Mon Sep 17 00:00:00 2001 From: philicious Date: Mon, 13 Jun 2016 23:52:13 +0200 Subject: [PATCH 2/6] added missing systemIncludes for QMap, QDateTime, QDate --- .../java/io/swagger/codegen/languages/Qt5CPPGenerator.java | 3 +++ samples/client/petstore/qt5cpp/client/SWGOrder.h | 2 +- samples/client/petstore/qt5cpp/client/SWGStoreApi.h | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java index aa32eb4e5100..6b5be9fafe13 100644 --- a/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java +++ b/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java @@ -135,6 +135,9 @@ public class Qt5CPPGenerator extends DefaultCodegen implements CodegenConfig { systemIncludes.add("QString"); systemIncludes.add("QList"); + systemIncludes.add("QMap"); + systemIncludes.add("QDate"); + systemIncludes.add("QDateTime"); } /** diff --git a/samples/client/petstore/qt5cpp/client/SWGOrder.h b/samples/client/petstore/qt5cpp/client/SWGOrder.h index fd3855000eae..c355ac5c4519 100644 --- a/samples/client/petstore/qt5cpp/client/SWGOrder.h +++ b/samples/client/petstore/qt5cpp/client/SWGOrder.h @@ -10,7 +10,7 @@ #include -#include "QDateTime.h" +#include #include #include "SWGObject.h" diff --git a/samples/client/petstore/qt5cpp/client/SWGStoreApi.h b/samples/client/petstore/qt5cpp/client/SWGStoreApi.h index a90a297499cf..a12c056ced1f 100644 --- a/samples/client/petstore/qt5cpp/client/SWGStoreApi.h +++ b/samples/client/petstore/qt5cpp/client/SWGStoreApi.h @@ -4,7 +4,7 @@ #include "SWGHttpRequest.h" #include -#include "QMap.h" +#include #include "SWGOrder.h" #include From 6f85deeecd229621933c8e33df945ccb290fb94d Mon Sep 17 00:00:00 2001 From: philicious Date: Mon, 13 Jun 2016 23:53:01 +0200 Subject: [PATCH 3/6] added missing source/header for SWGApiResponse in Makefile --- samples/client/petstore/qt5cpp/PetStore/PetStore.pro | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro index 70b3618cba63..64f27a3c9249 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetStore.pro +++ b/samples/client/petstore/qt5cpp/PetStore/PetStore.pro @@ -28,6 +28,7 @@ SOURCES += main.cpp \ ../client/SWGTag.cpp \ ../client/SWGUser.cpp \ ../client/SWGUserApi.cpp \ + ../client/SWGApiResponse.cpp \ PetApiTests.cpp HEADERS += \ @@ -43,4 +44,5 @@ HEADERS += \ ../client/SWGUser.h \ ../client/SWGUserApi.h \ PetApiTests.h \ + ../client/SWGApiResponse.h \ ../client/SWGModelFactory.h From 511971cf679531a85021ad21b37133f9fb7ea910 Mon Sep 17 00:00:00 2001 From: philicious Date: Mon, 13 Jun 2016 23:54:27 +0200 Subject: [PATCH 4/6] fixed wrong function parameter type in PetApiTest.cpp --- samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp index e2d0ffb5d379..4b1d5f5cd5fe 100644 --- a/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp +++ b/samples/client/petstore/qt5cpp/PetStore/PetApiTests.cpp @@ -228,7 +228,7 @@ void PetApiTests::updatePetWithFormTest() { connect(api, &SWGPetApi::updatePetWithFormSignal, this, [](){loop.quit();}); connect(&timer, &QTimer::timeout, &loop, &QEventLoop::quit); - api->updatePetWithForm(new QString(QString::number(id)), new QString("gorilla"), NULL); + api->updatePetWithForm(id, new QString("gorilla"), NULL); timer.start(); loop.exec(); QVERIFY2(timer.isActive(), "didn't finish within timeout"); From 9825dfc735d77bab075786a4150b10a587181c05 Mon Sep 17 00:00:00 2001 From: philicious Date: Tue, 14 Jun 2016 00:13:12 +0200 Subject: [PATCH 5/6] fixed Qt5 api-body template bug with form params --- .../swagger-codegen/src/main/resources/qt5cpp/api-body.mustache | 2 +- samples/client/petstore/qt5cpp/client/SWGPetApi.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache index fc69cfa44047..544706e8a4e3 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache @@ -87,7 +87,7 @@ void HttpRequestInput input(fullPath, "{{httpMethod}}"); {{#formParams}}if ({{paramName}} != NULL) { - {{^isFile}}input.add_var("{{paramName}}", *{{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{paramName}}", *{{paramName}}.local_filename, *{{paramName}}.request_filename, *{{paramName}}.mime_type);{{/isFile}} + {{^isFile}}input.add_var("{{paramName}}", *{{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{paramName}}", (*{{paramName}}).local_filename, (*{{paramName}}).request_filename, (*{{paramName}}).mime_type);{{/isFile}} } {{/formParams}} diff --git a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp index b5e383575beb..c5ac6513dce5 100644 --- a/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGPetApi.cpp @@ -438,7 +438,7 @@ SWGPetApi::uploadFile(qint64 petId, QString* additionalMetadata, SWGHttpRequestI input.add_var("additionalMetadata", *additionalMetadata); } if (file != NULL) { - input.add_file("file", *file.local_filename, *file.request_filename, *file.mime_type); + input.add_file("file", (*file).local_filename, (*file).request_filename, (*file).mime_type); } From 691ef883330bec82508835014bd996a7323ad101 Mon Sep 17 00:00:00 2001 From: philicious Date: Tue, 14 Jun 2016 00:15:39 +0200 Subject: [PATCH 6/6] updated SWGHelpers in tests with output from 1b79734 --- .../petstore/qt5cpp/client/SWGHelpers.cpp | 73 +++++++++++++++++-- 1 file changed, 68 insertions(+), 5 deletions(-) diff --git a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp index 6b439996724d..dfa28c8b3bff 100644 --- a/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp +++ b/samples/client/petstore/qt5cpp/client/SWGHelpers.cpp @@ -53,6 +53,46 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { qDebug() << "Can't set value because the target pointer is NULL"; } } + else if (QStringLiteral("QDateTime").compare(type) == 0) { + QDateTime **val = static_cast(value); + + if(val != NULL) { + if(!obj.isNull()) { + // create a new value and return + delete *val; + *val = new QDateTime(QDateTime::fromString(obj.toString(), Qt::ISODate)); + return; + } + else { + // set target to NULL + delete *val; + *val = NULL; + } + } + else { + qDebug() << "Can't set value because the target pointer is NULL"; + } + } + else if (QStringLiteral("QDate").compare(type) == 0) { + QDate **val = static_cast(value); + + if(val != NULL) { + if(!obj.isNull()) { + // create a new value and return + delete *val; + *val = new QDate(QDate::fromString(obj.toString(), Qt::ISODate)); + return; + } + else { + // set target to NULL + delete *val; + *val = NULL; + } + } + else { + qDebug() << "Can't set value because the target pointer is NULL"; + } + } else if(type.startsWith("SWG") && obj.isObject()) { // complex type QJsonObject jsonObj = obj.toObject(); @@ -104,6 +144,21 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { setValue(&val, jval, QStringLiteral("double"), QStringLiteral("")); output->append((void*)&val); } + else if(QStringLiteral("QString").compare(complexType) == 0) { + QString val; + setValue(&val, jval, QStringLiteral("QString"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("QDate").compare(complexType) == 0) { + QDate val; + setValue(&val, jval, QStringLiteral("QDate"), QStringLiteral("")); + output->append((void*)&val); + } + else if(QStringLiteral("QDateTime").compare(complexType) == 0) { + QDateTime val; + setValue(&val, jval, QStringLiteral("QDateTime"), QStringLiteral("")); + output->append((void*)&val); + } } } QList **val = static_cast**>(value); @@ -139,23 +194,31 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { } else if(QStringLiteral("qint32").compare(type) == 0) { qint32* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("qint64").compare(type) == 0) { qint64* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("bool").compare(type) == 0) { bool* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); } else if(QStringLiteral("float").compare(type) == 0) { float* str = static_cast(value); - output->insert(name, QJsonValue((double)*str)); + output->insert(name, QJsonValue((double)*str)); } else if(QStringLiteral("double").compare(type) == 0) { double* str = static_cast(value); - output->insert(name, QJsonValue(*str)); + output->insert(name, QJsonValue(*str)); + } + else if(QStringLiteral("QDate").compare(type) == 0) { + QDate* date = static_cast(value); + output->insert(name, QJsonValue(date->toString(Qt::ISODate))); + } + else if(QStringLiteral("QDateTime").compare(type) == 0) { + QDateTime* datetime = static_cast(value); + output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); } }