fix NPE with qt5 pestore 3.0 spec

This commit is contained in:
wing328
2018-04-04 22:37:12 +08:00
parent 8dbf2ed851
commit df19e1e05e
11 changed files with 511 additions and 22 deletions

31
bin/openapi3/qt5-petstore.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/sh
SCRIPT="$0"
while [ -h "$SCRIPT" ] ; do
ls=`ls -ld "$SCRIPT"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
SCRIPT="$link"
else
SCRIPT=`dirname "$SCRIPT"`/"$link"
fi
done
if [ ! -d "${APP_DIR}" ]; then
APP_DIR=`dirname "$SCRIPT"`/..
APP_DIR=`cd "${APP_DIR}"; pwd`
fi
executable="./modules/openapi-generator-cli/target/openapi-generator-cli.jar"
if [ ! -f "$executable" ]
then
mvn clean package
fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -XX:MaxPermSize=256M -Xmx1024M -DloggerPath=conf/log4j.properties"
ags="$@ generate -t modules/openapi-generator/src/main/resources/qt5cpp -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -l cpp-qt5 -o samples/client/petstore/qt5cpp"
java $JAVA_OPTS -jar $executable $ags

View File

@@ -289,8 +289,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
Schema inner = ap.getItems();
return getSchemaType(p) + "<" + getTypeDeclaration(inner) + ">*";
} else if (isMapSchema(p)) {
MapSchema mp = (MapSchema) p;
Schema inner = (Schema) mp.getAdditionalProperties();
Schema inner = (Schema) p.getAdditionalProperties();
return getSchemaType(p) + "<QString, " + getTypeDeclaration(inner) + ">*";
}
if (foundationClasses.contains(openAPIType)) {

View File

@@ -0,0 +1,126 @@
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
#include "SWGBody.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGBody::SWGBody(QString json) {
init();
this->fromJson(json);
}
SWGBody::SWGBody() {
init();
}
SWGBody::~SWGBody() {
this->cleanup();
}
void
SWGBody::init() {
name = new QString("");
m_name_isSet = false;
status = new QString("");
m_status_isSet = false;
}
void
SWGBody::cleanup() {
if(name != nullptr) {
delete name;
}
if(status != nullptr) {
delete status;
}
}
SWGBody*
SWGBody::fromJson(QString json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGBody::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&name, pJson["name"], "QString", "QString");
::Swagger::setValue(&status, pJson["status"], "QString", "QString");
}
QString
SWGBody::asJson ()
{
QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject
SWGBody::asJsonObject() {
QJsonObject obj;
if(name != nullptr && *name != QString("")){
toJsonValue(QString("name"), name, obj, QString("QString"));
}
if(status != nullptr && *status != QString("")){
toJsonValue(QString("status"), status, obj, QString("QString"));
}
return obj;
}
QString*
SWGBody::getName() {
return name;
}
void
SWGBody::setName(QString* name) {
this->name = name;
this->m_name_isSet = true;
}
QString*
SWGBody::getStatus() {
return status;
}
void
SWGBody::setStatus(QString* status) {
this->status = status;
this->m_status_isSet = true;
}
bool
SWGBody::isSet(){
bool isObjectUpdated = false;
do{
if(name != nullptr && *name != QString("")){ isObjectUpdated = true; break;}
if(status != nullptr && *status != QString("")){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}
}

View File

@@ -0,0 +1,64 @@
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/*
* SWGBody.h
*
*
*/
#ifndef SWGBody_H_
#define SWGBody_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGBody: public SWGObject {
public:
SWGBody();
SWGBody(QString json);
~SWGBody();
void init();
void cleanup();
QString asJson () override;
QJsonObject asJsonObject() override;
void fromJsonObject(QJsonObject json) override;
SWGBody* fromJson(QString jsonString) override;
QString* getName();
void setName(QString* name);
QString* getStatus();
void setStatus(QString* status);
virtual bool isSet() override;
private:
QString* name;
bool m_name_isSet;
QString* status;
bool m_status_isSet;
};
}
#endif /* SWGBody_H_ */

View File

@@ -0,0 +1,126 @@
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
#include "SWGBody_1.h"
#include "SWGHelpers.h"
#include <QJsonDocument>
#include <QJsonArray>
#include <QObject>
#include <QDebug>
namespace Swagger {
SWGBody_1::SWGBody_1(QString json) {
init();
this->fromJson(json);
}
SWGBody_1::SWGBody_1() {
init();
}
SWGBody_1::~SWGBody_1() {
this->cleanup();
}
void
SWGBody_1::init() {
additional_metadata = new QString("");
m_additional_metadata_isSet = false;
file = NULL;
m_file_isSet = false;
}
void
SWGBody_1::cleanup() {
if(additional_metadata != nullptr) {
delete additional_metadata;
}
if(file != nullptr) {
delete file;
}
}
SWGBody_1*
SWGBody_1::fromJson(QString json) {
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject jsonObject = doc.object();
this->fromJsonObject(jsonObject);
return this;
}
void
SWGBody_1::fromJsonObject(QJsonObject pJson) {
::Swagger::setValue(&additional_metadata, pJson["additionalMetadata"], "QString", "QString");
::Swagger::setValue(&file, pJson["file"], "QString", "QString");
}
QString
SWGBody_1::asJson ()
{
QJsonObject obj = this->asJsonObject();
QJsonDocument doc(obj);
QByteArray bytes = doc.toJson();
return QString(bytes);
}
QJsonObject
SWGBody_1::asJsonObject() {
QJsonObject obj;
if(additional_metadata != nullptr && *additional_metadata != QString("")){
toJsonValue(QString("additionalMetadata"), additional_metadata, obj, QString("QString"));
}
if((file != nullptr) && (file->isSet())){
toJsonValue(QString("file"), file, obj, QString("QString"));
}
return obj;
}
QString*
SWGBody_1::getAdditionalMetadata() {
return additional_metadata;
}
void
SWGBody_1::setAdditionalMetadata(QString* additional_metadata) {
this->additional_metadata = additional_metadata;
this->m_additional_metadata_isSet = true;
}
QString*
SWGBody_1::getFile() {
return file;
}
void
SWGBody_1::setFile(QString* file) {
this->file = file;
this->m_file_isSet = true;
}
bool
SWGBody_1::isSet(){
bool isObjectUpdated = false;
do{
if(additional_metadata != nullptr && *additional_metadata != QString("")){ isObjectUpdated = true; break;}
if(file != nullptr && file->isSet()){ isObjectUpdated = true; break;}
}while(false);
return isObjectUpdated;
}
}

View File

@@ -0,0 +1,64 @@
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually.
*/
/*
* SWGBody_1.h
*
*
*/
#ifndef SWGBody_1_H_
#define SWGBody_1_H_
#include <QJsonObject>
#include <QString>
#include "SWGObject.h"
namespace Swagger {
class SWGBody_1: public SWGObject {
public:
SWGBody_1();
SWGBody_1(QString json);
~SWGBody_1();
void init();
void cleanup();
QString asJson () override;
QJsonObject asJsonObject() override;
void fromJsonObject(QJsonObject json) override;
SWGBody_1* fromJson(QString jsonString) override;
QString* getAdditionalMetadata();
void setAdditionalMetadata(QString* additional_metadata);
QString* getFile();
void setFile(QString* file);
virtual bool isSet() override;
private:
QString* additional_metadata;
bool m_additional_metadata_isSet;
QString* file;
bool m_file_isSet;
};
}
#endif /* SWGBody_1_H_ */

View File

@@ -16,6 +16,8 @@
#include "SWGObject.h"
#include "SWGApiResponse.h"
#include "SWGBody.h"
#include "SWGBody_1.h"
#include "SWGCategory.h"
#include "SWGOrder.h"
#include "SWGPet.h"
@@ -28,6 +30,12 @@ namespace Swagger {
if(QString("SWGApiResponse").compare(type) == 0) {
return new SWGApiResponse();
}
if(QString("SWGBody").compare(type) == 0) {
return new SWGBody();
}
if(QString("SWGBody_1").compare(type) == 0) {
return new SWGBody_1();
}
if(QString("SWGCategory").compare(type) == 0) {
return new SWGCategory();
}

View File

@@ -141,13 +141,47 @@ SWGPetApi::findPetsByStatus(QList<QString*>* status) {
fullPath.append(this->host).append(this->basePath).append("/pet/findByStatus");
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("status"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(status)));
if (status->size() > 0) {
if (QString("csv").indexOf("multi") == 0) {
foreach(QString* t, *status) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=").append(stringValue(t));
}
}
else if (QString("csv").indexOf("ssv") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=");
qint32 count = 0;
foreach(QString* t, *status) {
if (count > 0) {
fullPath.append(" ");
}
fullPath.append(stringValue(t));
}
}
else if (QString("csv").indexOf("tsv") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("status=");
qint32 count = 0;
foreach(QString* t, *status) {
if (count > 0) {
fullPath.append("\t");
}
fullPath.append(stringValue(t));
}
}
}
SWGHttpRequestWorker *worker = new SWGHttpRequestWorker();
@@ -214,13 +248,47 @@ SWGPetApi::findPetsByTags(QList<QString*>* tags) {
fullPath.append(this->host).append(this->basePath).append("/pet/findByTags");
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append(QUrl::toPercentEncoding("tags"))
.append("=")
.append(QUrl::toPercentEncoding(stringValue(tags)));
if (tags->size() > 0) {
if (QString("csv").indexOf("multi") == 0) {
foreach(QString* t, *tags) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=").append(stringValue(t));
}
}
else if (QString("csv").indexOf("ssv") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=");
qint32 count = 0;
foreach(QString* t, *tags) {
if (count > 0) {
fullPath.append(" ");
}
fullPath.append(stringValue(t));
}
}
else if (QString("csv").indexOf("tsv") == 0) {
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
fullPath.append("tags=");
qint32 count = 0;
foreach(QString* t, *tags) {
if (count > 0) {
fullPath.append("\t");
}
fullPath.append(stringValue(t));
}
}
}
SWGHttpRequestWorker *worker = new SWGHttpRequestWorker();
@@ -446,7 +514,7 @@ SWGPetApi::updatePetWithFormCallback(SWGHttpRequestWorker * worker) {
}
void
SWGPetApi::uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file) {
SWGPetApi::uploadFile(qint64 pet_id, QString* additional_metadata, QString* file) {
QString fullPath;
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage");

View File

@@ -17,7 +17,6 @@
#include <QString>
#include "SWGApiResponse.h"
#include "SWGHttpRequest.h"
#include "SWGPet.h"
#include <QObject>
@@ -43,7 +42,7 @@ public:
void getPetById(qint64 pet_id);
void updatePet(SWGPet& pet);
void updatePetWithForm(qint64 pet_id, QString* name, QString* status);
void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file);
void uploadFile(qint64 pet_id, QString* additional_metadata, QString* file);
private:
void addPetCallback (SWGHttpRequestWorker * worker);

View File

@@ -119,15 +119,15 @@ SWGStoreApi::getInventoryCallback(SWGHttpRequestWorker * worker) {
msg = "Error: " + worker->error_str;
}
QMap<QString, qint32>* output = new QMap<QString, qint32>();
QMap<QString, qint32>* output = NULL;
QString json(worker->response);
QByteArray array (json.toStdString().c_str());
QJsonDocument doc = QJsonDocument::fromJson(array);
QJsonObject obj = doc.object();
foreach(QString key, obj.keys()) {
qint32 val;
setValue(&val, obj[key], "qint32", QString());
QMap val;
setValue(&val, obj[key], "QMap", QString());
output->insert(key, val);
}
worker->deleteLater();

View File

@@ -3,6 +3,8 @@ QT += network
HEADERS += \
# Models
$${PWD}/SWGApiResponse.h \
$${PWD}/SWGBody.h \
$${PWD}/SWGBody_1.h \
$${PWD}/SWGCategory.h \
$${PWD}/SWGOrder.h \
$${PWD}/SWGPet.h \
@@ -22,6 +24,8 @@ HEADERS += \
SOURCES += \
# Models
$${PWD}/SWGApiResponse.cpp \
$${PWD}/SWGBody.cpp \
$${PWD}/SWGBody_1.cpp \
$${PWD}/SWGCategory.cpp \
$${PWD}/SWGOrder.cpp \
$${PWD}/SWGPet.cpp \