From b2cb215741ffc70c2e33499b19cca5a80c55d4c4 Mon Sep 17 00:00:00 2001 From: philicious Date: Thu, 28 Jul 2016 19:29:33 +0200 Subject: [PATCH 1/2] Qt5: added missing data type handler for QByteArray to SWGHelper --- .../resources/qt5cpp/helpers-body.mustache | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) 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 fc5af8e0ae3..fb7b29b0107 100644 --- a/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache +++ b/modules/swagger-codegen/src/main/resources/qt5cpp/helpers-body.mustache @@ -94,6 +94,27 @@ setValue(void* value, QJsonValue obj, QString type, QString complexType) { qDebug() << "Can't set value because the target pointer is NULL"; } } + else if (QStringLiteral("QByteArray").compare(type) == 0) { + QByteArray **val = static_cast(value); + + if(val != NULL) { + if(!obj.isNull()) { + // create a new value and return + delete *val; + + *val = new QByteArray(QByteArray::fromBase64(QByteArray::fromStdString(obj.toString().toStdString()))); + 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(); @@ -221,6 +242,10 @@ toJsonValue(QString name, void* value, QJsonObject* output, QString type) { QDateTime* datetime = static_cast(value); output->insert(name, QJsonValue(datetime->toString(Qt::ISODate))); } + else if(QStringLiteral("QByteArray").compare(type) == 0) { + QByteArray* byteArray = static_cast(value); + output->insert(name, QJsonValue(QString(byteArray->toBase64()))); + } } void From a67f168fa626725a2c503220ff6af9a411106655 Mon Sep 17 00:00:00 2001 From: philicious Date: Thu, 28 Jul 2016 19:34:45 +0200 Subject: [PATCH 2/2] Qt5: add handling for swagger type-format "byte" to Qt5 generator --- .../main/java/io/swagger/codegen/languages/Qt5CPPGenerator.java | 2 ++ 1 file changed, 2 insertions(+) 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 46999eccbe1..742b057003b 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 @@ -124,6 +124,7 @@ public Qt5CPPGenerator() { //TODO binary should be mapped to byte array // mapped to String as a workaround typeMapping.put("binary", "QString"); + typeMapping.put("ByteArray", "QByteArray"); importMapping = new HashMap(); @@ -138,6 +139,7 @@ public Qt5CPPGenerator() { systemIncludes.add("QMap"); systemIncludes.add("QDate"); systemIncludes.add("QDateTime"); + systemIncludes.add("QByteArray"); } /**