diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-body.mustache index 4dd03102bad6..a4c04a8951c0 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-body.mustache @@ -7,13 +7,49 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} +class {{prefix}}SerializerSettings { +public: + static void setDateTimeFormat(const QString & dtFormat){ + getInstance()->dateTimeFormat = dtFormat; + } + static QString getDateTimeFormat() { + return getInstance()->dateTimeFormat; + } + static {{prefix}}SerializerSettings *getInstance(){ + if(instance == nullptr){ + instance = new {{prefix}}SerializerSettings(); + } + return instance; + } +private: + explicit {{prefix}}SerializerSettings(){ + instance = this; + dateTimeFormat.clear(); + } + static {{prefix}}SerializerSettings *instance; + QString dateTimeFormat; +}; + +{{prefix}}SerializerSettings * {{prefix}}SerializerSettings::instance = nullptr; + +bool setDateTimeFormat(const QString& dateTimeFormat){ + bool success = false; + auto dt = QDateTime::fromString(QDateTime::currentDateTime().toString(dateTimeFormat), dateTimeFormat); + if(dt.isValid()){ + success = true; + {{prefix}}SerializerSettings::setDateTimeFormat(dateTimeFormat); + } + return success; +} + + QString toStringValue(const QString &value) { return value; } QString toStringValue(const QDateTime &value) { // ISO 8601 - return value.toString("yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + return {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()? value.toString(Qt::ISODate):value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); } QString toStringValue(const QByteArray &value) { @@ -62,7 +98,7 @@ QJsonValue toJsonValue(const QString &value) { } QJsonValue toJsonValue(const QDateTime &value) { - return QJsonValue(value.toString(Qt::ISODate)); + return QJsonValue(value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?value.toString(Qt::ISODate):value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()))); } QJsonValue toJsonValue(const QByteArray &value) { @@ -115,7 +151,7 @@ bool fromStringValue(const QString &inStr, QDateTime &value) { if (inStr.isEmpty()) { return false; } else { - auto dateTime = QDateTime::fromString(inStr, "yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + auto dateTime = {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(inStr, Qt::ISODate) :QDateTime::fromString(inStr, {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); if (dateTime.isValid()) { value.setDate(dateTime.date()); value.setTime(dateTime.time()); @@ -220,7 +256,7 @@ bool fromJsonValue(QString &value, const QJsonValue &jval) { bool fromJsonValue(QDateTime &value, const QJsonValue &jval) { bool ok = true; if (!jval.isUndefined() && !jval.isNull() && jval.isString()) { - value = QDateTime::fromString(jval.toString(), Qt::ISODate); + value = {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(jval.toString(), Qt::ISODate): QDateTime::fromString(jval.toString(), {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); ok = value.isValid(); } else { ok = false; diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-header.mustache index a53e0a30edd9..0a8e6b8b2145 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/helpers-header.mustache @@ -20,6 +20,8 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} +bool setDateTimeFormat(const QString&); + template QString toStringValue(const QList &val); diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-body.mustache index 4dd03102bad6..a4c04a8951c0 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-body.mustache @@ -7,13 +7,49 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} +class {{prefix}}SerializerSettings { +public: + static void setDateTimeFormat(const QString & dtFormat){ + getInstance()->dateTimeFormat = dtFormat; + } + static QString getDateTimeFormat() { + return getInstance()->dateTimeFormat; + } + static {{prefix}}SerializerSettings *getInstance(){ + if(instance == nullptr){ + instance = new {{prefix}}SerializerSettings(); + } + return instance; + } +private: + explicit {{prefix}}SerializerSettings(){ + instance = this; + dateTimeFormat.clear(); + } + static {{prefix}}SerializerSettings *instance; + QString dateTimeFormat; +}; + +{{prefix}}SerializerSettings * {{prefix}}SerializerSettings::instance = nullptr; + +bool setDateTimeFormat(const QString& dateTimeFormat){ + bool success = false; + auto dt = QDateTime::fromString(QDateTime::currentDateTime().toString(dateTimeFormat), dateTimeFormat); + if(dt.isValid()){ + success = true; + {{prefix}}SerializerSettings::setDateTimeFormat(dateTimeFormat); + } + return success; +} + + QString toStringValue(const QString &value) { return value; } QString toStringValue(const QDateTime &value) { // ISO 8601 - return value.toString("yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + return {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()? value.toString(Qt::ISODate):value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); } QString toStringValue(const QByteArray &value) { @@ -62,7 +98,7 @@ QJsonValue toJsonValue(const QString &value) { } QJsonValue toJsonValue(const QDateTime &value) { - return QJsonValue(value.toString(Qt::ISODate)); + return QJsonValue(value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?value.toString(Qt::ISODate):value.toString({{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()))); } QJsonValue toJsonValue(const QByteArray &value) { @@ -115,7 +151,7 @@ bool fromStringValue(const QString &inStr, QDateTime &value) { if (inStr.isEmpty()) { return false; } else { - auto dateTime = QDateTime::fromString(inStr, "yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + auto dateTime = {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(inStr, Qt::ISODate) :QDateTime::fromString(inStr, {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); if (dateTime.isValid()) { value.setDate(dateTime.date()); value.setTime(dateTime.time()); @@ -220,7 +256,7 @@ bool fromJsonValue(QString &value, const QJsonValue &jval) { bool fromJsonValue(QDateTime &value, const QJsonValue &jval) { bool ok = true; if (!jval.isUndefined() && !jval.isNull() && jval.isString()) { - value = QDateTime::fromString(jval.toString(), Qt::ISODate); + value = {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(jval.toString(), Qt::ISODate): QDateTime::fromString(jval.toString(), {{prefix}}SerializerSettings::getInstance()->getDateTimeFormat()); ok = value.isValid(); } else { ok = false; diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-header.mustache index a53e0a30edd9..0a8e6b8b2145 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/helpers-header.mustache @@ -20,6 +20,8 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} +bool setDateTimeFormat(const QString&); + template QString toStringValue(const QList &val); diff --git a/samples/client/petstore/cpp-qt5/PetStore/main.cpp b/samples/client/petstore/cpp-qt5/PetStore/main.cpp index af23f1652a87..79e626c957c0 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/main.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/main.cpp @@ -1,12 +1,14 @@ #include #include +#include "PFXHelpers.h" #include "PetApiTests.h" #include "StoreApiTests.h" #include "UserApiTests.h" int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); + ::test_namespace::setDateTimeFormat("yyyy-MM-ddTHH:mm:ss.zzzZ"); PetApiTests petApiTests; StoreApiTests storeApiTests; UserApiTests userApiTests; diff --git a/samples/client/petstore/cpp-qt5/client/PFXHelpers.cpp b/samples/client/petstore/cpp-qt5/client/PFXHelpers.cpp index 66ff2d4fd4e5..b3b36c83be8b 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXHelpers.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXHelpers.cpp @@ -15,13 +15,49 @@ namespace test_namespace { +class PFXSerializerSettings { +public: + static void setDateTimeFormat(const QString & dtFormat){ + getInstance()->dateTimeFormat = dtFormat; + } + static QString getDateTimeFormat() { + return getInstance()->dateTimeFormat; + } + static PFXSerializerSettings *getInstance(){ + if(instance == nullptr){ + instance = new PFXSerializerSettings(); + } + return instance; + } +private: + explicit PFXSerializerSettings(){ + instance = this; + dateTimeFormat.clear(); + } + static PFXSerializerSettings *instance; + QString dateTimeFormat; +}; + +PFXSerializerSettings * PFXSerializerSettings::instance = nullptr; + +bool setDateTimeFormat(const QString& dateTimeFormat){ + bool success = false; + auto dt = QDateTime::fromString(QDateTime::currentDateTime().toString(dateTimeFormat), dateTimeFormat); + if(dt.isValid()){ + success = true; + PFXSerializerSettings::setDateTimeFormat(dateTimeFormat); + } + return success; +} + + QString toStringValue(const QString &value) { return value; } QString toStringValue(const QDateTime &value) { // ISO 8601 - return value.toString("yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + return PFXSerializerSettings::getInstance()->getDateTimeFormat().isEmpty()? value.toString(Qt::ISODate):value.toString(PFXSerializerSettings::getInstance()->getDateTimeFormat()); } QString toStringValue(const QByteArray &value) { @@ -70,7 +106,7 @@ QJsonValue toJsonValue(const QString &value) { } QJsonValue toJsonValue(const QDateTime &value) { - return QJsonValue(value.toString(Qt::ISODate)); + return QJsonValue(value.toString(PFXSerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?value.toString(Qt::ISODate):value.toString(PFXSerializerSettings::getInstance()->getDateTimeFormat()))); } QJsonValue toJsonValue(const QByteArray &value) { @@ -123,7 +159,7 @@ bool fromStringValue(const QString &inStr, QDateTime &value) { if (inStr.isEmpty()) { return false; } else { - auto dateTime = QDateTime::fromString(inStr, "yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + auto dateTime = PFXSerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(inStr, Qt::ISODate) :QDateTime::fromString(inStr, PFXSerializerSettings::getInstance()->getDateTimeFormat()); if (dateTime.isValid()) { value.setDate(dateTime.date()); value.setTime(dateTime.time()); @@ -228,7 +264,7 @@ bool fromJsonValue(QString &value, const QJsonValue &jval) { bool fromJsonValue(QDateTime &value, const QJsonValue &jval) { bool ok = true; if (!jval.isUndefined() && !jval.isNull() && jval.isString()) { - value = QDateTime::fromString(jval.toString(), Qt::ISODate); + value = PFXSerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(jval.toString(), Qt::ISODate): QDateTime::fromString(jval.toString(), PFXSerializerSettings::getInstance()->getDateTimeFormat()); ok = value.isValid(); } else { ok = false; diff --git a/samples/client/petstore/cpp-qt5/client/PFXHelpers.h b/samples/client/petstore/cpp-qt5/client/PFXHelpers.h index e8c0ee7f9412..8bed4f0e80c0 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXHelpers.h +++ b/samples/client/petstore/cpp-qt5/client/PFXHelpers.h @@ -28,6 +28,8 @@ namespace test_namespace { +bool setDateTimeFormat(const QString&); + template QString toStringValue(const QList &val); diff --git a/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.cpp b/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.cpp index 6f24349c29f3..474278331811 100644 --- a/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.cpp +++ b/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.cpp @@ -15,13 +15,49 @@ namespace OpenAPI { +class OAISerializerSettings { +public: + static void setDateTimeFormat(const QString & dtFormat){ + getInstance()->dateTimeFormat = dtFormat; + } + static QString getDateTimeFormat() { + return getInstance()->dateTimeFormat; + } + static OAISerializerSettings *getInstance(){ + if(instance == nullptr){ + instance = new OAISerializerSettings(); + } + return instance; + } +private: + explicit OAISerializerSettings(){ + instance = this; + dateTimeFormat.clear(); + } + static OAISerializerSettings *instance; + QString dateTimeFormat; +}; + +OAISerializerSettings * OAISerializerSettings::instance = nullptr; + +bool setDateTimeFormat(const QString& dateTimeFormat){ + bool success = false; + auto dt = QDateTime::fromString(QDateTime::currentDateTime().toString(dateTimeFormat), dateTimeFormat); + if(dt.isValid()){ + success = true; + OAISerializerSettings::setDateTimeFormat(dateTimeFormat); + } + return success; +} + + QString toStringValue(const QString &value) { return value; } QString toStringValue(const QDateTime &value) { // ISO 8601 - return value.toString("yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + return OAISerializerSettings::getInstance()->getDateTimeFormat().isEmpty()? value.toString(Qt::ISODate):value.toString(OAISerializerSettings::getInstance()->getDateTimeFormat()); } QString toStringValue(const QByteArray &value) { @@ -70,7 +106,7 @@ QJsonValue toJsonValue(const QString &value) { } QJsonValue toJsonValue(const QDateTime &value) { - return QJsonValue(value.toString(Qt::ISODate)); + return QJsonValue(value.toString(OAISerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?value.toString(Qt::ISODate):value.toString(OAISerializerSettings::getInstance()->getDateTimeFormat()))); } QJsonValue toJsonValue(const QByteArray &value) { @@ -123,7 +159,7 @@ bool fromStringValue(const QString &inStr, QDateTime &value) { if (inStr.isEmpty()) { return false; } else { - auto dateTime = QDateTime::fromString(inStr, "yyyy-MM-ddTHH:mm:ss[Z|[+|-]HH:mm]"); + auto dateTime = OAISerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(inStr, Qt::ISODate) :QDateTime::fromString(inStr, OAISerializerSettings::getInstance()->getDateTimeFormat()); if (dateTime.isValid()) { value.setDate(dateTime.date()); value.setTime(dateTime.time()); @@ -228,7 +264,7 @@ bool fromJsonValue(QString &value, const QJsonValue &jval) { bool fromJsonValue(QDateTime &value, const QJsonValue &jval) { bool ok = true; if (!jval.isUndefined() && !jval.isNull() && jval.isString()) { - value = QDateTime::fromString(jval.toString(), Qt::ISODate); + value = OAISerializerSettings::getInstance()->getDateTimeFormat().isEmpty()?QDateTime::fromString(jval.toString(), Qt::ISODate): QDateTime::fromString(jval.toString(), OAISerializerSettings::getInstance()->getDateTimeFormat()); ok = value.isValid(); } else { ok = false; diff --git a/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.h b/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.h index 221119f2131a..b5cf6d6928f4 100644 --- a/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.h +++ b/samples/server/petstore/cpp-qt5-qhttpengine-server/server/src/models/OAIHelpers.h @@ -28,6 +28,8 @@ namespace OpenAPI { +bool setDateTimeFormat(const QString&); + template QString toStringValue(const QList &val);