[cpp-qt5] client response headers and validation of properties for client and server (#1508)

* Add validation of required properties
Add Header extraction for client
* Remove some todos
* Add Test for Store API
Improve some checks for serialization
This commit is contained in:
sunn 2018-11-29 11:00:37 +01:00 committed by GitHub
parent 5b4a19849e
commit 308515bbc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 966 additions and 394 deletions

View File

@ -53,6 +53,10 @@ void {{prefix}}HttpRequestInput::add_file(QString variable_name, QString local_f
{{prefix}}HttpRequestWorker::~{{prefix}}HttpRequestWorker() { {{prefix}}HttpRequestWorker::~{{prefix}}HttpRequestWorker() {
} }
QMap<QByteArray, QByteArray> {{prefix}}HttpRequestWorker::getResponseHeaders() const {
return headers;
}
QString {{prefix}}HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) { QString {{prefix}}HttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
// result structure follows RFC 5987 // result structure follows RFC 5987
bool need_utf_encoding = false; bool need_utf_encoding = false;
@ -305,7 +309,11 @@ void {{prefix}}HttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
error_type = reply->error(); error_type = reply->error();
response = reply->readAll(); response = reply->readAll();
error_str = reply->errorString(); error_str = reply->errorString();
if(reply->rawHeaderPairs().count() > 0){
for(const auto& item: reply->rawHeaderPairs()){
headers.insert(item.first, item.second);
}
}
reply->deleteLater(); reply->deleteLater();
emit on_execution_finished(this); emit on_execution_finished(this);

View File

@ -61,9 +61,10 @@ public:
QNetworkReply::NetworkError error_type; QNetworkReply::NetworkError error_type;
QString error_str; QString error_str;
explicit {{prefix}}HttpRequestWorker(QObject *parent = 0); explicit {{prefix}}HttpRequestWorker(QObject *parent = nullptr);
virtual ~{{prefix}}HttpRequestWorker(); virtual ~{{prefix}}HttpRequestWorker();
QMap<QByteArray, QByteArray> getResponseHeaders() const;
QString http_attribute_encode(QString attribute_name, QString input); QString http_attribute_encode(QString attribute_name, QString input);
void execute({{prefix}}HttpRequestInput *input); void execute({{prefix}}HttpRequestInput *input);
static QSslConfiguration* sslDefaultConfiguration; static QSslConfiguration* sslDefaultConfiguration;
@ -73,7 +74,7 @@ signals:
private: private:
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
QMap<QByteArray, QByteArray> headers;
private slots: private slots:
void on_manager_finished(QNetworkReply *reply); void on_manager_finished(QNetworkReply *reply);

View File

@ -47,7 +47,7 @@ toStringValue(const bool &value) {
QString QString
toStringValue(const float &value){ toStringValue(const float &value){
return QString::number(value); return QString::number(static_cast<double>(value));
} }
QString QString
@ -92,7 +92,7 @@ toJsonValue(const bool &value){
QJsonValue QJsonValue
toJsonValue(const float &value){ toJsonValue(const float &value){
return QJsonValue(value); return QJsonValue(static_cast<double>(value));
} }
QJsonValue QJsonValue
@ -193,88 +193,126 @@ fromStringValue(const QString &inStr, double &value){
return ok; return ok;
} }
void bool
fromJsonValue(QString &value, const QJsonValue &jval){ fromJsonValue(QString &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull()){
if(jval.isString()){ if(jval.isString()){
value = jval.toString(); value = jval.toString();
} else if(jval.isBool()) { } else if(jval.isBool()) {
value = jval.toBool() ? "true" : "false"; value = jval.toBool() ? "true" : "false";
} else if(jval.isDouble()){ } else if(jval.isDouble()){
value = QString::number(jval.toDouble()); value = QString::number(jval.toDouble());
} else {
ok = false;
} }
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDateTime &value, const QJsonValue &jval){ fromJsonValue(QDateTime &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDateTime::fromString(jval.toString(), Qt::ISODate); value = QDateTime::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QByteArray &value, const QJsonValue &jval){ fromJsonValue(QByteArray &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()) {
value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString())); value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString()));
ok = value.size() > 0 ;
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDate &value, const QJsonValue &jval){ fromJsonValue(QDate &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDate::fromString(jval.toString(), Qt::ISODate); value = QDate::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint32 &value, const QJsonValue &jval){ fromJsonValue(qint32 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toInt(); value = jval.toInt();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint64 &value, const QJsonValue &jval){ fromJsonValue(qint64 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toVariant().toLongLong(); value = jval.toVariant().toLongLong();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(bool &value, const QJsonValue &jval){ fromJsonValue(bool &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isBool()){
value = jval.toBool(); value = jval.toBool();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(float &value, const QJsonValue &jval){ fromJsonValue(float &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = static_cast<float>(jval.toDouble()); value = static_cast<float>(jval.toDouble());
} else {
ok = false;
} }
return ok;
} }
void bool
fromJsonValue(double &value, const QJsonValue &jval){ fromJsonValue(double &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = jval.toDouble(); value = jval.toDouble();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){ fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
bool ok = true;
if(jval.isObject()){ if(jval.isObject()){
value.fromJsonObject(jval.toObject()); value.fromJsonObject(jval.toObject());
ok = value.isValid();
} else {
ok = false;
} }
return ok;
} }
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}

View File

@ -30,7 +30,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QString toStringValue(const QList<T> &val) { QString toStringValue(const QList<T> &val) {
QString strArray; QString strArray;
for(auto item : val) { for(const auto& item : val) {
strArray.append(toStringValue(item) + ","); strArray.append(toStringValue(item) + ",");
} }
if(val.count() > 0) { if(val.count() > 0) {
@ -53,7 +53,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QList<T> &val) { QJsonValue toJsonValue(const QList<T> &val) {
QJsonArray jArray; QJsonArray jArray;
for(auto item : val) { for(const auto& item : val) {
jArray.append(toJsonValue(item)); jArray.append(toJsonValue(item));
} }
return jArray; return jArray;
@ -62,7 +62,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QMap<QString, T> &val) { QJsonValue toJsonValue(const QMap<QString, T> &val) {
QJsonObject jObject; QJsonObject jObject;
for(auto itemkey : val.keys()) { for(const auto& itemkey : val.keys()) {
jObject.insert(itemkey, toJsonValue(val.value(itemkey))); jObject.insert(itemkey, toJsonValue(val.value(itemkey)));
} }
return jObject; return jObject;
@ -79,56 +79,69 @@ namespace {{this}} {
bool fromStringValue(const QString &inStr, double &value); bool fromStringValue(const QString &inStr, double &value);
template <typename T> template <typename T>
void fromStringValue(const QList<QString> &inStr, QList<T> &val) { bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
for(auto item: inStr){ bool ok = (inStr.count() > 0);
for(const auto& item: inStr){
T itemVal; T itemVal;
fromStringValue(item, itemVal); ok &= fromStringValue(item, itemVal);
val.push_back(itemVal); val.push_back(itemVal);
} }
return ok;
} }
template <typename T> template <typename T>
void fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) { bool fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) {
for(auto itemkey : inStr.keys()){ bool ok = (inStr.count() > 0);
for(const auto& itemkey : inStr.keys()){
T itemVal; T itemVal;
fromStringValue(inStr.value(itemkey), itemVal); ok &= fromStringValue(inStr.value(itemkey), itemVal);
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
return ok;
} }
void fromJsonValue(QString &value, const QJsonValue &jval); bool fromJsonValue(QString &value, const QJsonValue &jval);
void fromJsonValue(QDateTime &value, const QJsonValue &jval); bool fromJsonValue(QDateTime &value, const QJsonValue &jval);
void fromJsonValue(QByteArray &value, const QJsonValue &jval); bool fromJsonValue(QByteArray &value, const QJsonValue &jval);
void fromJsonValue(QDate &value, const QJsonValue &jval); bool fromJsonValue(QDate &value, const QJsonValue &jval);
void fromJsonValue(qint32 &value, const QJsonValue &jval); bool fromJsonValue(qint32 &value, const QJsonValue &jval);
void fromJsonValue(qint64 &value, const QJsonValue &jval); bool fromJsonValue(qint64 &value, const QJsonValue &jval);
void fromJsonValue(bool &value, const QJsonValue &jval); bool fromJsonValue(bool &value, const QJsonValue &jval);
void fromJsonValue(float &value, const QJsonValue &jval); bool fromJsonValue(float &value, const QJsonValue &jval);
void fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue(double &value, const QJsonValue &jval);
void fromJsonValue({{prefix}}Object &value, const QJsonValue &jval); bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
template <typename T> template <typename T>
void fromJsonValue(QList<T> &val, const QJsonValue &jval) { bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isArray()){ if(jval.isArray()){
for(const QJsonValue &jitem : jval.toArray()){ for(const auto& jitem : jval.toArray()){
T item; T item;
fromJsonValue(item, jitem); ok &= fromJsonValue(item, jitem);
val.push_back(item); val.push_back(item);
} }
} else {
ok = false;
} }
return ok;
} }
template <typename T> template <typename T>
void fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) { bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isObject()){
auto varmap = jval.toObject().toVariantMap(); auto varmap = jval.toObject().toVariantMap();
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto itemkey : varmap.keys() ){ for(const auto& itemkey : varmap.keys() ){
T itemVal; T itemVal;
fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey))); ok &= fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey)));
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
} }
return; } else {
ok = false;
}
return ok;
} }
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}

