forked from loafle/openapi-generator-original
436 lines
12 KiB
C++
436 lines
12 KiB
C++
/**
|
|
* 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 <QDebug>
|
|
#include <QJsonParseError>
|
|
#include "PFXHelpers.h"
|
|
|
|
namespace test_namespace {
|
|
|
|
class PFXSerializerSettings {
|
|
public:
|
|
struct CustomDateTimeFormat{
|
|
bool isStringSet = false;
|
|
QString formatString;
|
|
bool isEnumSet = false;
|
|
Qt::DateFormat formatEnum;
|
|
};
|
|
|
|
static CustomDateTimeFormat getCustomDateTimeFormat() {
|
|
return getInstance()->customDateTimeFormat;
|
|
}
|
|
|
|
static void setDateTimeFormatString(const QString &dtFormat){
|
|
getInstance()->customDateTimeFormat.isStringSet = true;
|
|
getInstance()->customDateTimeFormat.isEnumSet = false;
|
|
getInstance()->customDateTimeFormat.formatString = dtFormat;
|
|
}
|
|
|
|
static void setDateTimeFormatEnum(const Qt::DateFormat &dtFormat){
|
|
getInstance()->customDateTimeFormat.isEnumSet = true;
|
|
getInstance()->customDateTimeFormat.isStringSet = false;
|
|
getInstance()->customDateTimeFormat.formatEnum = dtFormat;
|
|
}
|
|
|
|
static PFXSerializerSettings *getInstance(){
|
|
if(instance == nullptr){
|
|
instance = new PFXSerializerSettings();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
private:
|
|
explicit PFXSerializerSettings(){
|
|
instance = this;
|
|
customDateTimeFormat.isStringSet = false;
|
|
customDateTimeFormat.isEnumSet = false;
|
|
}
|
|
static PFXSerializerSettings *instance;
|
|
CustomDateTimeFormat customDateTimeFormat;
|
|
};
|
|
|
|
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::setDateTimeFormatString(dateTimeFormat);
|
|
}
|
|
return success;
|
|
}
|
|
|
|
bool setDateTimeFormat(const Qt::DateFormat &dateTimeFormat){
|
|
bool success = false;
|
|
auto dt = QDateTime::fromString(QDateTime::currentDateTime().toString(dateTimeFormat), dateTimeFormat);
|
|
if (dt.isValid()) {
|
|
success = true;
|
|
PFXSerializerSettings::setDateTimeFormatEnum(dateTimeFormat);
|
|
}
|
|
return success;
|
|
}
|
|
|
|
QString toStringValue(const QString &value) {
|
|
return value;
|
|
}
|
|
|
|
QString toStringValue(const QDateTime &value) {
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isStringSet) {
|
|
return value.toString(PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatString);
|
|
}
|
|
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isEnumSet) {
|
|
return value.toString(PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatEnum);
|
|
}
|
|
|
|
// ISO 8601
|
|
return value.toString(Qt::ISODate);
|
|
}
|
|
|
|
QString toStringValue(const QByteArray &value) {
|
|
return QString(value);
|
|
}
|
|
|
|
QString toStringValue(const QDate &value) {
|
|
// ISO 8601
|
|
return value.toString(Qt::DateFormat::ISODate);
|
|
}
|
|
|
|
QString toStringValue(const qint32 &value) {
|
|
return QString::number(value);
|
|
}
|
|
|
|
QString toStringValue(const qint64 &value) {
|
|
return QString::number(value);
|
|
}
|
|
|
|
QString toStringValue(const bool &value) {
|
|
return QString(value ? "true" : "false");
|
|
}
|
|
|
|
QString toStringValue(const float &value) {
|
|
return QString::number(static_cast<double>(value));
|
|
}
|
|
|
|
QString toStringValue(const double &value) {
|
|
return QString::number(value);
|
|
}
|
|
|
|
QString toStringValue(const PFXObject &value) {
|
|
return value.asJson();
|
|
}
|
|
|
|
QString toStringValue(const PFXEnum &value) {
|
|
return value.asJson();
|
|
}
|
|
|
|
QString toStringValue(const PFXHttpFileElement &value) {
|
|
return value.asJson();
|
|
}
|
|
|
|
QJsonValue toJsonValue(const QString &value) {
|
|
return QJsonValue(value);
|
|
}
|
|
|
|
QJsonValue toJsonValue(const QDateTime &value) {
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isStringSet) {
|
|
return QJsonValue(value.toString(PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatString));
|
|
}
|
|
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isEnumSet) {
|
|
return QJsonValue(value.toString(PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatEnum));
|
|
}
|
|
|
|
// ISO 8601
|
|
return QJsonValue(value.toString(Qt::ISODate));
|
|
}
|
|
|
|
QJsonValue toJsonValue(const QByteArray &value) {
|
|
return QJsonValue(QString(value.toBase64()));
|
|
}
|
|
|
|
QJsonValue toJsonValue(const QDate &value) {
|
|
return QJsonValue(value.toString(Qt::ISODate));
|
|
}
|
|
|
|
QJsonValue toJsonValue(const qint32 &value) {
|
|
return QJsonValue(value);
|
|
}
|
|
|
|
QJsonValue toJsonValue(const qint64 &value) {
|
|
return QJsonValue(value);
|
|
}
|
|
|
|
QJsonValue toJsonValue(const bool &value) {
|
|
return QJsonValue(value);
|
|
}
|
|
|
|
QJsonValue toJsonValue(const float &value) {
|
|
return QJsonValue(static_cast<double>(value));
|
|
}
|
|
|
|
QJsonValue toJsonValue(const double &value) {
|
|
return QJsonValue(value);
|
|
}
|
|
|
|
QJsonValue toJsonValue(const PFXObject &value) {
|
|
return value.asJsonObject();
|
|
}
|
|
|
|
QJsonValue toJsonValue(const PFXEnum &value) {
|
|
return value.asJsonValue();
|
|
}
|
|
|
|
QJsonValue toJsonValue(const PFXHttpFileElement &value) {
|
|
return value.asJsonValue();
|
|
}
|
|
|
|
QJsonValue toJsonValue(const QJsonValue &value) {
|
|
return value;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, QString &value) {
|
|
value.clear();
|
|
value.append(inStr);
|
|
return !inStr.isEmpty();
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, QDateTime &value) {
|
|
if (inStr.isEmpty()) {
|
|
return false;
|
|
} else {
|
|
QDateTime dateTime;
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isStringSet) {
|
|
dateTime = QDateTime::fromString(inStr, PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatString);
|
|
} else if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isEnumSet) {
|
|
dateTime = QDateTime::fromString(inStr, PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatEnum);
|
|
} else {
|
|
dateTime = QDateTime::fromString(inStr, Qt::ISODate);
|
|
}
|
|
|
|
if (dateTime.isValid()) {
|
|
value.setDate(dateTime.date());
|
|
value.setTime(dateTime.time());
|
|
} else {
|
|
qDebug() << "DateTime is invalid";
|
|
}
|
|
return dateTime.isValid();
|
|
}
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, QByteArray &value) {
|
|
if (inStr.isEmpty()) {
|
|
return false;
|
|
} else {
|
|
value.clear();
|
|
value.append(inStr.toUtf8());
|
|
return !value.isEmpty();
|
|
}
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, QDate &value) {
|
|
if (inStr.isEmpty()) {
|
|
return false;
|
|
} else {
|
|
auto date = QDate::fromString(inStr, Qt::DateFormat::ISODate);
|
|
if (date.isValid()) {
|
|
value.setDate(date.year(), date.month(), date.day());
|
|
} else {
|
|
qDebug() << "Date is invalid";
|
|
}
|
|
return date.isValid();
|
|
}
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, qint32 &value) {
|
|
bool ok = false;
|
|
value = QVariant(inStr).toInt(&ok);
|
|
return ok;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, qint64 &value) {
|
|
bool ok = false;
|
|
value = QVariant(inStr).toLongLong(&ok);
|
|
return ok;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, bool &value) {
|
|
value = QVariant(inStr).toBool();
|
|
return ((inStr == "true") || (inStr == "false"));
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, float &value) {
|
|
bool ok = false;
|
|
value = QVariant(inStr).toFloat(&ok);
|
|
return ok;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, double &value) {
|
|
bool ok = false;
|
|
value = QVariant(inStr).toDouble(&ok);
|
|
return ok;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, PFXObject &value)
|
|
{
|
|
QJsonParseError err;
|
|
QJsonDocument::fromJson(inStr.toUtf8(),&err);
|
|
if ( err.error == QJsonParseError::NoError ){
|
|
value.fromJson(inStr);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, PFXEnum &value) {
|
|
value.fromJson(inStr);
|
|
return true;
|
|
}
|
|
|
|
bool fromStringValue(const QString &inStr, PFXHttpFileElement &value) {
|
|
return value.fromStringValue(inStr);
|
|
}
|
|
|
|
bool fromJsonValue(QString &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull()) {
|
|
if (jval.isString()) {
|
|
value = jval.toString();
|
|
} else if (jval.isBool()) {
|
|
value = jval.toBool() ? "true" : "false";
|
|
} else if (jval.isDouble()) {
|
|
value = QString::number(jval.toDouble());
|
|
} else {
|
|
ok = false;
|
|
}
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(QDateTime &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull() && jval.isString()) {
|
|
if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isStringSet) {
|
|
value = QDateTime::fromString(jval.toString(), PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatString);
|
|
} else if (PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().isEnumSet) {
|
|
value = QDateTime::fromString(jval.toString(), PFXSerializerSettings::getInstance()->getCustomDateTimeFormat().formatEnum);
|
|
} else {
|
|
value = QDateTime::fromString(jval.toString(), Qt::ISODate);
|
|
}
|
|
ok = value.isValid();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(QByteArray &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull() && jval.isString()) {
|
|
value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString()));
|
|
ok = value.size() > 0;
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(QDate &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull() && jval.isString()) {
|
|
value = QDate::fromString(jval.toString(), Qt::ISODate);
|
|
ok = value.isValid();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(qint32 &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()) {
|
|
value = jval.toInt();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(qint64 &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()) {
|
|
value = jval.toVariant().toLongLong();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(bool &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (jval.isBool()) {
|
|
value = jval.toBool();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(float &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (jval.isDouble()) {
|
|
value = static_cast<float>(jval.toDouble());
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(double &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (jval.isDouble()) {
|
|
value = jval.toDouble();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(PFXObject &value, const QJsonValue &jval) {
|
|
bool ok = true;
|
|
if (jval.isObject()) {
|
|
value.fromJsonObject(jval.toObject());
|
|
ok = value.isValid();
|
|
} else {
|
|
ok = false;
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
bool fromJsonValue(PFXEnum &value, const QJsonValue &jval) {
|
|
value.fromJsonValue(jval);
|
|
return true;
|
|
}
|
|
|
|
bool fromJsonValue(PFXHttpFileElement &value, const QJsonValue &jval) {
|
|
return value.fromJsonValue(jval);
|
|
}
|
|
|
|
bool fromJsonValue(QJsonValue &value, const QJsonValue &jval) {
|
|
value = jval;
|
|
return true;
|
|
}
|
|
|
|
} // namespace test_namespace
|