forked from loafle/openapi-generator-original
[C++] [Qt5] Add enum support for client and server (#2339)
* Add enum support to Qt5 client and server * Correct model name prefix * Remove tabs * Correct wrong filename when prefix used
This commit is contained in:
parent
0bc06f8d4d
commit
3bb4edf865
@ -5,6 +5,7 @@ import io.swagger.v3.oas.models.media.Schema;
|
||||
import io.swagger.v3.parser.util.SchemaTypeUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.openapitools.codegen.CodegenConfig;
|
||||
import org.openapitools.codegen.CodegenModel;
|
||||
import org.openapitools.codegen.CodegenOperation;
|
||||
import org.openapitools.codegen.CodegenParameter;
|
||||
import org.openapitools.codegen.utils.ModelUtils;
|
||||
@ -280,7 +281,19 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
List<CodegenOperation> operations = (List<CodegenOperation>) objectMap.get("operation");
|
||||
|
||||
List<Map<String, String>> imports = (List<Map<String, String>>) objs.get("imports");
|
||||
Map<String, CodegenModel> codegenModels = new HashMap<String, CodegenModel> ();
|
||||
for(Object moObj : allModels) {
|
||||
CodegenModel mo = ((Map<String, CodegenModel>) moObj).get("model");
|
||||
if(mo.isEnum) {
|
||||
codegenModels.put(mo.classname, mo);
|
||||
}
|
||||
}
|
||||
for (CodegenOperation operation : operations) {
|
||||
if(operation.returnType != null) {
|
||||
if(codegenModels.containsKey(operation.returnType)){
|
||||
operation.vendorExtensions.put("returnsEnum", true);
|
||||
}
|
||||
}
|
||||
// Check all return parameter baseType if there is a necessity to include, include it if not
|
||||
// already done
|
||||
if (operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||
@ -316,6 +329,21 @@ public class CppQt5AbstractCodegen extends AbstractCppCodegen implements Codegen
|
||||
return objs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||
return postProcessModelsEnum(objs);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toEnumValue(String value, String datatype) {
|
||||
return escapeText(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDataTypeString(String dataType) {
|
||||
return "QString".equals(dataType);
|
||||
}
|
||||
|
||||
private Map<String, String> createMapping(String key, String value) {
|
||||
Map<String, String> customImport = new HashMap<String, String>();
|
||||
customImport.put(key, toModelImport(value));
|
||||
|
@ -75,6 +75,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, PREFIX + "HttpRequest.h"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, PREFIX + "HttpRequest.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, PREFIX + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, PREFIX + "Enum.h"));
|
||||
if (optionalProjectFileFlag) {
|
||||
supportingFiles.add(new SupportingFile("Project.mustache", sourceFolder, "client.pri"));
|
||||
}
|
||||
@ -100,6 +101,7 @@ public class CppQt5ClientCodegen extends CppQt5AbstractCodegen implements Codege
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.h.mustache", sourceFolder, modelNamePrefix + "HttpRequest.h"));
|
||||
supportingFiles.add(new SupportingFile("HttpRequest.cpp.mustache", sourceFolder, modelNamePrefix + "HttpRequest.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder, modelNamePrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder, modelNamePrefix + "Enum.h"));
|
||||
|
||||
typeMapping.put("file", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
typeMapping.put("binary", modelNamePrefix + "HttpRequestInputFileElement");
|
||||
|
@ -83,6 +83,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, PREFIX + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, PREFIX + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, PREFIX + "Enum.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, PREFIX + "ApiRouter.cpp"));
|
||||
|
||||
@ -106,6 +107,7 @@ public class CppQt5QHttpEngineServerCodegen extends CppQt5AbstractCodegen implem
|
||||
supportingFiles.add(new SupportingFile("helpers-header.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.h"));
|
||||
supportingFiles.add(new SupportingFile("helpers-body.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Helpers.cpp"));
|
||||
supportingFiles.add(new SupportingFile("object.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Object.h"));
|
||||
supportingFiles.add(new SupportingFile("enum.mustache", sourceFolder + MODEL_DIR, modelNamePrefix + "Enum.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.h.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.h"));
|
||||
supportingFiles.add(new SupportingFile("apirouter.cpp.mustache", sourceFolder + APIHANDLER_DIR, modelNamePrefix + "ApiRouter.cpp"));
|
||||
|
||||
|
@ -19,6 +19,7 @@ HEADERS += \
|
||||
$${PWD}/{{prefix}}Helpers.h \
|
||||
$${PWD}/{{prefix}}HttpRequest.h \
|
||||
$${PWD}/{{prefix}}Object.h
|
||||
$${PWD}/{{prefix}}Enum.h
|
||||
|
||||
SOURCES += \
|
||||
# Models
|
||||
|
57
modules/openapi-generator/src/main/resources/cpp-qt5-client/enum.mustache
vendored
Normal file
57
modules/openapi-generator/src/main/resources/cpp-qt5-client/enum.mustache
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{{>licenseInfo}}
|
||||
#ifndef {{prefix}}_ENUM_H
|
||||
#define {{prefix}}_ENUM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonValue>
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
class {{prefix}}Enum {
|
||||
public:
|
||||
{{prefix}}Enum() {
|
||||
|
||||
}
|
||||
|
||||
{{prefix}}Enum(QString jsonString) {
|
||||
fromJson(jsonString);
|
||||
}
|
||||
|
||||
virtual ~{{prefix}}Enum(){
|
||||
|
||||
}
|
||||
|
||||
virtual QJsonValue asJsonValue() const {
|
||||
return QJsonValue(jstr);
|
||||
}
|
||||
|
||||
virtual QString asJson() const {
|
||||
return jstr;
|
||||
}
|
||||
|
||||
virtual void fromJson(QString jsonString) {
|
||||
jstr = jsonString;
|
||||
}
|
||||
|
||||
virtual void fromJsonValue(QJsonValue jval) {
|
||||
jstr = jval.toString();
|
||||
}
|
||||
|
||||
virtual bool isSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool isValid() const {
|
||||
return true;
|
||||
}
|
||||
private :
|
||||
QString jstr;
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
#endif // {{prefix}}_ENUM_H
|
@ -1,7 +1,7 @@
|
||||
{{>licenseInfo}}
|
||||
#include <QDebug>
|
||||
#include "{{prefix}}Helpers.h"
|
||||
#include "{{prefix}}Object.h"
|
||||
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -55,6 +55,11 @@ toStringValue(const double &value){
|
||||
return QString::number(value);
|
||||
}
|
||||
|
||||
QString
|
||||
toStringValue(const {{prefix}}Enum &value){
|
||||
return value.asJson();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const QString &value){
|
||||
return QJsonValue(value);
|
||||
@ -105,6 +110,11 @@ toJsonValue(const {{prefix}}Object &value){
|
||||
return value.asJsonObject();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const {{prefix}}Enum &value){
|
||||
return value.asJsonValue();
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, QString &value){
|
||||
value.clear();
|
||||
@ -193,6 +203,12 @@ fromStringValue(const QString &inStr, double &value){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, {{prefix}}Enum &value){
|
||||
value.fromJson(inStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||
bool ok = true;
|
||||
@ -315,6 +331,12 @@ fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval){
|
||||
value.fromJsonValue(jval);
|
||||
return true;
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <QDate>
|
||||
#include <QVariant>
|
||||
#include "{{prefix}}Object.h"
|
||||
#include "{{prefix}}Enum.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -26,6 +27,7 @@ namespace {{this}} {
|
||||
QString toStringValue(const bool &value);
|
||||
QString toStringValue(const float &value);
|
||||
QString toStringValue(const double &value);
|
||||
QString toStringValue(const {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
QString toStringValue(const QList<T> &val) {
|
||||
@ -49,6 +51,7 @@ namespace {{this}} {
|
||||
QJsonValue toJsonValue(const float &value);
|
||||
QJsonValue toJsonValue(const double &value);
|
||||
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
||||
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
QJsonValue toJsonValue(const QList<T> &val) {
|
||||
@ -77,6 +80,7 @@ namespace {{this}} {
|
||||
bool fromStringValue(const QString &inStr, bool &value);
|
||||
bool fromStringValue(const QString &inStr, float &value);
|
||||
bool fromStringValue(const QString &inStr, double &value);
|
||||
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||
@ -110,6 +114,7 @@ namespace {{this}} {
|
||||
bool fromJsonValue(float &value, const QJsonValue &jval);
|
||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
||||
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
||||
|
||||
template <typename T>
|
||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||
|
@ -28,23 +28,31 @@ namespace {{this}} {
|
||||
|
||||
void
|
||||
{{classname}}::init() {
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
m_{{name}}_isSet = false;
|
||||
m_{{name}}_isValid = false;
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
m_value_isSet = false;
|
||||
m_value_isValid = false;
|
||||
m_value = e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;
|
||||
{{/isEnum}}
|
||||
}
|
||||
|
||||
void
|
||||
{{classname}}::fromJson(QString jsonString) {
|
||||
QByteArray array (jsonString.toStdString().c_str());
|
||||
{{^isEnum}}QByteArray array (jsonString.toStdString().c_str());
|
||||
QJsonDocument doc = QJsonDocument::fromJson(array);
|
||||
QJsonObject jsonObject = doc.object();
|
||||
this->fromJsonObject(jsonObject);
|
||||
this->fromJsonObject(jsonObject);{{/isEnum}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}
|
||||
{{#-first}}if{{/-first}}{{^-first}}else if{{/-first}} ( jsonString.compare({{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}}, Qt::CaseInsensitive) == 0) {
|
||||
m_value = e{{classname}}::{{name}};
|
||||
m_value_isValid = true;
|
||||
}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
void
|
||||
{{classname}}::fromJsonObject(QJsonObject json) {
|
||||
{{#vars}}
|
||||
{{classname}}::fromJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}(QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} json) {
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{^isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}}
|
||||
{{#isContainer}}{{^items.isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
|
||||
if(json["{{baseName}}"].isArray()){
|
||||
@ -68,33 +76,45 @@ void
|
||||
}
|
||||
}
|
||||
}{{/isMapContainer}}{{/items.isContainer}}{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
{{#allowableValues}}{{#enumVars}}{{#-first}}{{#isString}}fromJson(json.toString());{{/isString}}{{^isString}}m_value = static_cast<e{{classname}}>(json.toInt());{{/isString}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
QString
|
||||
{{classname}}::asJson () const {
|
||||
QJsonObject obj = this->asJsonObject();
|
||||
{{^isEnum}}QJsonObject obj = this->asJsonObject();
|
||||
QJsonDocument doc(obj);
|
||||
QByteArray bytes = doc.toJson();
|
||||
return QString(bytes);
|
||||
return QString(bytes);{{/isEnum}}{{#isEnum}}
|
||||
QString val;
|
||||
{{#allowableValues}}
|
||||
switch (m_value){
|
||||
{{#enumVars}}
|
||||
case e{{classname}}::{{name}}:
|
||||
val = {{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}};
|
||||
break;{{#-last}}
|
||||
default:
|
||||
break;{{/-last}}
|
||||
{{/enumVars}}
|
||||
}{{/allowableValues}}
|
||||
return val;{{/isEnum}}
|
||||
}
|
||||
|
||||
QJsonObject
|
||||
{{classname}}::asJsonObject() const {
|
||||
QJsonObject obj;
|
||||
{{#vars}}
|
||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
||||
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
||||
{{^isEnum}}QJsonObject obj;{{#vars}}
|
||||
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
||||
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
||||
}{{/isContainer}}{{#isContainer}}
|
||||
if({{name}}.size() > 0){
|
||||
{{^items.isContainer}}obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));{{/items.isContainer}}{{#items.isContainer}}
|
||||
obj.insert(QString("{{baseName}}"), toJsonValue({{name}}));{{/items.isContainer}}
|
||||
} {{/isContainer}}
|
||||
{{/vars}}
|
||||
return obj;
|
||||
} {{/isContainer}}{{/vars}}
|
||||
return obj;{{/isEnum}}{{#isEnum}}
|
||||
{{#allowableValues}}{{#enumVars}}{{#-first}}{{^isString}}return QJsonValue(static_cast<int>(m_value));{{/isString}}{{#isString}}return QJsonValue(asJson());{{/isString}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}}
|
||||
{{classname}}::{{getter}}() const {
|
||||
return {{name}};
|
||||
@ -105,20 +125,30 @@ void
|
||||
this->m_{{name}}_isSet = true;
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
{{classname}}::e{{classname}} {{classname}}::getValue() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void {{classname}}::setValue(const {{classname}}::e{{classname}}& value){
|
||||
m_value = value;
|
||||
m_value_isSet = true;
|
||||
}
|
||||
{{/isEnum}}
|
||||
bool
|
||||
{{classname}}::isSet() const {
|
||||
bool isObjectUpdated = false;
|
||||
{{^isEnum}}bool isObjectUpdated = false;
|
||||
do{ {{#vars}}
|
||||
{{#isContainer}}if({{name}}.size() > 0){{/isContainer}}{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{{/isContainer}}{ isObjectUpdated = true; break;}
|
||||
{{/vars}}}while(false);
|
||||
return isObjectUpdated;
|
||||
return isObjectUpdated;{{/isEnum}}{{#isEnum}}
|
||||
return m_value_isSet;{{/isEnum}}
|
||||
}
|
||||
|
||||
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;
|
||||
return {{^isEnum}}{{#vars}}{{#required}}m_{{name}}_isValid && {{/required}}{{/vars}}true{{/isEnum}}{{#isEnum}}m_value_isValid{{/isEnum}};
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
@ -15,6 +15,7 @@
|
||||
{{/imports}}
|
||||
|
||||
#include "{{prefix}}Object.h"
|
||||
#include "{{prefix}}Enum.h"
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
@ -22,32 +23,51 @@
|
||||
namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
class {{classname}}: public {{prefix}}Object {
|
||||
class {{classname}}: public {{prefix}}{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Enum{{/isEnum}} {
|
||||
public:
|
||||
{{classname}}();
|
||||
{{classname}}(QString json);
|
||||
~{{classname}}() override;
|
||||
|
||||
QString asJson () const override;
|
||||
QJsonObject asJsonObject() const override;
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const override;
|
||||
void fromJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}(QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}} {{getter}}() const;
|
||||
void {{setter}}(const {{{dataType}}} &{{name}});
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}{{#allowableValues}}
|
||||
enum class e{{classname}} {{#enumVars}}{{#-first}}{{^isString}}: int {{/isString}}{{/-first}}{{/enumVars}}{
|
||||
INVALID_VALUE_OPENAPI_GENERATED = 0,
|
||||
{{#enumVars}}
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{enumDescription}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
{{{name}}}{{^-last}}, {{/-last}}
|
||||
{{/enumVars}}
|
||||
};{{/allowableValues}}
|
||||
|
||||
{{classname}}::e{{classname}} getValue() const;
|
||||
void setValue(const {{classname}}::e{{classname}}& value);{{/isEnum}}
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}} {{name}};
|
||||
bool m_{{name}}_isSet;
|
||||
bool m_{{name}}_isValid;
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}
|
||||
{{#isEnum}}e{{classname}} m_value;
|
||||
bool m_value_isSet;
|
||||
bool m_value_isValid;
|
||||
{{/isEnum}}
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
@ -116,9 +116,10 @@ void {{classname}}Request::{{nickname}}Request({{#hasPathParams}}{{#pathParams}}
|
||||
{{#operations}}{{#operation}}void {{classname}}Request::{{nickname}}Response({{#returnType}}const {{{returnType}}}& res{{/returnType}}){
|
||||
writeResponseHeaders();{{#returnType}}{{#isMapContainer}}
|
||||
QJsonDocument resDoc(::{{cppNamespace}}::toJsonValue(res).toObject());
|
||||
socket->writeJson(resDoc);{{/isMapContainer}}{{^isMapContainer}}{{^returnTypeIsPrimitive}}
|
||||
socket->writeJson(resDoc);{{/isMapContainer}}{{^isMapContainer}}{{^returnTypeIsPrimitive}}{{^vendorExtensions.returnsEnum}}
|
||||
QJsonDocument resDoc(::{{cppNamespace}}::toJsonValue(res).to{{^isListContainer}}Object{{/isListContainer}}{{#isListContainer}}Array{{/isListContainer}}());
|
||||
socket->writeJson(resDoc);{{/returnTypeIsPrimitive}}{{#returnTypeIsPrimitive}}
|
||||
socket->writeJson(resDoc);{{/vendorExtensions.returnsEnum}}{{#vendorExtensions.returnsEnum}}
|
||||
socket->write(::{{cppNamespace}}::toStringValue(res).toUtf8());{{/vendorExtensions.returnsEnum}}{{/returnTypeIsPrimitive}}{{#returnTypeIsPrimitive}}
|
||||
socket->write({{#isListContainer}}QString("["+{{/isListContainer}}::{{cppNamespace}}::toStringValue(res){{#isListContainer}}+"]"){{/isListContainer}}.toUtf8());{{/returnTypeIsPrimitive}}{{/isMapContainer}}{{/returnType}}{{^returnType}}
|
||||
socket->setStatusCode(QHttpEngine::Socket::OK);{{/returnType}}
|
||||
if(socket->isOpen()){
|
||||
@ -132,9 +133,10 @@ void {{classname}}Request::{{nickname}}Request({{#hasPathParams}}{{#pathParams}}
|
||||
writeResponseHeaders();{{#returnType}}
|
||||
Q_UNUSED(error_str); // response will be used instead of error string{{#isMapContainer}}
|
||||
QJsonDocument resDoc(::{{cppNamespace}}::toJsonValue(res).toObject());
|
||||
socket->writeJson(resDoc);{{/isMapContainer}}{{^isMapContainer}}{{^returnTypeIsPrimitive}}
|
||||
socket->writeJson(resDoc);{{/isMapContainer}}{{^isMapContainer}}{{^returnTypeIsPrimitive}}{{^vendorExtensions.returnsEnum}}
|
||||
QJsonDocument resDoc(::{{cppNamespace}}::toJsonValue(res).to{{^isListContainer}}Object{{/isListContainer}}{{#isListContainer}}Array{{/isListContainer}}());
|
||||
socket->writeJson(resDoc);{{/returnTypeIsPrimitive}}{{#returnTypeIsPrimitive}}
|
||||
socket->writeJson(resDoc);{{/vendorExtensions.returnsEnum}}{{#vendorExtensions.returnsEnum}}
|
||||
socket->write(::{{cppNamespace}}::toStringValue(res).toUtf8());{{/vendorExtensions.returnsEnum}}{{/returnTypeIsPrimitive}}{{#returnTypeIsPrimitive}}
|
||||
socket->write({{#isListContainer}}QString("["+{{/isListContainer}}::{{cppNamespace}}::toStringValue(res){{#isListContainer}}+"]"){{/isListContainer}}.toUtf8());{{/returnTypeIsPrimitive}}{{/isMapContainer}}{{/returnType}}{{^returnType}}
|
||||
socket->setStatusCode(QHttpEngine::Socket::NotFound);
|
||||
socket->write(error_str.toUtf8());{{/returnType}}
|
||||
|
57
modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/enum.mustache
vendored
Normal file
57
modules/openapi-generator/src/main/resources/cpp-qt5-qhttpengine-server/enum.mustache
vendored
Normal file
@ -0,0 +1,57 @@
|
||||
{{>licenseInfo}}
|
||||
#ifndef {{prefix}}_ENUM_H
|
||||
#define {{prefix}}_ENUM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonValue>
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
class {{prefix}}Enum {
|
||||
public:
|
||||
{{prefix}}Enum() {
|
||||
|
||||
}
|
||||
|
||||
{{prefix}}Enum(QString jsonString) {
|
||||
fromJson(jsonString);
|
||||
}
|
||||
|
||||
virtual ~{{prefix}}Enum(){
|
||||
|
||||
}
|
||||
|
||||
virtual QJsonValue asJsonValue() const {
|
||||
return QJsonValue(jstr);
|
||||
}
|
||||
|
||||
virtual QString asJson() const {
|
||||
return jstr;
|
||||
}
|
||||
|
||||
virtual void fromJson(QString jsonString) {
|
||||
jstr = jsonString;
|
||||
}
|
||||
|
||||
virtual void fromJsonValue(QJsonValue jval) {
|
||||
jstr = jval.toString();
|
||||
}
|
||||
|
||||
virtual bool isSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool isValid() const {
|
||||
return true;
|
||||
}
|
||||
private :
|
||||
QString jstr;
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
#endif // {{prefix}}_ENUM_H
|
@ -1,7 +1,7 @@
|
||||
{{>licenseInfo}}
|
||||
#include <QDebug>
|
||||
#include "{{prefix}}Helpers.h"
|
||||
#include "{{prefix}}Object.h"
|
||||
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -55,6 +55,11 @@ toStringValue(const double &value){
|
||||
return QString::number(value);
|
||||
}
|
||||
|
||||
QString
|
||||
toStringValue(const {{prefix}}Enum &value){
|
||||
return value.asJson();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const QString &value){
|
||||
return QJsonValue(value);
|
||||
@ -105,6 +110,11 @@ toJsonValue(const {{prefix}}Object &value){
|
||||
return value.asJsonObject();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const {{prefix}}Enum &value){
|
||||
return value.asJsonValue();
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, QString &value){
|
||||
value.clear();
|
||||
@ -193,6 +203,12 @@ fromStringValue(const QString &inStr, double &value){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, {{prefix}}Enum &value){
|
||||
value.fromJson(inStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||
bool ok = true;
|
||||
@ -315,6 +331,12 @@ fromJsonValue({{prefix}}Object &value, const QJsonValue &jval){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval){
|
||||
value.fromJsonValue(jval);
|
||||
return true;
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
}
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <QDate>
|
||||
#include <QVariant>
|
||||
#include "{{prefix}}Object.h"
|
||||
#include "{{prefix}}Enum.h"
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
namespace {{this}} {
|
||||
@ -26,6 +27,7 @@ namespace {{this}} {
|
||||
QString toStringValue(const bool &value);
|
||||
QString toStringValue(const float &value);
|
||||
QString toStringValue(const double &value);
|
||||
QString toStringValue(const {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
QString toStringValue(const QList<T> &val) {
|
||||
@ -49,6 +51,7 @@ namespace {{this}} {
|
||||
QJsonValue toJsonValue(const float &value);
|
||||
QJsonValue toJsonValue(const double &value);
|
||||
QJsonValue toJsonValue(const {{prefix}}Object &value);
|
||||
QJsonValue toJsonValue(const {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
QJsonValue toJsonValue(const QList<T> &val) {
|
||||
@ -77,6 +80,7 @@ namespace {{this}} {
|
||||
bool fromStringValue(const QString &inStr, bool &value);
|
||||
bool fromStringValue(const QString &inStr, float &value);
|
||||
bool fromStringValue(const QString &inStr, double &value);
|
||||
bool fromStringValue(const QString &inStr, {{prefix}}Enum &value);
|
||||
|
||||
template <typename T>
|
||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||
@ -110,6 +114,7 @@ namespace {{this}} {
|
||||
bool fromJsonValue(float &value, const QJsonValue &jval);
|
||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||
bool fromJsonValue({{prefix}}Object &value, const QJsonValue &jval);
|
||||
bool fromJsonValue({{prefix}}Enum &value, const QJsonValue &jval);
|
||||
|
||||
template <typename T>
|
||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||
|
@ -28,23 +28,31 @@ namespace {{this}} {
|
||||
|
||||
void
|
||||
{{classname}}::init() {
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
m_{{name}}_isSet = false;
|
||||
m_{{name}}_isValid = false;
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
m_value_isSet = false;
|
||||
m_value_isValid = false;
|
||||
m_value = e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;
|
||||
{{/isEnum}}
|
||||
}
|
||||
|
||||
void
|
||||
{{classname}}::fromJson(QString jsonString) {
|
||||
QByteArray array (jsonString.toStdString().c_str());
|
||||
{{^isEnum}}QByteArray array (jsonString.toStdString().c_str());
|
||||
QJsonDocument doc = QJsonDocument::fromJson(array);
|
||||
QJsonObject jsonObject = doc.object();
|
||||
this->fromJsonObject(jsonObject);
|
||||
this->fromJsonObject(jsonObject);{{/isEnum}}{{#isEnum}}{{#allowableValues}}{{#enumVars}}
|
||||
{{#-first}}if{{/-first}}{{^-first}}else if{{/-first}} ( jsonString.compare({{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}}, Qt::CaseInsensitive) == 0) {
|
||||
m_value = e{{classname}}::{{name}};
|
||||
m_value_isValid = true;
|
||||
}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
void
|
||||
{{classname}}::fromJsonObject(QJsonObject json) {
|
||||
{{#vars}}
|
||||
{{classname}}::fromJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}(QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} json) {
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{^isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/isContainer}}
|
||||
{{#isContainer}}{{^items.isContainer}}m_{{name}}_isValid = ::{{cppNamespace}}::fromJsonValue({{name}}, json[QString("{{baseName}}")]);{{/items.isContainer}}{{#items.isContainer}}{{#isListContainer}}
|
||||
if(json["{{baseName}}"].isArray()){
|
||||
@ -68,33 +76,45 @@ void
|
||||
}
|
||||
}
|
||||
}{{/isMapContainer}}{{/items.isContainer}}{{/isContainer}}
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
{{#allowableValues}}{{#enumVars}}{{#-first}}{{#isString}}fromJson(json.toString());{{/isString}}{{^isString}}m_value = static_cast<e{{classname}}>(json.toInt());{{/isString}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
QString
|
||||
{{classname}}::asJson () const {
|
||||
QJsonObject obj = this->asJsonObject();
|
||||
{{^isEnum}}QJsonObject obj = this->asJsonObject();
|
||||
QJsonDocument doc(obj);
|
||||
QByteArray bytes = doc.toJson();
|
||||
return QString(bytes);
|
||||
return QString(bytes);{{/isEnum}}{{#isEnum}}
|
||||
QString val;
|
||||
{{#allowableValues}}
|
||||
switch (m_value){
|
||||
{{#enumVars}}
|
||||
case e{{classname}}::{{name}}:
|
||||
val = {{#isString}}"{{value}}"{{/isString}}{{^isString}}QString::number({{value}}){{/isString}};
|
||||
break;{{#-last}}
|
||||
default:
|
||||
break;{{/-last}}
|
||||
{{/enumVars}}
|
||||
}{{/allowableValues}}
|
||||
return val;{{/isEnum}}
|
||||
}
|
||||
|
||||
QJsonObject
|
||||
{{classname}}::asJsonObject() const {
|
||||
QJsonObject obj;
|
||||
{{#vars}}
|
||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}
|
||||
{{classname}}::asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const {
|
||||
{{^isEnum}}QJsonObject obj;{{#vars}}
|
||||
{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{
|
||||
obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));
|
||||
}{{/isContainer}}{{#isContainer}}
|
||||
if({{name}}.size() > 0){
|
||||
{{^items.isContainer}}obj.insert(QString("{{baseName}}"), ::{{cppNamespace}}::toJsonValue({{name}}));{{/items.isContainer}}{{#items.isContainer}}
|
||||
obj.insert(QString("{{baseName}}"), toJsonValue({{name}}));{{/items.isContainer}}
|
||||
} {{/isContainer}}
|
||||
{{/vars}}
|
||||
return obj;
|
||||
} {{/isContainer}}{{/vars}}
|
||||
return obj;{{/isEnum}}{{#isEnum}}
|
||||
{{#allowableValues}}{{#enumVars}}{{#-first}}{{^isString}}return QJsonValue(static_cast<int>(m_value));{{/isString}}{{#isString}}return QJsonValue(asJson());{{/isString}}{{/-first}}{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
}
|
||||
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}}
|
||||
{{classname}}::{{getter}}() const {
|
||||
return {{name}};
|
||||
@ -105,20 +125,30 @@ void
|
||||
this->m_{{name}}_isSet = true;
|
||||
}
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}
|
||||
{{classname}}::e{{classname}} {{classname}}::getValue() const {
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void {{classname}}::setValue(const {{classname}}::e{{classname}}& value){
|
||||
m_value = value;
|
||||
m_value_isSet = true;
|
||||
}
|
||||
{{/isEnum}}
|
||||
bool
|
||||
{{classname}}::isSet() const {
|
||||
bool isObjectUpdated = false;
|
||||
{{^isEnum}}bool isObjectUpdated = false;
|
||||
do{ {{#vars}}
|
||||
{{#isContainer}}if({{name}}.size() > 0){{/isContainer}}{{^isContainer}}{{#complexType}}if({{name}}.isSet()){{/complexType}}{{^complexType}}if(m_{{name}}_isSet){{/complexType}}{{/isContainer}}{ isObjectUpdated = true; break;}
|
||||
{{/vars}}}while(false);
|
||||
return isObjectUpdated;
|
||||
return isObjectUpdated;{{/isEnum}}{{#isEnum}}
|
||||
return m_value_isSet;{{/isEnum}}
|
||||
}
|
||||
|
||||
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;
|
||||
return {{^isEnum}}{{#vars}}{{#required}}m_{{name}}_isValid && {{/required}}{{/vars}}true{{/isEnum}}{{#isEnum}}m_value_isValid{{/isEnum}};
|
||||
}
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
@ -15,6 +15,7 @@
|
||||
{{/imports}}
|
||||
|
||||
#include "{{prefix}}Object.h"
|
||||
#include "{{prefix}}Enum.h"
|
||||
|
||||
{{#models}}
|
||||
{{#model}}
|
||||
@ -22,32 +23,51 @@
|
||||
namespace {{this}} {
|
||||
{{/cppNamespaceDeclarations}}
|
||||
|
||||
class {{classname}}: public {{prefix}}Object {
|
||||
class {{classname}}: public {{prefix}}{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Enum{{/isEnum}} {
|
||||
public:
|
||||
{{classname}}();
|
||||
{{classname}}(QString json);
|
||||
~{{classname}}() override;
|
||||
|
||||
QString asJson () const override;
|
||||
QJsonObject asJsonObject() const override;
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} asJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}() const override;
|
||||
void fromJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}}(QJson{{^isEnum}}Object{{/isEnum}}{{#isEnum}}Value{{/isEnum}} json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}} {{getter}}() const;
|
||||
void {{setter}}(const {{{dataType}}} &{{name}});
|
||||
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}{{#isEnum}}{{#allowableValues}}
|
||||
enum class e{{classname}} {{#enumVars}}{{#-first}}{{^isString}}: int {{/isString}}{{/-first}}{{/enumVars}}{
|
||||
INVALID_VALUE_OPENAPI_GENERATED = 0,
|
||||
{{#enumVars}}
|
||||
{{#enumDescription}}
|
||||
/**
|
||||
* {{enumDescription}}
|
||||
*/
|
||||
{{/enumDescription}}
|
||||
{{{name}}}{{^-last}}, {{/-last}}
|
||||
{{/enumVars}}
|
||||
};{{/allowableValues}}
|
||||
|
||||
{{classname}}::e{{classname}} getValue() const;
|
||||
void setValue(const {{classname}}::e{{classname}}& value);{{/isEnum}}
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
{{#vars}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{{dataType}}} {{name}};
|
||||
bool m_{{name}}_isSet;
|
||||
bool m_{{name}}_isValid;
|
||||
{{/vars}}
|
||||
{{/vars}}{{/isEnum}}
|
||||
{{#isEnum}}e{{classname}} m_value;
|
||||
bool m_value_isSet;
|
||||
bool m_value_isValid;
|
||||
{{/isEnum}}
|
||||
};
|
||||
|
||||
{{#cppNamespaceDeclarations}}
|
||||
|
@ -20,7 +20,9 @@ include(../client/client.pri)
|
||||
|
||||
SOURCES += main.cpp \
|
||||
PetApiTests.cpp \
|
||||
StoreApiTests.cpp
|
||||
StoreApiTests.cpp \
|
||||
UserApiTests.cpp
|
||||
|
||||
HEADERS += PetApiTests.h \
|
||||
StoreApiTests.h
|
||||
StoreApiTests.h \
|
||||
UserApiTests.h
|
||||
|
@ -8,7 +8,7 @@
|
||||
StoreApiTests::StoreApiTests () {}
|
||||
|
||||
StoreApiTests::~StoreApiTests () {
|
||||
exit(1);
|
||||
|
||||
}
|
||||
|
||||
OAIStoreApi* StoreApiTests::getApi() {
|
||||
|
@ -17,8 +17,6 @@ public:
|
||||
|
||||
private:
|
||||
OAIStoreApi* getApi();
|
||||
OAIOrder createRandomOrder();
|
||||
|
||||
signals:
|
||||
void quit();
|
||||
bool success();
|
||||
|
252
samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp
Normal file
252
samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp
Normal file
@ -0,0 +1,252 @@
|
||||
#include "UserApiTests.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QNetworkAccessManager>
|
||||
#include <QNetworkReply>
|
||||
#include <QDebug>
|
||||
#include <QRandomGenerator>
|
||||
UserApiTests::UserApiTests () {}
|
||||
|
||||
UserApiTests::~UserApiTests () {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
OAIUserApi* UserApiTests::getApi() {
|
||||
auto api = new OAIUserApi();
|
||||
api->host = "http://petstore.swagger.io";
|
||||
api->basePath = "/v2";
|
||||
return api;
|
||||
}
|
||||
|
||||
void UserApiTests::runTests() {
|
||||
UserApiTests* tests = new UserApiTests();
|
||||
QTest::qExec(tests);
|
||||
delete tests;
|
||||
}
|
||||
|
||||
OAIUser UserApiTests::createRandomUser() {
|
||||
OAIUser user;
|
||||
user.setId(QDateTime::currentMSecsSinceEpoch());
|
||||
user.setEmail(QString("Jane.Doe@openapitools.io"));
|
||||
user.setFirstName(QString("Jane"));
|
||||
user.setLastName(QString("Doe"));
|
||||
user.setPhone(QString("123456789"));
|
||||
user.setUsername(QString("janedoe"));
|
||||
user.setPassword(QString("secretPassword"));
|
||||
user.setUserStatus(static_cast<int>(QRandomGenerator::system()->generate()));
|
||||
return user;
|
||||
}
|
||||
|
||||
void UserApiTests::createUserTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(14000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::createUserSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
api->createUser(createRandomUser());
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::createUsersWithArrayInputTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(14000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::createUsersWithArrayInputSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
QList<OAIUser> users;
|
||||
users.append(createRandomUser());
|
||||
users.append(createRandomUser());
|
||||
users.append(createRandomUser());
|
||||
api->createUsersWithArrayInput(users);
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::createUsersWithListInputTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(14000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::createUsersWithListInputSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
QList<OAIUser> users;
|
||||
auto johndoe = createRandomUser();
|
||||
johndoe.setUsername(QString("johndoe"));
|
||||
auto rambo = createRandomUser();
|
||||
rambo.setUsername(QString("rambo"));
|
||||
users.append(johndoe);
|
||||
users.append(rambo);
|
||||
users.append(createRandomUser());
|
||||
api->createUsersWithListInput(users);
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::deleteUserTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(14000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::deleteUserSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
api->deleteUser(QString("rambo"));
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::getUserByNameTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(30000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this](OAIUser summary) {
|
||||
qDebug() << summary.getUsername();
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::getUserByNameSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
api->getUserByName(QString("johndoe"));
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::loginUserTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(30000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this](QString summary) {
|
||||
qDebug() << summary;
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::loginUserSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
api->loginUser(QString("johndoe"), QString("123456789"));
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::logoutUserTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(30000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::logoutUserSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
api->logoutUser();
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
||||
|
||||
void UserApiTests::updateUserTest(){
|
||||
auto api = getApi();
|
||||
QEventLoop loop;
|
||||
QTimer timer;
|
||||
timer.setInterval(30000);
|
||||
timer.setSingleShot(true);
|
||||
|
||||
auto validator = [this]() {
|
||||
emit quit();
|
||||
};
|
||||
auto finalizer = [&]() {
|
||||
loop.quit();
|
||||
};
|
||||
connect(this, &UserApiTests::quit, finalizer);
|
||||
connect(api, &OAIUserApi::updateUserSignal, this, validator);
|
||||
connect(&timer, &QTimer::timeout, &loop, finalizer);
|
||||
|
||||
auto johndoe = createRandomUser();
|
||||
johndoe.setUsername(QString("johndoe"));
|
||||
api->updateUser(QString("johndoe"), johndoe);
|
||||
timer.start();
|
||||
loop.exec();
|
||||
QVERIFY2(timer.isActive(), "didn't finish within timeout");
|
||||
disconnect(this, nullptr, nullptr, nullptr);
|
||||
delete api;
|
||||
}
|
37
samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h
Normal file
37
samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h
Normal file
@ -0,0 +1,37 @@
|
||||
#ifndef USERAPITESTS_H
|
||||
#define USERAPITESTS_H
|
||||
#include <QtTest/QtTest>
|
||||
#include <QTimer>
|
||||
|
||||
#include "../client/OAIUserApi.h"
|
||||
|
||||
using namespace OpenAPI;
|
||||
|
||||
class UserApiTests: public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
UserApiTests();
|
||||
virtual ~UserApiTests();
|
||||
|
||||
static void runTests();
|
||||
|
||||
private:
|
||||
OAIUserApi* getApi();
|
||||
OAIUser createRandomUser();
|
||||
|
||||
signals:
|
||||
void quit();
|
||||
bool success();
|
||||
|
||||
private slots:
|
||||
void createUserTest();
|
||||
void createUsersWithArrayInputTest();
|
||||
void createUsersWithListInputTest();
|
||||
void deleteUserTest();
|
||||
void getUserByNameTest();
|
||||
void loginUserTest();
|
||||
void logoutUserTest();
|
||||
void updateUserTest();
|
||||
};
|
||||
|
||||
#endif // USERAPITESTS_H
|
@ -1,10 +1,12 @@
|
||||
#include <QCoreApplication>
|
||||
#include "PetApiTests.h"
|
||||
#include "StoreApiTests.h"
|
||||
#include "UserApiTests.h"
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QCoreApplication a(argc, argv);
|
||||
PetApiTests::runTests();
|
||||
StoreApiTests::runTests();
|
||||
UserApiTests::runTests();
|
||||
return a.exec();
|
||||
}
|
||||
|
@ -37,13 +37,16 @@ OAIApiResponse::~OAIApiResponse() {
|
||||
|
||||
void
|
||||
OAIApiResponse::init() {
|
||||
|
||||
m_code_isSet = false;
|
||||
m_code_isValid = false;
|
||||
|
||||
m_type_isSet = false;
|
||||
m_type_isValid = false;
|
||||
|
||||
m_message_isSet = false;
|
||||
m_message_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAIApiResponse::fromJson(QString jsonString) {
|
||||
@ -55,12 +58,16 @@ OAIApiResponse::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAIApiResponse::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_code_isValid = ::OpenAPI::fromJsonValue(code, json[QString("code")]);
|
||||
|
||||
|
||||
m_type_isValid = ::OpenAPI::fromJsonValue(type, json[QString("type")]);
|
||||
|
||||
|
||||
m_message_isValid = ::OpenAPI::fromJsonValue(message, json[QString("message")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -86,6 +93,7 @@ OAIApiResponse::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint32
|
||||
OAIApiResponse::getCode() const {
|
||||
return code;
|
||||
@ -96,6 +104,7 @@ OAIApiResponse::setCode(const qint32 &code) {
|
||||
this->m_code_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIApiResponse::getType() const {
|
||||
return type;
|
||||
@ -106,6 +115,7 @@ OAIApiResponse::setType(const QString &type) {
|
||||
this->m_type_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIApiResponse::getMessage() const {
|
||||
return message;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -39,30 +40,39 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint32 getCode() const;
|
||||
void setCode(const qint32 &code);
|
||||
|
||||
|
||||
QString getType() const;
|
||||
void setType(const QString &type);
|
||||
|
||||
|
||||
QString getMessage() const;
|
||||
void setMessage(const QString &message);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint32 code;
|
||||
bool m_code_isSet;
|
||||
bool m_code_isValid;
|
||||
|
||||
QString type;
|
||||
bool m_type_isSet;
|
||||
bool m_type_isValid;
|
||||
|
||||
QString message;
|
||||
bool m_message_isSet;
|
||||
bool m_message_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,13 @@ OAICategory::~OAICategory() {
|
||||
|
||||
void
|
||||
OAICategory::init() {
|
||||
|
||||
m_id_isSet = false;
|
||||
m_id_isValid = false;
|
||||
|
||||
m_name_isSet = false;
|
||||
m_name_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAICategory::fromJson(QString jsonString) {
|
||||
@ -53,10 +55,13 @@ OAICategory::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAICategory::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
|
||||
|
||||
|
||||
m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -79,6 +84,7 @@ OAICategory::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAICategory::getId() const {
|
||||
return id;
|
||||
@ -89,6 +95,7 @@ OAICategory::setId(const qint64 &id) {
|
||||
this->m_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAICategory::getName() const {
|
||||
return name;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -39,24 +40,31 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint64 getId() const;
|
||||
void setId(const qint64 &id);
|
||||
|
||||
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint64 id;
|
||||
bool m_id_isSet;
|
||||
bool m_id_isValid;
|
||||
|
||||
QString name;
|
||||
bool m_name_isSet;
|
||||
bool m_name_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
64
samples/client/petstore/cpp-qt5/client/OAIEnum.h
Normal file
64
samples/client/petstore/cpp-qt5/client/OAIEnum.h
Normal file
@ -0,0 +1,64 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* OpenAPI spec version: 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.
|
||||
*/
|
||||
|
||||
#ifndef OAI_ENUM_H
|
||||
#define OAI_ENUM_H
|
||||
|
||||
#include <QString>
|
||||
#include <QJsonValue>
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
class OAIEnum {
|
||||
public:
|
||||
OAIEnum() {
|
||||
|
||||
}
|
||||
|
||||
OAIEnum(QString jsonString) {
|
||||
fromJson(jsonString);
|
||||
}
|
||||
|
||||
virtual ~OAIEnum(){
|
||||
|
||||
}
|
||||
|
||||
virtual QJsonValue asJsonValue() const {
|
||||
return QJsonValue(jstr);
|
||||
}
|
||||
|
||||
virtual QString asJson() const {
|
||||
return jstr;
|
||||
}
|
||||
|
||||
virtual void fromJson(QString jsonString) {
|
||||
jstr = jsonString;
|
||||
}
|
||||
|
||||
virtual void fromJsonValue(QJsonValue jval) {
|
||||
jstr = jval.toString();
|
||||
}
|
||||
|
||||
virtual bool isSet() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool isValid() const {
|
||||
return true;
|
||||
}
|
||||
private :
|
||||
QString jstr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // OAI_ENUM_H
|
@ -12,7 +12,7 @@
|
||||
|
||||
#include <QDebug>
|
||||
#include "OAIHelpers.h"
|
||||
#include "OAIObject.h"
|
||||
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -64,6 +64,11 @@ toStringValue(const double &value){
|
||||
return QString::number(value);
|
||||
}
|
||||
|
||||
QString
|
||||
toStringValue(const OAIEnum &value){
|
||||
return value.asJson();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const QString &value){
|
||||
return QJsonValue(value);
|
||||
@ -114,6 +119,11 @@ toJsonValue(const OAIObject &value){
|
||||
return value.asJsonObject();
|
||||
}
|
||||
|
||||
QJsonValue
|
||||
toJsonValue(const OAIEnum &value){
|
||||
return value.asJsonValue();
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, QString &value){
|
||||
value.clear();
|
||||
@ -202,6 +212,12 @@ fromStringValue(const QString &inStr, double &value){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromStringValue(const QString &inStr, OAIEnum &value){
|
||||
value.fromJson(inStr);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue(QString &value, const QJsonValue &jval){
|
||||
bool ok = true;
|
||||
@ -324,4 +340,10 @@ fromJsonValue(OAIObject &value, const QJsonValue &jval){
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool
|
||||
fromJsonValue(OAIEnum &value, const QJsonValue &jval){
|
||||
value.fromJsonValue(jval);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include <QDate>
|
||||
#include <QVariant>
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -35,6 +36,7 @@ namespace OpenAPI {
|
||||
QString toStringValue(const bool &value);
|
||||
QString toStringValue(const float &value);
|
||||
QString toStringValue(const double &value);
|
||||
QString toStringValue(const OAIEnum &value);
|
||||
|
||||
template <typename T>
|
||||
QString toStringValue(const QList<T> &val) {
|
||||
@ -58,6 +60,7 @@ namespace OpenAPI {
|
||||
QJsonValue toJsonValue(const float &value);
|
||||
QJsonValue toJsonValue(const double &value);
|
||||
QJsonValue toJsonValue(const OAIObject &value);
|
||||
QJsonValue toJsonValue(const OAIEnum &value);
|
||||
|
||||
template <typename T>
|
||||
QJsonValue toJsonValue(const QList<T> &val) {
|
||||
@ -86,6 +89,7 @@ namespace OpenAPI {
|
||||
bool fromStringValue(const QString &inStr, bool &value);
|
||||
bool fromStringValue(const QString &inStr, float &value);
|
||||
bool fromStringValue(const QString &inStr, double &value);
|
||||
bool fromStringValue(const QString &inStr, OAIEnum &value);
|
||||
|
||||
template <typename T>
|
||||
bool fromStringValue(const QList<QString> &inStr, QList<T> &val) {
|
||||
@ -119,6 +123,7 @@ namespace OpenAPI {
|
||||
bool fromJsonValue(float &value, const QJsonValue &jval);
|
||||
bool fromJsonValue(double &value, const QJsonValue &jval);
|
||||
bool fromJsonValue(OAIObject &value, const QJsonValue &jval);
|
||||
bool fromJsonValue(OAIEnum &value, const QJsonValue &jval);
|
||||
|
||||
template <typename T>
|
||||
bool fromJsonValue(QList<T> &val, const QJsonValue &jval) {
|
||||
|
@ -37,19 +37,25 @@ OAIOrder::~OAIOrder() {
|
||||
|
||||
void
|
||||
OAIOrder::init() {
|
||||
|
||||
m_id_isSet = false;
|
||||
m_id_isValid = false;
|
||||
|
||||
m_pet_id_isSet = false;
|
||||
m_pet_id_isValid = false;
|
||||
|
||||
m_quantity_isSet = false;
|
||||
m_quantity_isValid = false;
|
||||
|
||||
m_ship_date_isSet = false;
|
||||
m_ship_date_isValid = false;
|
||||
|
||||
m_status_isSet = false;
|
||||
m_status_isValid = false;
|
||||
|
||||
m_complete_isSet = false;
|
||||
m_complete_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAIOrder::fromJson(QString jsonString) {
|
||||
@ -61,18 +67,25 @@ OAIOrder::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAIOrder::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
|
||||
|
||||
|
||||
m_pet_id_isValid = ::OpenAPI::fromJsonValue(pet_id, json[QString("petId")]);
|
||||
|
||||
|
||||
m_quantity_isValid = ::OpenAPI::fromJsonValue(quantity, json[QString("quantity")]);
|
||||
|
||||
|
||||
m_ship_date_isValid = ::OpenAPI::fromJsonValue(ship_date, json[QString("shipDate")]);
|
||||
|
||||
|
||||
m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
|
||||
|
||||
|
||||
m_complete_isValid = ::OpenAPI::fromJsonValue(complete, json[QString("complete")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -107,6 +120,7 @@ OAIOrder::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAIOrder::getId() const {
|
||||
return id;
|
||||
@ -117,6 +131,7 @@ OAIOrder::setId(const qint64 &id) {
|
||||
this->m_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAIOrder::getPetId() const {
|
||||
return pet_id;
|
||||
@ -127,6 +142,7 @@ OAIOrder::setPetId(const qint64 &pet_id) {
|
||||
this->m_pet_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
qint32
|
||||
OAIOrder::getQuantity() const {
|
||||
return quantity;
|
||||
@ -137,6 +153,7 @@ OAIOrder::setQuantity(const qint32 &quantity) {
|
||||
this->m_quantity_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QDateTime
|
||||
OAIOrder::getShipDate() const {
|
||||
return ship_date;
|
||||
@ -147,6 +164,7 @@ OAIOrder::setShipDate(const QDateTime &ship_date) {
|
||||
this->m_ship_date_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIOrder::getStatus() const {
|
||||
return status;
|
||||
@ -157,6 +175,7 @@ OAIOrder::setStatus(const QString &status) {
|
||||
this->m_status_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
OAIOrder::isComplete() const {
|
||||
return complete;
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -40,48 +41,63 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint64 getId() const;
|
||||
void setId(const qint64 &id);
|
||||
|
||||
|
||||
qint64 getPetId() const;
|
||||
void setPetId(const qint64 &pet_id);
|
||||
|
||||
|
||||
qint32 getQuantity() const;
|
||||
void setQuantity(const qint32 &quantity);
|
||||
|
||||
|
||||
QDateTime getShipDate() const;
|
||||
void setShipDate(const QDateTime &ship_date);
|
||||
|
||||
|
||||
QString getStatus() const;
|
||||
void setStatus(const QString &status);
|
||||
|
||||
|
||||
bool isComplete() const;
|
||||
void setComplete(const bool &complete);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint64 id;
|
||||
bool m_id_isSet;
|
||||
bool m_id_isValid;
|
||||
|
||||
qint64 pet_id;
|
||||
bool m_pet_id_isSet;
|
||||
bool m_pet_id_isValid;
|
||||
|
||||
qint32 quantity;
|
||||
bool m_quantity_isSet;
|
||||
bool m_quantity_isValid;
|
||||
|
||||
QDateTime ship_date;
|
||||
bool m_ship_date_isSet;
|
||||
bool m_ship_date_isValid;
|
||||
|
||||
QString status;
|
||||
bool m_status_isSet;
|
||||
bool m_status_isValid;
|
||||
|
||||
bool complete;
|
||||
bool m_complete_isSet;
|
||||
bool m_complete_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,19 +37,25 @@ OAIPet::~OAIPet() {
|
||||
|
||||
void
|
||||
OAIPet::init() {
|
||||
|
||||
m_id_isSet = false;
|
||||
m_id_isValid = false;
|
||||
|
||||
m_category_isSet = false;
|
||||
m_category_isValid = false;
|
||||
|
||||
m_name_isSet = false;
|
||||
m_name_isValid = false;
|
||||
|
||||
m_photo_urls_isSet = false;
|
||||
m_photo_urls_isValid = false;
|
||||
|
||||
m_tags_isSet = false;
|
||||
m_tags_isValid = false;
|
||||
|
||||
m_status_isSet = false;
|
||||
m_status_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAIPet::fromJson(QString jsonString) {
|
||||
@ -61,18 +67,25 @@ OAIPet::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAIPet::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
|
||||
|
||||
|
||||
m_category_isValid = ::OpenAPI::fromJsonValue(category, json[QString("category")]);
|
||||
|
||||
|
||||
m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
|
||||
|
||||
|
||||
|
||||
m_photo_urls_isValid = ::OpenAPI::fromJsonValue(photo_urls, json[QString("photoUrls")]);
|
||||
|
||||
|
||||
m_tags_isValid = ::OpenAPI::fromJsonValue(tags, json[QString("tags")]);
|
||||
|
||||
m_status_isValid = ::OpenAPI::fromJsonValue(status, json[QString("status")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -109,6 +122,7 @@ OAIPet::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAIPet::getId() const {
|
||||
return id;
|
||||
@ -119,6 +133,7 @@ OAIPet::setId(const qint64 &id) {
|
||||
this->m_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
OAICategory
|
||||
OAIPet::getCategory() const {
|
||||
return category;
|
||||
@ -129,6 +144,7 @@ OAIPet::setCategory(const OAICategory &category) {
|
||||
this->m_category_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIPet::getName() const {
|
||||
return name;
|
||||
@ -139,6 +155,7 @@ OAIPet::setName(const QString &name) {
|
||||
this->m_name_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QList<QString>
|
||||
OAIPet::getPhotoUrls() const {
|
||||
return photo_urls;
|
||||
@ -149,6 +166,7 @@ OAIPet::setPhotoUrls(const QList<QString> &photo_urls) {
|
||||
this->m_photo_urls_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QList<OAITag>
|
||||
OAIPet::getTags() const {
|
||||
return tags;
|
||||
@ -159,6 +177,7 @@ OAIPet::setTags(const QList<OAITag> &tags) {
|
||||
this->m_tags_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIPet::getStatus() const {
|
||||
return status;
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -42,48 +43,63 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint64 getId() const;
|
||||
void setId(const qint64 &id);
|
||||
|
||||
|
||||
OAICategory getCategory() const;
|
||||
void setCategory(const OAICategory &category);
|
||||
|
||||
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
|
||||
QList<QString> getPhotoUrls() const;
|
||||
void setPhotoUrls(const QList<QString> &photo_urls);
|
||||
|
||||
|
||||
QList<OAITag> getTags() const;
|
||||
void setTags(const QList<OAITag> &tags);
|
||||
|
||||
|
||||
QString getStatus() const;
|
||||
void setStatus(const QString &status);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint64 id;
|
||||
bool m_id_isSet;
|
||||
bool m_id_isValid;
|
||||
|
||||
OAICategory category;
|
||||
bool m_category_isSet;
|
||||
bool m_category_isValid;
|
||||
|
||||
QString name;
|
||||
bool m_name_isSet;
|
||||
bool m_name_isValid;
|
||||
|
||||
QList<QString> photo_urls;
|
||||
bool m_photo_urls_isSet;
|
||||
bool m_photo_urls_isValid;
|
||||
|
||||
QList<OAITag> tags;
|
||||
bool m_tags_isSet;
|
||||
bool m_tags_isValid;
|
||||
|
||||
QString status;
|
||||
bool m_status_isSet;
|
||||
bool m_status_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,11 +37,13 @@ OAITag::~OAITag() {
|
||||
|
||||
void
|
||||
OAITag::init() {
|
||||
|
||||
m_id_isSet = false;
|
||||
m_id_isValid = false;
|
||||
|
||||
m_name_isSet = false;
|
||||
m_name_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAITag::fromJson(QString jsonString) {
|
||||
@ -53,10 +55,13 @@ OAITag::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAITag::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
|
||||
|
||||
|
||||
m_name_isValid = ::OpenAPI::fromJsonValue(name, json[QString("name")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -79,6 +84,7 @@ OAITag::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAITag::getId() const {
|
||||
return id;
|
||||
@ -89,6 +95,7 @@ OAITag::setId(const qint64 &id) {
|
||||
this->m_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAITag::getName() const {
|
||||
return name;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -39,24 +40,31 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint64 getId() const;
|
||||
void setId(const qint64 &id);
|
||||
|
||||
|
||||
QString getName() const;
|
||||
void setName(const QString &name);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint64 id;
|
||||
bool m_id_isSet;
|
||||
bool m_id_isValid;
|
||||
|
||||
QString name;
|
||||
bool m_name_isSet;
|
||||
bool m_name_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -37,23 +37,31 @@ OAIUser::~OAIUser() {
|
||||
|
||||
void
|
||||
OAIUser::init() {
|
||||
|
||||
m_id_isSet = false;
|
||||
m_id_isValid = false;
|
||||
|
||||
m_username_isSet = false;
|
||||
m_username_isValid = false;
|
||||
|
||||
m_first_name_isSet = false;
|
||||
m_first_name_isValid = false;
|
||||
|
||||
m_last_name_isSet = false;
|
||||
m_last_name_isValid = false;
|
||||
|
||||
m_email_isSet = false;
|
||||
m_email_isValid = false;
|
||||
|
||||
m_password_isSet = false;
|
||||
m_password_isValid = false;
|
||||
|
||||
m_phone_isSet = false;
|
||||
m_phone_isValid = false;
|
||||
|
||||
m_user_status_isSet = false;
|
||||
m_user_status_isValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
OAIUser::fromJson(QString jsonString) {
|
||||
@ -65,22 +73,31 @@ OAIUser::fromJson(QString jsonString) {
|
||||
|
||||
void
|
||||
OAIUser::fromJsonObject(QJsonObject json) {
|
||||
|
||||
m_id_isValid = ::OpenAPI::fromJsonValue(id, json[QString("id")]);
|
||||
|
||||
|
||||
m_username_isValid = ::OpenAPI::fromJsonValue(username, json[QString("username")]);
|
||||
|
||||
|
||||
m_first_name_isValid = ::OpenAPI::fromJsonValue(first_name, json[QString("firstName")]);
|
||||
|
||||
|
||||
m_last_name_isValid = ::OpenAPI::fromJsonValue(last_name, json[QString("lastName")]);
|
||||
|
||||
|
||||
m_email_isValid = ::OpenAPI::fromJsonValue(email, json[QString("email")]);
|
||||
|
||||
|
||||
m_password_isValid = ::OpenAPI::fromJsonValue(password, json[QString("password")]);
|
||||
|
||||
|
||||
m_phone_isValid = ::OpenAPI::fromJsonValue(phone, json[QString("phone")]);
|
||||
|
||||
|
||||
m_user_status_isValid = ::OpenAPI::fromJsonValue(user_status, json[QString("userStatus")]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
QString
|
||||
@ -121,6 +138,7 @@ OAIUser::asJsonObject() const {
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
qint64
|
||||
OAIUser::getId() const {
|
||||
return id;
|
||||
@ -131,6 +149,7 @@ OAIUser::setId(const qint64 &id) {
|
||||
this->m_id_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getUsername() const {
|
||||
return username;
|
||||
@ -141,6 +160,7 @@ OAIUser::setUsername(const QString &username) {
|
||||
this->m_username_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getFirstName() const {
|
||||
return first_name;
|
||||
@ -151,6 +171,7 @@ OAIUser::setFirstName(const QString &first_name) {
|
||||
this->m_first_name_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getLastName() const {
|
||||
return last_name;
|
||||
@ -161,6 +182,7 @@ OAIUser::setLastName(const QString &last_name) {
|
||||
this->m_last_name_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getEmail() const {
|
||||
return email;
|
||||
@ -171,6 +193,7 @@ OAIUser::setEmail(const QString &email) {
|
||||
this->m_email_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getPassword() const {
|
||||
return password;
|
||||
@ -181,6 +204,7 @@ OAIUser::setPassword(const QString &password) {
|
||||
this->m_password_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
OAIUser::getPhone() const {
|
||||
return phone;
|
||||
@ -191,6 +215,7 @@ OAIUser::setPhone(const QString &phone) {
|
||||
this->m_phone_isSet = true;
|
||||
}
|
||||
|
||||
|
||||
qint32
|
||||
OAIUser::getUserStatus() const {
|
||||
return user_status;
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <QString>
|
||||
|
||||
#include "OAIObject.h"
|
||||
#include "OAIEnum.h"
|
||||
|
||||
namespace OpenAPI {
|
||||
|
||||
@ -39,60 +40,79 @@ public:
|
||||
void fromJsonObject(QJsonObject json) override;
|
||||
void fromJson(QString jsonString) override;
|
||||
|
||||
|
||||
qint64 getId() const;
|
||||
void setId(const qint64 &id);
|
||||
|
||||
|
||||
QString getUsername() const;
|
||||
void setUsername(const QString &username);
|
||||
|
||||
|
||||
QString getFirstName() const;
|
||||
void setFirstName(const QString &first_name);
|
||||
|
||||
|
||||
QString getLastName() const;
|
||||
void setLastName(const QString &last_name);
|
||||
|
||||
|
||||
QString getEmail() const;
|
||||
void setEmail(const QString &email);
|
||||
|
||||
|
||||
QString getPassword() const;
|
||||
void setPassword(const QString &password);
|
||||
|
||||
|
||||
QString getPhone() const;
|
||||
void setPhone(const QString &phone);
|
||||
|
||||
|
||||
qint32 getUserStatus() const;
|
||||
void setUserStatus(const qint32 &user_status);
|
||||
|
||||
|
||||
|
||||
virtual bool isSet() const override;
|
||||
virtual bool isValid() const override;
|
||||
|
||||
private:
|
||||
void init();
|
||||
|
||||
qint64 id;
|
||||
bool m_id_isSet;
|
||||
bool m_id_isValid;
|
||||
|
||||
QString username;
|
||||
bool m_username_isSet;
|
||||
bool m_username_isValid;
|
||||
|
||||
QString first_name;
|
||||
bool m_first_name_isSet;
|
||||
bool m_first_name_isValid;
|
||||
|
||||
QString last_name;
|
||||
bool m_last_name_isSet;
|
||||
bool m_last_name_isValid;
|
||||
|
||||
QString email;
|
||||
bool m_email_isSet;
|
||||
bool m_email_isValid;
|
||||
|
||||
QString password;
|
||||
bool m_password_isSet;
|
||||
bool m_password_isValid;
|
||||
|
||||
QString phone;
|
||||
bool m_phone_isSet;
|
||||
bool m_phone_isValid;
|
||||
|
||||
qint32 user_status;
|
||||
bool m_user_status_isSet;
|
||||
bool m_user_status_isValid;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,6 +16,7 @@ HEADERS += \
|
||||
$${PWD}/OAIHelpers.h \
|
||||
$${PWD}/OAIHttpRequest.h \
|
||||
$${PWD}/OAIObject.h
|
||||
$${PWD}/OAIEnum.h
|
||||
|
||||
SOURCES += \
|
||||
# Models
|
||||
|
Loading…
x
Reference in New Issue
Block a user