View File

@ -14,6 +14,7 @@ namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}
{{classname}}::{{classname}}(QString json) { {{classname}}::{{classname}}(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -29,6 +30,7 @@ void
{{classname}}::init() { {{classname}}::init() {
{{#vars}} {{#vars}}
m_{{name}}_isSet = false; m_{{name}}_isSet = false;
m_{{name}}_isValid = false;
{{/vars}} {{/vars}}
} }
@ -43,23 +45,25 @@ void
void void
{{classname}}::fromJsonObject(QJsonObject json) { {{classname}}::fromJsonObject(QJsonObject json) {
{{#vars}} {{#vars}}
{{^isContainer}}::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}} {{^isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}}
{{#isContainer}}{{^items.isContainer}}::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}} {{#isContainer}}{{^items.isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
if(json["{{baseName}}"].isArray()){ if(json["{{baseName}}"].isArray()){
auto arr = json["{{baseName}}"].toArray(); auto arr = json["{{baseName}}"].toArray();
m_{{name}}_isValid = true;
for (const QJsonValue & jval : arr) { for (const QJsonValue & jval : arr) {
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item; {{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
::{{cppNamespace}}::fromJsonValue(item, jval) m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval)
{{name}}.push_back(item); {{name}}.push_back(item);
} }
}{{/isListContainer}}{{#isMapContainer}} }{{/isListContainer}}{{#isMapContainer}}
if(json["{{baseName}}"].isObject()){ if(json["{{baseName}}"].isObject()){
auto varmap = json["{{baseName}}"].toObject().toVariantMap(); auto varmap = json["{{baseName}}"].toObject().toVariantMap();
m_{{name}}_isValid = true;
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto val : varmap.keys()){ for(auto val : varmap.keys()){
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item; {{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
auto jval = QJsonValue::fromVariant(varmap.value(val)); auto jval = QJsonValue::fromVariant(varmap.value(val));
::{{cppNamespace}}::fromJsonValue(item, jval); m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
{{name}}.insert({{name}}.end(), val, item); {{name}}.insert({{name}}.end(), val, item);
} }
} }
@ -102,7 +106,6 @@ void
} }
{{/vars}} {{/vars}}
bool bool
{{classname}}::isSet() const { {{classname}}::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -112,6 +115,12 @@ bool
return isObjectUpdated; return isObjectUpdated;
} }
bool
{{classname}}::isValid() const {
// only required properties are required for the object to be considered valid
return {{#vars}}{{#required}}m_{{name}}_isValid && {{/required}}{{/vars}}true;
}
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
} }
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}

View File

@ -40,12 +40,13 @@ public:
{{/vars}} {{/vars}}
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
{{#vars}} {{#vars}}
{{{dataType}}} {{name}}; {{{dataType}}} {{name}};
bool m_{{name}}_isSet; bool m_{{name}}_isSet;
bool m_{{name}}_isValid;
{{/vars}} {{/vars}}
}; };

View File

@ -36,6 +36,10 @@ class {{prefix}}Object {
virtual bool isSet() const { virtual bool isSet() const {
return false; return false;
} }
virtual bool isValid() const {
return true;
}
private : private :
QJsonObject jObj; QJsonObject jObj;
}; };

View File

@ -140,13 +140,19 @@ void {{classname}}Request::{{nickname}}Request({{#hasPathParams}}{{#pathParams}}
{{/operation}}{{/operations}} {{/operation}}{{/operations}}
void {{classname}}Request::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){ void {{classname}}Request::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res);
if(socket->isOpen()){
socket->close();
}
} }
void {{classname}}Request::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){ void {{classname}}Request::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res->readAll());
if(socket->isOpen()){
socket->close();
}
} }
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}

View File

@ -47,7 +47,7 @@ toStringValue(const bool &value) {
QString QString
toStringValue(const float &value){ toStringValue(const float &value){
return QString::number(value); return QString::number(static_cast<double>(value));
} }
QString QString
@ -92,7 +92,7 @@ toJsonValue(const bool &value){
QJsonValue QJsonValue
toJsonValue(const float &value){ toJsonValue(const float &value){
return QJsonValue(value); return QJsonValue(static_cast<double>(value));
} }
QJsonValue QJsonValue
@ -193,88 +193,126 @@ fromStringValue(const QString &inStr, double &value){
return ok; return ok;
} }
void bool
fromJsonValue(QString &value, const QJsonValue &jval){ fromJsonValue(QString &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull()){
if(jval.isString()){ if(jval.isString()){
value = jval.toString(); value = jval.toString();
} else if(jval.isBool()) { } else if(jval.isBool()) {
value = jval.toBool() ? "true" : "false"; value = jval.toBool() ? "true" : "false";
} else if(jval.isDouble()){ } else if(jval.isDouble()){
value = QString::number(jval.toDouble()); value = QString::number(jval.toDouble());
} else {
ok = false;
} }
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDateTime &value, const QJsonValue &jval){ fromJsonValue(QDateTime &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDateTime::fromString(jval.toString(), Qt::ISODate); value = QDateTime::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QByteArray &value, const QJsonValue &jval){ fromJsonValue(QByteArray &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()) {
value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString())); value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString()));
ok = value.size() > 0 ;
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDate &value, const QJsonValue &jval){ fromJsonValue(QDate &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDate::fromString(jval.toString(), Qt::ISODate); value = QDate::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint32 &value, const QJsonValue &jval){ fromJsonValue(qint32 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toInt(); value = jval.toInt();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint64 &value, const QJsonValue &jval){ fromJsonValue(qint64 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toVariant().toLongLong(); value = jval.toVariant().toLongLong();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(bool &value, const QJsonValue &jval){ fromJsonValue(bool &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isBool()){
value = jval.toBool(); value = jval.toBool();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(float &value, const QJsonValue &jval){ fromJsonValue(float &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = static_cast<float>(jval.toDouble()); value = static_cast<float>(jval.toDouble());
} else {
ok = false;
} }
return ok;
} }
void bool
fromJsonValue(double &value, const QJsonValue &jval){ fromJsonValue(double &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = jval.toDouble(); value = jval.toDouble();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){ fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
bool ok = true;
if(jval.isObject()){ if(jval.isObject()){
value.fromJsonObject(jval.toObject()); value.fromJsonObject(jval.toObject());
ok = value.isValid();
} else {
ok = false;
} }
return ok;
} }
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}

View File

@ -30,7 +30,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QString toStringValue(const QList<T> &val) { QString toStringValue(const QList<T> &val) {
QString strArray; QString strArray;
for(auto item : val) { for(const auto& item : val) {
strArray.append(toStringValue(item) + ","); strArray.append(toStringValue(item) + ",");
} }
if(val.count() > 0) { if(val.count() > 0) {
@ -53,7 +53,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QList<T> &val) { QJsonValue toJsonValue(const QList<T> &val) {
QJsonArray jArray; QJsonArray jArray;
for(auto item : val) { for(const auto& item : val) {
jArray.append(toJsonValue(item)); jArray.append(toJsonValue(item));
} }
return jArray; return jArray;
@ -62,7 +62,7 @@ namespace {{this}} {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QMap<QString, T> &val) { QJsonValue toJsonValue(const QMap<QString, T> &val) {
QJsonObject jObject; QJsonObject jObject;
for(auto itemkey : val.keys()) { for(const auto& itemkey : val.keys()) {
jObject.insert(itemkey, toJsonValue(val.value(itemkey))); jObject.insert(itemkey, toJsonValue(val.value(itemkey)));
} }
return jObject; return jObject;
@ -79,56 +79,69 @@ namespace {{this}} {
bool fromStringValue(const QString &inStr, double &value); bool fromStringValue(const QString &inStr, double &value);
template <typename T> template <typename T>
void fromStringValue(const QList<QString> &inStr, QList<T> &val) { bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
for(auto item: inStr){ bool ok = (inStr.count() > 0);
for(const auto& item: inStr){
T itemVal; T itemVal;
fromStringValue(item, itemVal); ok &= fromStringValue(item, itemVal);
val.push_back(itemVal); val.push_back(itemVal);
} }
return ok;
} }
template <typename T> template <typename T>
void fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) { bool fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) {
for(auto itemkey : inStr.keys()){ bool ok = (inStr.count() > 0);
for(const auto& itemkey : inStr.keys()){
T itemVal; T itemVal;
fromStringValue(inStr.value(itemkey), itemVal); ok &= fromStringValue(inStr.value(itemkey), itemVal);
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
return ok;
} }
void fromJsonValue(QString &value, const QJsonValue &jval); bool fromJsonValue(QString &value, const QJsonValue &jval);
void fromJsonValue(QDateTime &value, const QJsonValue &jval); bool fromJsonValue(QDateTime &value, const QJsonValue &jval);
void fromJsonValue(QByteArray &value, const QJsonValue &jval); bool fromJsonValue(QByteArray &value, const QJsonValue &jval);
void fromJsonValue(QDate &value, const QJsonValue &jval); bool fromJsonValue(QDate &value, const QJsonValue &jval);
void fromJsonValue(qint32 &value, const QJsonValue &jval); bool fromJsonValue(qint32 &value, const QJsonValue &jval);
void fromJsonValue(qint64 &value, const QJsonValue &jval); bool fromJsonValue(qint64 &value, const QJsonValue &jval);
void fromJsonValue(bool &value, const QJsonValue &jval); bool fromJsonValue(bool &value, const QJsonValue &jval);
void fromJsonValue(float &value, const QJsonValue &jval); bool fromJsonValue(float &value, const QJsonValue &jval);
void fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue(double &value, const QJsonValue &jval);
void fromJsonValue({{prefix}}Object &value, const QJsonValue &jval); bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
template <typename T> template <typename T>
void fromJsonValue(QList<T> &val, const QJsonValue &jval) { bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isArray()){ if(jval.isArray()){
for(const QJsonValue &jitem : jval.toArray()){ for(const auto& jitem : jval.toArray()){
T item; T item;
fromJsonValue(item, jitem); ok &= fromJsonValue(item, jitem);
val.push_back(item); val.push_back(item);
} }
} else {
ok = false;
} }
return ok;
} }
template <typename T> template <typename T>
void fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) { bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isObject()){
auto varmap = jval.toObject().toVariantMap(); auto varmap = jval.toObject().toVariantMap();
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto itemkey : varmap.keys() ){ for(const auto& itemkey : varmap.keys() ){
T itemVal; T itemVal;
fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey))); ok &= fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey)));
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
} }
return; } else {
ok = false;
}
return ok;
} }
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}

View File

@ -14,6 +14,7 @@ namespace {{this}} {
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}
{{classname}}::{{classname}}(QString json) { {{classname}}::{{classname}}(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -29,6 +30,7 @@ void
{{classname}}::init() { {{classname}}::init() {
{{#vars}} {{#vars}}
m_{{name}}_isSet = false; m_{{name}}_isSet = false;
m_{{name}}_isValid = false;
{{/vars}} {{/vars}}
} }
@ -43,23 +45,25 @@ void
void void
{{classname}}::fromJsonObject(QJsonObject json) { {{classname}}::fromJsonObject(QJsonObject json) {
{{#vars}} {{#vars}}
{{^isContainer}}::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}} {{^isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}}
{{#isContainer}}{{^items.isContainer}}::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}} {{#isContainer}}{{^items.isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
if(json["{{baseName}}"].isArray()){ if(json["{{baseName}}"].isArray()){
auto arr = json["{{baseName}}"].toArray(); auto arr = json["{{baseName}}"].toArray();
m_{{name}}_isValid = true;
for (const QJsonValue & jval : arr) { for (const QJsonValue & jval : arr) {
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item; {{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
::{{cppNamespace}}::fromJsonValue(item, jval) m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval)
{{name}}.push_back(item); {{name}}.push_back(item);
} }
}{{/isListContainer}}{{#isMapContainer}} }{{/isListContainer}}{{#isMapContainer}}
if(json["{{baseName}}"].isObject()){ if(json["{{baseName}}"].isObject()){
auto varmap = json["{{baseName}}"].toObject().toVariantMap(); auto varmap = json["{{baseName}}"].toObject().toVariantMap();
m_{{name}}_isValid = true;
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto val : varmap.keys()){ for(auto val : varmap.keys()){
{{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item; {{^items.isContainer}}{{items.baseType}}{{/items.isContainer}}{{#items.isListContainer}}QList<{{items.items.baseType}}>{{/items.isListContainer}}{{#items.isMapContainer}}QMap<QString, {{items.items.baseType}}>{{/items.isMapContainer}} item;
auto jval = QJsonValue::fromVariant(varmap.value(val)); auto jval = QJsonValue::fromVariant(varmap.value(val));
::{{cppNamespace}}::fromJsonValue(item, jval); m_{{name}}_isValid &= ::{{cppNamespace}}::fromJsonValue(item, jval);
{{name}}.insert({{name}}.end(), val, item); {{name}}.insert({{name}}.end(), val, item);
} }
} }
@ -102,7 +106,6 @@ void
} }
{{/vars}} {{/vars}}
bool bool
{{classname}}::isSet() const { {{classname}}::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -112,6 +115,12 @@ bool
return isObjectUpdated; return isObjectUpdated;
} }
bool
{{classname}}::isValid() const {
// only required properties are required for the object to be considered valid
return {{#vars}}{{#required}}m_{{name}}_isValid && {{/required}}{{/vars}}true;
}
{{#cppNamespaceDeclarations}} {{#cppNamespaceDeclarations}}
} }
{{/cppNamespaceDeclarations}} {{/cppNamespaceDeclarations}}

View File

@ -40,12 +40,13 @@ public:
{{/vars}} {{/vars}}
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
{{#vars}} {{#vars}}
{{{dataType}}} {{name}}; {{{dataType}}} {{name}};
bool m_{{name}}_isSet; bool m_{{name}}_isSet;
bool m_{{name}}_isValid;
{{/vars}} {{/vars}}
}; };

View File

@ -36,6 +36,10 @@ class {{prefix}}Object {
virtual bool isSet() const { virtual bool isSet() const {
return false; return false;
} }
virtual bool isValid() const {
return true;
}
private : private :
QJsonObject jObj; QJsonObject jObj;
}; };

View File

@ -8,7 +8,7 @@
PetApiTests::PetApiTests () {} PetApiTests::PetApiTests () {}
PetApiTests::~PetApiTests () { PetApiTests::~PetApiTests () {
exit(1);
} }
OAIPetApi* PetApiTests::getApi() { OAIPetApi* PetApiTests::getApi() {
@ -35,7 +35,6 @@ void PetApiTests::runTests() {
void PetApiTests::findPetsByStatusTest() { void PetApiTests::findPetsByStatusTest() {
OAIPetApi* api = getApi(); OAIPetApi* api = getApi();
QEventLoop loop; QEventLoop loop;
QTimer timer; QTimer timer;
timer.setInterval(14000); timer.setInterval(14000);

View File

@ -19,6 +19,8 @@ TEMPLATE = app
include(../client/client.pri) include(../client/client.pri)
SOURCES += main.cpp \ SOURCES += main.cpp \
PetApiTests.cpp PetApiTests.cpp \
StoreApiTests.cpp
HEADERS += PetApiTests.h HEADERS += PetApiTests.h \
StoreApiTests.h

View File

@ -0,0 +1,117 @@
#include "StoreApiTests.h"
#include <QJsonDocument>
#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QDebug>
StoreApiTests::StoreApiTests () {}
StoreApiTests::~StoreApiTests () {
exit(1);
}
OAIStoreApi* StoreApiTests::getApi() {
auto api = new OAIStoreApi();
api->host = "http://petstore.swagger.io";
api->basePath = "/v2";
return api;
}
void StoreApiTests::runTests() {
StoreApiTests* tests = new StoreApiTests();
QTest::qExec(tests);
delete tests;
}
void StoreApiTests::placeOrderTest() {
auto api = getApi();
QEventLoop loop;
QTimer timer;
timer.setInterval(14000);
timer.setSingleShot(true);
auto validator = [this](OAIOrder order) {
QVERIFY(order.getPetId() == 10000);
QVERIFY((order.getId() == 500));
qDebug() << order.getShipDate();
emit quit();
};
auto finalizer = [&]() {
loop.quit();
};
connect(this, &StoreApiTests::quit, finalizer);
connect(api, &OAIStoreApi::placeOrderSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, finalizer);
OAIOrder order;
order.setId(500);
order.setQuantity(10);
order.setPetId(10000);
order.setComplete(false);
order.setStatus(QString("shipping"));
order.setShipDate(QDateTime::currentDateTime());
api->placeOrder(order);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
disconnect(this, nullptr, nullptr, nullptr);
delete api;
}
void StoreApiTests::getOrderByIdTest() {
auto api = getApi();
QEventLoop loop;
QTimer timer;
timer.setInterval(14000);
timer.setSingleShot(true);
auto validator = [this](OAIOrder order) {
QVERIFY(order.getPetId() == 10000);
QVERIFY((order.getId() == 500));
qDebug() << order.getShipDate();
emit quit();
};
auto finalizer = [&]() {
loop.quit();
};
connect(this, &StoreApiTests::quit, finalizer);
connect(api, &OAIStoreApi::getOrderByIdSignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, finalizer);
api->getOrderById(500);
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
disconnect(this, nullptr, nullptr, nullptr);
delete api;
}
void StoreApiTests::getInventoryTest() {
auto api = getApi();
QEventLoop loop;
QTimer timer;
timer.setInterval(14000);
timer.setSingleShot(true);
auto validator = [this](QMap<QString, qint32> status) {
for(const auto& key : status.keys()) {
qDebug() << (key) << " Quantities " << status.value(key);
}
emit quit();
};
auto finalizer = [&]() {
loop.quit();
};
connect(this, &StoreApiTests::quit, finalizer);
connect(api, &OAIStoreApi::getInventorySignal, this, validator);
connect(&timer, &QTimer::timeout, &loop, finalizer);
api->getInventory();
timer.start();
loop.exec();
QVERIFY2(timer.isActive(), "didn't finish within timeout");
disconnect(this, nullptr, nullptr, nullptr);
delete api;
}

View File

@ -0,0 +1,32 @@
#ifndef STOREAPITESTS_H
#define STOREAPITESTS_H
#include <QtTest/QtTest>
#include <QTimer>
#include "../client/OAIStoreApi.h"
using namespace OpenAPI;
class StoreApiTests: public QObject {
Q_OBJECT
public:
StoreApiTests();
virtual ~StoreApiTests();
static void runTests();
private:
OAIStoreApi* getApi();
OAIOrder createRandomOrder();
signals:
void quit();
bool success();
private slots:
void placeOrderTest();
void getOrderByIdTest();
void getInventoryTest();
};
#endif // STOREAPITESTS_H

View File

@ -1,8 +1,10 @@
#include <QCoreApplication> #include <QCoreApplication>
#include "PetApiTests.h" #include "PetApiTests.h"
#include "StoreApiTests.h"
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv); QCoreApplication a(argc, argv);
PetApiTests::runTests(); PetApiTests::runTests();
StoreApiTests::runTests();
return a.exec(); return a.exec();
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIApiResponse::OAIApiResponse(QString json) { OAIApiResponse::OAIApiResponse(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,8 +38,11 @@ OAIApiResponse::~OAIApiResponse() {
void void
OAIApiResponse::init() { OAIApiResponse::init() {
m_code_isSet = false; m_code_isSet = false;
m_code_isValid = false;
m_type_isSet = false; m_type_isSet = false;
m_type_isValid = false;
m_message_isSet = false; m_message_isSet = false;
m_message_isValid = false;
} }
void void
@ -51,11 +55,11 @@ OAIApiResponse::fromJson(QString jsonString) {
void void
OAIApiResponse::fromJsonObject(QJsonObject json) { OAIApiResponse::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(code, json[QString("code")]); m_code_isValid = ::OpenAPI::fromJsonValue(code, json[QString("code")]);
::OpenAPI::fromJsonValue(type, json[QString("type")]); m_type_isValid = ::OpenAPI::fromJsonValue(type, json[QString("type")]);
::OpenAPI::fromJsonValue(message, json[QString("message")]); m_message_isValid = ::OpenAPI::fromJsonValue(message, json[QString("message")]);
} }
@ -112,7 +116,6 @@ OAIApiResponse::setMessage(const QString &message) {
this->m_message_isSet = true; this->m_message_isSet = true;
} }
bool bool
OAIApiResponse::isSet() const { OAIApiResponse::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -126,5 +129,11 @@ OAIApiResponse::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIApiResponse::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -50,17 +50,18 @@ public:
void setMessage(const QString &message); void setMessage(const QString &message);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint32 code; qint32 code;
bool m_code_isSet; bool m_code_isSet;
bool m_code_isValid;
QString type; QString type;
bool m_type_isSet; bool m_type_isSet;
bool m_type_isValid;
QString message; QString message;
bool m_message_isSet; bool m_message_isSet;
bool m_message_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAICategory::OAICategory(QString json) { OAICategory::OAICategory(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,7 +38,9 @@ OAICategory::~OAICategory() {
void void
OAICategory::init() { OAICategory::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
} }
void void
@ -50,9 +53,9 @@ OAICategory::fromJson(QString jsonString) {
void void
OAICategory::fromJsonObject(QJsonObject json) { OAICategory::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
} }
@ -96,7 +99,6 @@ OAICategory::setName(const QString &name) {
this->m_name_isSet = true; this->m_name_isSet = true;
} }
bool bool
OAICategory::isSet() const { OAICategory::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -108,5 +110,11 @@ OAICategory::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAICategory::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -47,14 +47,15 @@ public:
void setName(const QString &name); void setName(const QString &name);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
}; };
} }

View File

@ -56,7 +56,7 @@ toStringValue(const bool &value) {
QString QString
toStringValue(const float &value){ toStringValue(const float &value){
return QString::number(value); return QString::number(static_cast<double>(value));
} }
QString QString
@ -101,7 +101,7 @@ toJsonValue(const bool &value){
QJsonValue QJsonValue
toJsonValue(const float &value){ toJsonValue(const float &value){
return QJsonValue(value); return QJsonValue(static_cast<double>(value));
} }
QJsonValue QJsonValue
@ -202,88 +202,126 @@ fromStringValue(const QString &inStr, double &value){
return ok; return ok;
} }
void bool
fromJsonValue(QString &value, const QJsonValue &jval){ fromJsonValue(QString &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull()){
if(jval.isString()){ if(jval.isString()){
value = jval.toString(); value = jval.toString();
} else if(jval.isBool()) { } else if(jval.isBool()) {
value = jval.toBool() ? "true" : "false"; value = jval.toBool() ? "true" : "false";
} else if(jval.isDouble()){ } else if(jval.isDouble()){
value = QString::number(jval.toDouble()); value = QString::number(jval.toDouble());
} else {
ok = false;
} }
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDateTime &value, const QJsonValue &jval){ fromJsonValue(QDateTime &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDateTime::fromString(jval.toString(), Qt::ISODate); value = QDateTime::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QByteArray &value, const QJsonValue &jval){ fromJsonValue(QByteArray &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()) {
value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString())); value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString()));
ok = value.size() > 0 ;
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDate &value, const QJsonValue &jval){ fromJsonValue(QDate &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDate::fromString(jval.toString(), Qt::ISODate); value = QDate::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint32 &value, const QJsonValue &jval){ fromJsonValue(qint32 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toInt(); value = jval.toInt();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint64 &value, const QJsonValue &jval){ fromJsonValue(qint64 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toVariant().toLongLong(); value = jval.toVariant().toLongLong();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(bool &value, const QJsonValue &jval){ fromJsonValue(bool &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isBool()){
value = jval.toBool(); value = jval.toBool();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(float &value, const QJsonValue &jval){ fromJsonValue(float &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = static_cast<float>(jval.toDouble()); value = static_cast<float>(jval.toDouble());
} else {
ok = false;
} }
return ok;
} }
void bool
fromJsonValue(double &value, const QJsonValue &jval){ fromJsonValue(double &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = jval.toDouble(); value = jval.toDouble();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(OAIObject &value, const QJsonValue &jval){ fromJsonValue(OAIObject &value, const QJsonValue &jval){
bool ok = true;
if(jval.isObject()){ if(jval.isObject()){
value.fromJsonObject(jval.toObject()); value.fromJsonObject(jval.toObject());
ok = value.isValid();
} else {
ok = false;
} }
return ok;
} }
} }

View File

@ -39,7 +39,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QString toStringValue(const QList<T> &val) { QString toStringValue(const QList<T> &val) {
QString strArray; QString strArray;
for(auto item : val) { for(const auto& item : val) {
strArray.append(toStringValue(item) + ","); strArray.append(toStringValue(item) + ",");
} }
if(val.count() > 0) { if(val.count() > 0) {
@ -62,7 +62,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QList<T> &val) { QJsonValue toJsonValue(const QList<T> &val) {
QJsonArray jArray; QJsonArray jArray;
for(auto item : val) { for(const auto& item : val) {
jArray.append(toJsonValue(item)); jArray.append(toJsonValue(item));
} }
return jArray; return jArray;
@ -71,7 +71,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QMap<QString, T> &val) { QJsonValue toJsonValue(const QMap<QString, T> &val) {
QJsonObject jObject; QJsonObject jObject;
for(auto itemkey : val.keys()) { for(const auto& itemkey : val.keys()) {
jObject.insert(itemkey, toJsonValue(val.value(itemkey))); jObject.insert(itemkey, toJsonValue(val.value(itemkey)));
} }
return jObject; return jObject;
@ -88,56 +88,69 @@ namespace OpenAPI {
bool fromStringValue(const QString &inStr, double &value); bool fromStringValue(const QString &inStr, double &value);
template <typename T> template <typename T>
void fromStringValue(const QList<QString> &inStr, QList<T> &val) { bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
for(auto item: inStr){ bool ok = (inStr.count() > 0);
for(const auto& item: inStr){
T itemVal; T itemVal;
fromStringValue(item, itemVal); ok &= fromStringValue(item, itemVal);
val.push_back(itemVal); val.push_back(itemVal);
} }
return ok;
} }
template <typename T> template <typename T>
void fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) { bool fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) {
for(auto itemkey : inStr.keys()){ bool ok = (inStr.count() > 0);
for(const auto& itemkey : inStr.keys()){
T itemVal; T itemVal;
fromStringValue(inStr.value(itemkey), itemVal); ok &= fromStringValue(inStr.value(itemkey), itemVal);
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
return ok;
} }
void fromJsonValue(QString &value, const QJsonValue &jval); bool fromJsonValue(QString &value, const QJsonValue &jval);
void fromJsonValue(QDateTime &value, const QJsonValue &jval); bool fromJsonValue(QDateTime &value, const QJsonValue &jval);
void fromJsonValue(QByteArray &value, const QJsonValue &jval); bool fromJsonValue(QByteArray &value, const QJsonValue &jval);
void fromJsonValue(QDate &value, const QJsonValue &jval); bool fromJsonValue(QDate &value, const QJsonValue &jval);
void fromJsonValue(qint32 &value, const QJsonValue &jval); bool fromJsonValue(qint32 &value, const QJsonValue &jval);
void fromJsonValue(qint64 &value, const QJsonValue &jval); bool fromJsonValue(qint64 &value, const QJsonValue &jval);
void fromJsonValue(bool &value, const QJsonValue &jval); bool fromJsonValue(bool &value, const QJsonValue &jval);
void fromJsonValue(float &value, const QJsonValue &jval); bool fromJsonValue(float &value, const QJsonValue &jval);
void fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue(double &value, const QJsonValue &jval);
void fromJsonValue(OAIObject &value, const QJsonValue &jval); bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
template <typename T> template <typename T>
void fromJsonValue(QList<T> &val, const QJsonValue &jval) { bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isArray()){ if(jval.isArray()){
for(const QJsonValue &jitem : jval.toArray()){ for(const auto& jitem : jval.toArray()){
T item; T item;
fromJsonValue(item, jitem); ok &= fromJsonValue(item, jitem);
val.push_back(item); val.push_back(item);
} }
} else {
ok = false;
} }
return ok;
} }
template <typename T> template <typename T>
void fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) { bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isObject()){
auto varmap = jval.toObject().toVariantMap(); auto varmap = jval.toObject().toVariantMap();
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto itemkey : varmap.keys() ){ for(const auto& itemkey : varmap.keys() ){
T itemVal; T itemVal;
fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey))); ok &= fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey)));
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
} }
return; } else {
ok = false;
}
return ok;
} }
} }

View File

@ -62,6 +62,10 @@ OAIHttpRequestWorker::OAIHttpRequestWorker(QObject *parent)
OAIHttpRequestWorker::~OAIHttpRequestWorker() { OAIHttpRequestWorker::~OAIHttpRequestWorker() {
} }
QMap<QByteArray, QByteArray> OAIHttpRequestWorker::getResponseHeaders() const {
return headers;
}
QString OAIHttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) { QString OAIHttpRequestWorker::http_attribute_encode(QString attribute_name, QString input) {
// result structure follows RFC 5987 // result structure follows RFC 5987
bool need_utf_encoding = false; bool need_utf_encoding = false;
@ -314,7 +318,11 @@ void OAIHttpRequestWorker::on_manager_finished(QNetworkReply *reply) {
error_type = reply->error(); error_type = reply->error();
response = reply->readAll(); response = reply->readAll();
error_str = reply->errorString(); error_str = reply->errorString();
if(reply->rawHeaderPairs().count() > 0){
for(const auto& item: reply->rawHeaderPairs()){
headers.insert(item.first, item.second);
}
}
reply->deleteLater(); reply->deleteLater();
emit on_execution_finished(this); emit on_execution_finished(this);

View File

@ -70,9 +70,10 @@ public:
QNetworkReply::NetworkError error_type; QNetworkReply::NetworkError error_type;
QString error_str; QString error_str;
explicit OAIHttpRequestWorker(QObject *parent = 0); explicit OAIHttpRequestWorker(QObject *parent = nullptr);
virtual ~OAIHttpRequestWorker(); virtual ~OAIHttpRequestWorker();
QMap<QByteArray, QByteArray> getResponseHeaders() const;
QString http_attribute_encode(QString attribute_name, QString input); QString http_attribute_encode(QString attribute_name, QString input);
void execute(OAIHttpRequestInput *input); void execute(OAIHttpRequestInput *input);
static QSslConfiguration* sslDefaultConfiguration; static QSslConfiguration* sslDefaultConfiguration;
@ -82,7 +83,7 @@ signals:
private: private:
QNetworkAccessManager *manager; QNetworkAccessManager *manager;
QMap<QByteArray, QByteArray> headers;
private slots: private slots:
void on_manager_finished(QNetworkReply *reply); void on_manager_finished(QNetworkReply *reply);

View File

@ -45,6 +45,10 @@ class OAIObject {
virtual bool isSet() const { virtual bool isSet() const {
return false; return false;
} }
virtual bool isValid() const {
return true;
}
private : private :
QJsonObject jObj; QJsonObject jObj;
}; };

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIOrder::OAIOrder(QString json) { OAIOrder::OAIOrder(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,11 +38,17 @@ OAIOrder::~OAIOrder() {
void void
OAIOrder::init() { OAIOrder::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_pet_id_isSet = false; m_pet_id_isSet = false;
m_pet_id_isValid = false;
m_quantity_isSet = false; m_quantity_isSet = false;
m_quantity_isValid = false;
m_ship_date_isSet = false; m_ship_date_isSet = false;
m_ship_date_isValid = false;
m_status_isSet = false; m_status_isSet = false;
m_status_isValid = false;
m_complete_isSet = false; m_complete_isSet = false;
m_complete_isValid = false;
} }
void void
@ -54,17 +61,17 @@ OAIOrder::fromJson(QString jsonString) {
void void
OAIOrder::fromJsonObject(QJsonObject json) { OAIOrder::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(pet_id, json[QString("petId")]); m_pet_id_isValid = ::OpenAPI::fromJsonValue(pet_id, json[QString("petId")]);
::OpenAPI::fromJsonValue(quantity, json[QString("quantity")]); m_quantity_isValid = ::OpenAPI::fromJsonValue(quantity, json[QString("quantity")]);
::OpenAPI::fromJsonValue(ship_date, json[QString("shipDate")]); m_ship_date_isValid = ::OpenAPI::fromJsonValue(ship_date, json[QString("shipDate")]);
::OpenAPI::fromJsonValue(status, json[QString("status")]); m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
::OpenAPI::fromJsonValue(complete, json[QString("complete")]); m_complete_isValid = ::OpenAPI::fromJsonValue(complete, json[QString("complete")]);
} }
@ -160,7 +167,6 @@ OAIOrder::setComplete(const bool &complete) {
this->m_complete_isSet = true; this->m_complete_isSet = true;
} }
bool bool
OAIOrder::isSet() const { OAIOrder::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -180,5 +186,11 @@ OAIOrder::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIOrder::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -60,26 +60,27 @@ public:
void setComplete(const bool &complete); void setComplete(const bool &complete);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
qint64 pet_id; qint64 pet_id;
bool m_pet_id_isSet; bool m_pet_id_isSet;
bool m_pet_id_isValid;
qint32 quantity; qint32 quantity;
bool m_quantity_isSet; bool m_quantity_isSet;
bool m_quantity_isValid;
QDateTime ship_date; QDateTime ship_date;
bool m_ship_date_isSet; bool m_ship_date_isSet;
bool m_ship_date_isValid;
QString status; QString status;
bool m_status_isSet; bool m_status_isSet;
bool m_status_isValid;
bool complete; bool complete;
bool m_complete_isSet; bool m_complete_isSet;
bool m_complete_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIPet::OAIPet(QString json) { OAIPet::OAIPet(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,11 +38,17 @@ OAIPet::~OAIPet() {
void void
OAIPet::init() { OAIPet::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_category_isSet = false; m_category_isSet = false;
m_category_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
m_photo_urls_isSet = false; m_photo_urls_isSet = false;
m_photo_urls_isValid = false;
m_tags_isSet = false; m_tags_isSet = false;
m_tags_isValid = false;
m_status_isSet = false; m_status_isSet = false;
m_status_isValid = false;
} }
void void
@ -54,17 +61,17 @@ OAIPet::fromJson(QString jsonString) {
void void
OAIPet::fromJsonObject(QJsonObject json) { OAIPet::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(category, json[QString("category")]); m_category_isValid = ::OpenAPI::fromJsonValue(category, json[QString("category")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
::OpenAPI::fromJsonValue(photo_urls, json[QString("photoUrls")]); m_photo_urls_isValid = ::OpenAPI::fromJsonValue(photo_urls, json[QString("photoUrls")]);
::OpenAPI::fromJsonValue(tags, json[QString("tags")]); m_tags_isValid = ::OpenAPI::fromJsonValue(tags, json[QString("tags")]);
::OpenAPI::fromJsonValue(status, json[QString("status")]); m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
} }
@ -162,7 +169,6 @@ OAIPet::setStatus(const QString &status) {
this->m_status_isSet = true; this->m_status_isSet = true;
} }
bool bool
OAIPet::isSet() const { OAIPet::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -182,5 +188,11 @@ OAIPet::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIPet::isValid() const {
// only required properties are required for the object to be considered valid
return m_name_isValid && m_photo_urls_isValid && true;
}
} }

View File

@ -62,26 +62,27 @@ public:
void setStatus(const QString &status); void setStatus(const QString &status);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
OAICategory category; OAICategory category;
bool m_category_isSet; bool m_category_isSet;
bool m_category_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
QList<QString> photo_urls; QList<QString> photo_urls;
bool m_photo_urls_isSet; bool m_photo_urls_isSet;
bool m_photo_urls_isValid;
QList<OAITag> tags; QList<OAITag> tags;
bool m_tags_isSet; bool m_tags_isSet;
bool m_tags_isValid;
QString status; QString status;
bool m_status_isSet; bool m_status_isSet;
bool m_status_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAITag::OAITag(QString json) { OAITag::OAITag(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,7 +38,9 @@ OAITag::~OAITag() {
void void
OAITag::init() { OAITag::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
} }
void void
@ -50,9 +53,9 @@ OAITag::fromJson(QString jsonString) {
void void
OAITag::fromJsonObject(QJsonObject json) { OAITag::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
} }
@ -96,7 +99,6 @@ OAITag::setName(const QString &name) {
this->m_name_isSet = true; this->m_name_isSet = true;
} }
bool bool
OAITag::isSet() const { OAITag::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -108,5 +110,11 @@ OAITag::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAITag::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -47,14 +47,15 @@ public:
void setName(const QString &name); void setName(const QString &name);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIUser::OAIUser(QString json) { OAIUser::OAIUser(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,13 +38,21 @@ OAIUser::~OAIUser() {
void void
OAIUser::init() { OAIUser::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_username_isSet = false; m_username_isSet = false;
m_username_isValid = false;
m_first_name_isSet = false; m_first_name_isSet = false;
m_first_name_isValid = false;
m_last_name_isSet = false; m_last_name_isSet = false;
m_last_name_isValid = false;
m_email_isSet = false; m_email_isSet = false;
m_email_isValid = false;
m_password_isSet = false; m_password_isSet = false;
m_password_isValid = false;
m_phone_isSet = false; m_phone_isSet = false;
m_phone_isValid = false;
m_user_status_isSet = false; m_user_status_isSet = false;
m_user_status_isValid = false;
} }
void void
@ -56,21 +65,21 @@ OAIUser::fromJson(QString jsonString) {
void void
OAIUser::fromJsonObject(QJsonObject json) { OAIUser::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(username, json[QString("username")]); m_username_isValid = ::OpenAPI::fromJsonValue(username, json[QString("username")]);
::OpenAPI::fromJsonValue(first_name, json[QString("firstName")]); m_first_name_isValid = ::OpenAPI::fromJsonValue(first_name, json[QString("firstName")]);
::OpenAPI::fromJsonValue(last_name, json[QString("lastName")]); m_last_name_isValid = ::OpenAPI::fromJsonValue(last_name, json[QString("lastName")]);
::OpenAPI::fromJsonValue(email, json[QString("email")]); m_email_isValid = ::OpenAPI::fromJsonValue(email, json[QString("email")]);
::OpenAPI::fromJsonValue(password, json[QString("password")]); m_password_isValid = ::OpenAPI::fromJsonValue(password, json[QString("password")]);
::OpenAPI::fromJsonValue(phone, json[QString("phone")]); m_phone_isValid = ::OpenAPI::fromJsonValue(phone, json[QString("phone")]);
::OpenAPI::fromJsonValue(user_status, json[QString("userStatus")]); m_user_status_isValid = ::OpenAPI::fromJsonValue(user_status, json[QString("userStatus")]);
} }
@ -192,7 +201,6 @@ OAIUser::setUserStatus(const qint32 &user_status) {
this->m_user_status_isSet = true; this->m_user_status_isSet = true;
} }
bool bool
OAIUser::isSet() const { OAIUser::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -216,5 +224,11 @@ OAIUser::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIUser::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -65,32 +65,33 @@ public:
void setUserStatus(const qint32 &user_status); void setUserStatus(const qint32 &user_status);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString username; QString username;
bool m_username_isSet; bool m_username_isSet;
bool m_username_isValid;
QString first_name; QString first_name;
bool m_first_name_isSet; bool m_first_name_isSet;
bool m_first_name_isValid;
QString last_name; QString last_name;
bool m_last_name_isSet; bool m_last_name_isSet;
bool m_last_name_isValid;
QString email; QString email;
bool m_email_isSet; bool m_email_isSet;
bool m_email_isValid;
QString password; QString password;
bool m_password_isSet; bool m_password_isSet;
bool m_password_isValid;
QString phone; QString phone;
bool m_phone_isSet; bool m_phone_isSet;
bool m_phone_isValid;
qint32 user_status; qint32 user_status;
bool m_user_status_isSet; bool m_user_status_isSet;
bool m_user_status_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIApiResponse::OAIApiResponse(QString json) { OAIApiResponse::OAIApiResponse(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,8 +38,11 @@ OAIApiResponse::~OAIApiResponse() {
void void
OAIApiResponse::init() { OAIApiResponse::init() {
m_code_isSet = false; m_code_isSet = false;
m_code_isValid = false;
m_type_isSet = false; m_type_isSet = false;
m_type_isValid = false;
m_message_isSet = false; m_message_isSet = false;
m_message_isValid = false;
} }
void void
@ -51,11 +55,11 @@ OAIApiResponse::fromJson(QString jsonString) {
void void
OAIApiResponse::fromJsonObject(QJsonObject json) { OAIApiResponse::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(code, json[QString("code")]); m_code_isValid = ::OpenAPI::fromJsonValue(code, json[QString("code")]);
::OpenAPI::fromJsonValue(type, json[QString("type")]); m_type_isValid = ::OpenAPI::fromJsonValue(type, json[QString("type")]);
::OpenAPI::fromJsonValue(message, json[QString("message")]); m_message_isValid = ::OpenAPI::fromJsonValue(message, json[QString("message")]);
} }
@ -112,7 +116,6 @@ OAIApiResponse::setMessage(const QString &message) {
this->m_message_isSet = true; this->m_message_isSet = true;
} }
bool bool
OAIApiResponse::isSet() const { OAIApiResponse::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -126,5 +129,11 @@ OAIApiResponse::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIApiResponse::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -50,17 +50,18 @@ public:
void setMessage(const QString &message); void setMessage(const QString &message);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint32 code; qint32 code;
bool m_code_isSet; bool m_code_isSet;
bool m_code_isValid;
QString type; QString type;
bool m_type_isSet; bool m_type_isSet;
bool m_type_isValid;
QString message; QString message;
bool m_message_isSet; bool m_message_isSet;
bool m_message_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAICategory::OAICategory(QString json) { OAICategory::OAICategory(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,7 +38,9 @@ OAICategory::~OAICategory() {
void void
OAICategory::init() { OAICategory::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
} }
void void
@ -50,9 +53,9 @@ OAICategory::fromJson(QString jsonString) {
void void
OAICategory::fromJsonObject(QJsonObject json) { OAICategory::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
} }
@ -96,7 +99,6 @@ OAICategory::setName(const QString &name) {
this->m_name_isSet = true; this->m_name_isSet = true;
} }
bool bool
OAICategory::isSet() const { OAICategory::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -108,5 +110,11 @@ OAICategory::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAICategory::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -47,14 +47,15 @@ public:
void setName(const QString &name); void setName(const QString &name);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
}; };
} }

View File

@ -56,7 +56,7 @@ toStringValue(const bool &value) {
QString QString
toStringValue(const float &value){ toStringValue(const float &value){
return QString::number(value); return QString::number(static_cast<double>(value));
} }
QString QString
@ -101,7 +101,7 @@ toJsonValue(const bool &value){
QJsonValue QJsonValue
toJsonValue(const float &value){ toJsonValue(const float &value){
return QJsonValue(value); return QJsonValue(static_cast<double>(value));
} }
QJsonValue QJsonValue
@ -202,88 +202,126 @@ fromStringValue(const QString &inStr, double &value){
return ok; return ok;
} }
void bool
fromJsonValue(QString &value, const QJsonValue &jval){ fromJsonValue(QString &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull()){
if(jval.isString()){ if(jval.isString()){
value = jval.toString(); value = jval.toString();
} else if(jval.isBool()) { } else if(jval.isBool()) {
value = jval.toBool() ? "true" : "false"; value = jval.toBool() ? "true" : "false";
} else if(jval.isDouble()){ } else if(jval.isDouble()){
value = QString::number(jval.toDouble()); value = QString::number(jval.toDouble());
} else {
ok = false;
} }
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDateTime &value, const QJsonValue &jval){ fromJsonValue(QDateTime &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDateTime::fromString(jval.toString(), Qt::ISODate); value = QDateTime::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QByteArray &value, const QJsonValue &jval){ fromJsonValue(QByteArray &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()) {
value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString())); value = QByteArray::fromBase64(QByteArray::fromStdString(jval.toString().toStdString()));
ok = value.size() > 0 ;
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(QDate &value, const QJsonValue &jval){ fromJsonValue(QDate &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && jval.isString()){
value = QDate::fromString(jval.toString(), Qt::ISODate); value = QDate::fromString(jval.toString(), Qt::ISODate);
ok = value.isValid();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint32 &value, const QJsonValue &jval){ fromJsonValue(qint32 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toInt(); value = jval.toInt();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(qint64 &value, const QJsonValue &jval){ fromJsonValue(qint64 &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(!jval.isUndefined() && !jval.isNull() && !jval.isObject() && !jval.isArray()){
value = jval.toVariant().toLongLong(); value = jval.toVariant().toLongLong();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(bool &value, const QJsonValue &jval){ fromJsonValue(bool &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isBool()){
value = jval.toBool(); value = jval.toBool();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(float &value, const QJsonValue &jval){ fromJsonValue(float &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = static_cast<float>(jval.toDouble()); value = static_cast<float>(jval.toDouble());
} else {
ok = false;
} }
return ok;
} }
void bool
fromJsonValue(double &value, const QJsonValue &jval){ fromJsonValue(double &value, const QJsonValue &jval){
if(!(jval.isUndefined() || jval.isNull())){ bool ok = true;
if(jval.isDouble()){
value = jval.toDouble(); value = jval.toDouble();
} else {
ok = false;
}
return ok;
} }
} bool
void
fromJsonValue(OAIObject &value, const QJsonValue &jval){ fromJsonValue(OAIObject &value, const QJsonValue &jval){
bool ok = true;
if(jval.isObject()){ if(jval.isObject()){
value.fromJsonObject(jval.toObject()); value.fromJsonObject(jval.toObject());
ok = value.isValid();
} else {
ok = false;
} }
return ok;
} }
} }

View File

@ -39,7 +39,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QString toStringValue(const QList<T> &val) { QString toStringValue(const QList<T> &val) {
QString strArray; QString strArray;
for(auto item : val) { for(const auto& item : val) {
strArray.append(toStringValue(item) + ","); strArray.append(toStringValue(item) + ",");
} }
if(val.count() > 0) { if(val.count() > 0) {
@ -62,7 +62,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QList<T> &val) { QJsonValue toJsonValue(const QList<T> &val) {
QJsonArray jArray; QJsonArray jArray;
for(auto item : val) { for(const auto& item : val) {
jArray.append(toJsonValue(item)); jArray.append(toJsonValue(item));
} }
return jArray; return jArray;
@ -71,7 +71,7 @@ namespace OpenAPI {
template <typename T> template <typename T>
QJsonValue toJsonValue(const QMap<QString, T> &val) { QJsonValue toJsonValue(const QMap<QString, T> &val) {
QJsonObject jObject; QJsonObject jObject;
for(auto itemkey : val.keys()) { for(const auto& itemkey : val.keys()) {
jObject.insert(itemkey, toJsonValue(val.value(itemkey))); jObject.insert(itemkey, toJsonValue(val.value(itemkey)));
} }
return jObject; return jObject;
@ -88,56 +88,69 @@ namespace OpenAPI {
bool fromStringValue(const QString &inStr, double &value); bool fromStringValue(const QString &inStr, double &value);
template <typename T> template <typename T>
void fromStringValue(const QList<QString> &inStr, QList<T> &val) { bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
for(auto item: inStr){ bool ok = (inStr.count() > 0);
for(const auto& item: inStr){
T itemVal; T itemVal;
fromStringValue(item, itemVal); ok &= fromStringValue(item, itemVal);
val.push_back(itemVal); val.push_back(itemVal);
} }
return ok;
} }
template <typename T> template <typename T>
void fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) { bool fromStringValue(const QMap<QString, QString> &inStr, QMap<QString, T> &val) {
for(auto itemkey : inStr.keys()){ bool ok = (inStr.count() > 0);
for(const auto& itemkey : inStr.keys()){
T itemVal; T itemVal;
fromStringValue(inStr.value(itemkey), itemVal); ok &= fromStringValue(inStr.value(itemkey), itemVal);
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
return ok;
} }
void fromJsonValue(QString &value, const QJsonValue &jval); bool fromJsonValue(QString &value, const QJsonValue &jval);
void fromJsonValue(QDateTime &value, const QJsonValue &jval); bool fromJsonValue(QDateTime &value, const QJsonValue &jval);
void fromJsonValue(QByteArray &value, const QJsonValue &jval); bool fromJsonValue(QByteArray &value, const QJsonValue &jval);
void fromJsonValue(QDate &value, const QJsonValue &jval); bool fromJsonValue(QDate &value, const QJsonValue &jval);
void fromJsonValue(qint32 &value, const QJsonValue &jval); bool fromJsonValue(qint32 &value, const QJsonValue &jval);
void fromJsonValue(qint64 &value, const QJsonValue &jval); bool fromJsonValue(qint64 &value, const QJsonValue &jval);
void fromJsonValue(bool &value, const QJsonValue &jval); bool fromJsonValue(bool &value, const QJsonValue &jval);
void fromJsonValue(float &value, const QJsonValue &jval); bool fromJsonValue(float &value, const QJsonValue &jval);
void fromJsonValue(double &value, const QJsonValue &jval); bool fromJsonValue(double &value, const QJsonValue &jval);
void fromJsonValue(OAIObject &value, const QJsonValue &jval); bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
template <typename T> template <typename T>
void fromJsonValue(QList<T> &val, const QJsonValue &jval) { bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isArray()){ if(jval.isArray()){
for(const QJsonValue &jitem : jval.toArray()){ for(const auto& jitem : jval.toArray()){
T item; T item;
fromJsonValue(item, jitem); ok &= fromJsonValue(item, jitem);
val.push_back(item); val.push_back(item);
} }
} else {
ok = false;
} }
return ok;
} }
template <typename T> template <typename T>
void fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) { bool fromJsonValue(QMap<QString, T> &val, const QJsonValue &jval) {
bool ok = true;
if(jval.isObject()){
auto varmap = jval.toObject().toVariantMap(); auto varmap = jval.toObject().toVariantMap();
if(varmap.count() > 0){ if(varmap.count() > 0){
for(auto itemkey : varmap.keys() ){ for(const auto& itemkey : varmap.keys() ){
T itemVal; T itemVal;
fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey))); ok &= fromJsonValue(itemVal, QJsonValue::fromVariant(varmap.value(itemkey)));
val.insert(itemkey, itemVal); val.insert(itemkey, itemVal);
} }
} }
return; } else {
ok = false;
}
return ok;
} }
} }

View File

@ -45,6 +45,10 @@ class OAIObject {
virtual bool isSet() const { virtual bool isSet() const {
return false; return false;
} }
virtual bool isValid() const {
return true;
}
private : private :
QJsonObject jObj; QJsonObject jObj;
}; };

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIOrder::OAIOrder(QString json) { OAIOrder::OAIOrder(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,11 +38,17 @@ OAIOrder::~OAIOrder() {
void void
OAIOrder::init() { OAIOrder::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_pet_id_isSet = false; m_pet_id_isSet = false;
m_pet_id_isValid = false;
m_quantity_isSet = false; m_quantity_isSet = false;
m_quantity_isValid = false;
m_ship_date_isSet = false; m_ship_date_isSet = false;
m_ship_date_isValid = false;
m_status_isSet = false; m_status_isSet = false;
m_status_isValid = false;
m_complete_isSet = false; m_complete_isSet = false;
m_complete_isValid = false;
} }
void void
@ -54,17 +61,17 @@ OAIOrder::fromJson(QString jsonString) {
void void
OAIOrder::fromJsonObject(QJsonObject json) { OAIOrder::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(pet_id, json[QString("petId")]); m_pet_id_isValid = ::OpenAPI::fromJsonValue(pet_id, json[QString("petId")]);
::OpenAPI::fromJsonValue(quantity, json[QString("quantity")]); m_quantity_isValid = ::OpenAPI::fromJsonValue(quantity, json[QString("quantity")]);
::OpenAPI::fromJsonValue(ship_date, json[QString("shipDate")]); m_ship_date_isValid = ::OpenAPI::fromJsonValue(ship_date, json[QString("shipDate")]);
::OpenAPI::fromJsonValue(status, json[QString("status")]); m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
::OpenAPI::fromJsonValue(complete, json[QString("complete")]); m_complete_isValid = ::OpenAPI::fromJsonValue(complete, json[QString("complete")]);
} }
@ -160,7 +167,6 @@ OAIOrder::setComplete(const bool &complete) {
this->m_complete_isSet = true; this->m_complete_isSet = true;
} }
bool bool
OAIOrder::isSet() const { OAIOrder::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -180,5 +186,11 @@ OAIOrder::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIOrder::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -60,26 +60,27 @@ public:
void setComplete(const bool &complete); void setComplete(const bool &complete);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
qint64 pet_id; qint64 pet_id;
bool m_pet_id_isSet; bool m_pet_id_isSet;
bool m_pet_id_isValid;
qint32 quantity; qint32 quantity;
bool m_quantity_isSet; bool m_quantity_isSet;
bool m_quantity_isValid;
QDateTime ship_date; QDateTime ship_date;
bool m_ship_date_isSet; bool m_ship_date_isSet;
bool m_ship_date_isValid;
QString status; QString status;
bool m_status_isSet; bool m_status_isSet;
bool m_status_isValid;
bool complete; bool complete;
bool m_complete_isSet; bool m_complete_isSet;
bool m_complete_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIPet::OAIPet(QString json) { OAIPet::OAIPet(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,11 +38,17 @@ OAIPet::~OAIPet() {
void void
OAIPet::init() { OAIPet::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_category_isSet = false; m_category_isSet = false;
m_category_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
m_photo_urls_isSet = false; m_photo_urls_isSet = false;
m_photo_urls_isValid = false;
m_tags_isSet = false; m_tags_isSet = false;
m_tags_isValid = false;
m_status_isSet = false; m_status_isSet = false;
m_status_isValid = false;
} }
void void
@ -54,17 +61,17 @@ OAIPet::fromJson(QString jsonString) {
void void
OAIPet::fromJsonObject(QJsonObject json) { OAIPet::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(category, json[QString("category")]); m_category_isValid = ::OpenAPI::fromJsonValue(category, json[QString("category")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
::OpenAPI::fromJsonValue(photo_urls, json[QString("photoUrls")]); m_photo_urls_isValid = ::OpenAPI::fromJsonValue(photo_urls, json[QString("photoUrls")]);
::OpenAPI::fromJsonValue(tags, json[QString("tags")]); m_tags_isValid = ::OpenAPI::fromJsonValue(tags, json[QString("tags")]);
::OpenAPI::fromJsonValue(status, json[QString("status")]); m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
} }
@ -162,7 +169,6 @@ OAIPet::setStatus(const QString &status) {
this->m_status_isSet = true; this->m_status_isSet = true;
} }
bool bool
OAIPet::isSet() const { OAIPet::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -182,5 +188,11 @@ OAIPet::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIPet::isValid() const {
// only required properties are required for the object to be considered valid
return m_name_isValid && m_photo_urls_isValid && true;
}
} }

View File

@ -62,26 +62,27 @@ public:
void setStatus(const QString &status); void setStatus(const QString &status);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
OAICategory category; OAICategory category;
bool m_category_isSet; bool m_category_isSet;
bool m_category_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
QList<QString> photo_urls; QList<QString> photo_urls;
bool m_photo_urls_isSet; bool m_photo_urls_isSet;
bool m_photo_urls_isValid;
QList<OAITag> tags; QList<OAITag> tags;
bool m_tags_isSet; bool m_tags_isSet;
bool m_tags_isValid;
QString status; QString status;
bool m_status_isSet; bool m_status_isSet;
bool m_status_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAITag::OAITag(QString json) { OAITag::OAITag(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,7 +38,9 @@ OAITag::~OAITag() {
void void
OAITag::init() { OAITag::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_name_isSet = false; m_name_isSet = false;
m_name_isValid = false;
} }
void void
@ -50,9 +53,9 @@ OAITag::fromJson(QString jsonString) {
void void
OAITag::fromJsonObject(QJsonObject json) { OAITag::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(name, json[QString("name")]); m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
} }
@ -96,7 +99,6 @@ OAITag::setName(const QString &name) {
this->m_name_isSet = true; this->m_name_isSet = true;
} }
bool bool
OAITag::isSet() const { OAITag::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -108,5 +110,11 @@ OAITag::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAITag::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -47,14 +47,15 @@ public:
void setName(const QString &name); void setName(const QString &name);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString name; QString name;
bool m_name_isSet; bool m_name_isSet;
bool m_name_isValid;
}; };
} }

View File

@ -23,6 +23,7 @@
namespace OpenAPI { namespace OpenAPI {
OAIUser::OAIUser(QString json) { OAIUser::OAIUser(QString json) {
this->init();
this->fromJson(json); this->fromJson(json);
} }
@ -37,13 +38,21 @@ OAIUser::~OAIUser() {
void void
OAIUser::init() { OAIUser::init() {
m_id_isSet = false; m_id_isSet = false;
m_id_isValid = false;
m_username_isSet = false; m_username_isSet = false;
m_username_isValid = false;
m_first_name_isSet = false; m_first_name_isSet = false;
m_first_name_isValid = false;
m_last_name_isSet = false; m_last_name_isSet = false;
m_last_name_isValid = false;
m_email_isSet = false; m_email_isSet = false;
m_email_isValid = false;
m_password_isSet = false; m_password_isSet = false;
m_password_isValid = false;
m_phone_isSet = false; m_phone_isSet = false;
m_phone_isValid = false;
m_user_status_isSet = false; m_user_status_isSet = false;
m_user_status_isValid = false;
} }
void void
@ -56,21 +65,21 @@ OAIUser::fromJson(QString jsonString) {
void void
OAIUser::fromJsonObject(QJsonObject json) { OAIUser::fromJsonObject(QJsonObject json) {
::OpenAPI::fromJsonValue(id, json[QString("id")]); m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
::OpenAPI::fromJsonValue(username, json[QString("username")]); m_username_isValid = ::OpenAPI::fromJsonValue(username, json[QString("username")]);
::OpenAPI::fromJsonValue(first_name, json[QString("firstName")]); m_first_name_isValid = ::OpenAPI::fromJsonValue(first_name, json[QString("firstName")]);
::OpenAPI::fromJsonValue(last_name, json[QString("lastName")]); m_last_name_isValid = ::OpenAPI::fromJsonValue(last_name, json[QString("lastName")]);
::OpenAPI::fromJsonValue(email, json[QString("email")]); m_email_isValid = ::OpenAPI::fromJsonValue(email, json[QString("email")]);
::OpenAPI::fromJsonValue(password, json[QString("password")]); m_password_isValid = ::OpenAPI::fromJsonValue(password, json[QString("password")]);
::OpenAPI::fromJsonValue(phone, json[QString("phone")]); m_phone_isValid = ::OpenAPI::fromJsonValue(phone, json[QString("phone")]);
::OpenAPI::fromJsonValue(user_status, json[QString("userStatus")]); m_user_status_isValid = ::OpenAPI::fromJsonValue(user_status, json[QString("userStatus")]);
} }
@ -192,7 +201,6 @@ OAIUser::setUserStatus(const qint32 &user_status) {
this->m_user_status_isSet = true; this->m_user_status_isSet = true;
} }
bool bool
OAIUser::isSet() const { OAIUser::isSet() const {
bool isObjectUpdated = false; bool isObjectUpdated = false;
@ -216,5 +224,11 @@ OAIUser::isSet() const {
return isObjectUpdated; return isObjectUpdated;
} }
bool
OAIUser::isValid() const {
// only required properties are required for the object to be considered valid
return true;
}
} }

View File

@ -65,32 +65,33 @@ public:
void setUserStatus(const qint32 &user_status); void setUserStatus(const qint32 &user_status);
virtual bool isSet() const override; virtual bool isSet() const override;
virtual bool isValid() const override;
private: private:
qint64 id; qint64 id;
bool m_id_isSet; bool m_id_isSet;
bool m_id_isValid;
QString username; QString username;
bool m_username_isSet; bool m_username_isSet;
bool m_username_isValid;
QString first_name; QString first_name;
bool m_first_name_isSet; bool m_first_name_isSet;
bool m_first_name_isValid;
QString last_name; QString last_name;
bool m_last_name_isSet; bool m_last_name_isSet;
bool m_last_name_isValid;
QString email; QString email;
bool m_email_isSet; bool m_email_isSet;
bool m_email_isValid;
QString password; QString password;
bool m_password_isSet; bool m_password_isSet;
bool m_password_isValid;
QString phone; QString phone;
bool m_phone_isSet; bool m_phone_isSet;
bool m_phone_isValid;
qint32 user_status; qint32 user_status;
bool m_user_status_isSet; bool m_user_status_isSet;
bool m_user_status_isValid;
}; };
} }

View File

@ -333,13 +333,19 @@ void OAIPetApiRequest::uploadFileError(const OAIApiResponse& res, QNetworkReply:
void OAIPetApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){ void OAIPetApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res);
if(socket->isOpen()){
socket->close();
}
} }
void OAIPetApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){ void OAIPetApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res->readAll());
if(socket->isOpen()){
socket->close();
}
} }
} }

View File

@ -186,13 +186,19 @@ void OAIStoreApiRequest::placeOrderError(const OAIOrder& res, QNetworkReply::Net
void OAIStoreApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){ void OAIStoreApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res);
if(socket->isOpen()){
socket->close();
}
} }
void OAIStoreApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){ void OAIStoreApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res->readAll());
if(socket->isOpen()){
socket->close();
}
} }
} }

View File

@ -338,13 +338,19 @@ void OAIUserApiRequest::updateUserError(QNetworkReply::NetworkError error_type,
void OAIUserApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){ void OAIUserApiRequest::sendCustomResponse(QByteArray & res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res);
if(socket->isOpen()){
socket->close();
}
} }
void OAIUserApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){ void OAIUserApiRequest::sendCustomResponse(QIODevice *res, QNetworkReply::NetworkError error_type){
Q_UNUSED(res); // TODO
Q_UNUSED(error_type); // TODO Q_UNUSED(error_type); // TODO
socket->write(res->readAll());
if(socket->isOpen()){
socket->close();
}
} }
} }