mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 12:40:53 +00:00
fix NPE with cpp qt5, add logic to avoid NPE with composed schema (#267)
This commit is contained in:
parent
acb63fd5e8
commit
0b3ec6b1f8
@ -1148,6 +1148,18 @@ public class DefaultCodegen implements CodegenConfig {
|
||||
**/
|
||||
@SuppressWarnings("static-method")
|
||||
public String getSchemaType(Schema schema) {
|
||||
// TODO better logic to handle compose schema
|
||||
if (schema instanceof ComposedSchema) { // composed schema
|
||||
ComposedSchema cs = (ComposedSchema) schema;
|
||||
for (Schema s : cs.getAllOf()) {
|
||||
if (s != null) {
|
||||
// using the first schema defined in allOf
|
||||
schema = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(schema.get$ref())) { // object
|
||||
// get the schema/model name from $ref
|
||||
String schemaName = ModelUtils.getSimpleRef(schema.get$ref());
|
||||
|
@ -345,6 +345,7 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
@Override
|
||||
public String getSchemaType(Schema p) {
|
||||
String openAPIType = super.getSchemaType(p);
|
||||
|
||||
String type = null;
|
||||
if (typeMapping.containsKey(openAPIType)) {
|
||||
type = typeMapping.get(openAPIType);
|
||||
@ -362,6 +363,11 @@ public class CppQt5ClientCodegen extends AbstractCppCodegen implements CodegenCo
|
||||
|
||||
@Override
|
||||
public String toModelName(String type) {
|
||||
if (type == null) {
|
||||
LOGGER.warn("Model name can't be null. Defaul to 'UnknownModel'.");
|
||||
type = "UnknownModel";
|
||||
}
|
||||
|
||||
if (typeMapping.keySet().contains(type) ||
|
||||
typeMapping.values().contains(type) ||
|
||||
importMapping.values().contains(type) ||
|
||||
|
@ -30,7 +30,7 @@ SWGPetApi::SWGPetApi(QString host, QString basePath) {
|
||||
}
|
||||
|
||||
void
|
||||
SWGPetApi::addPet(SWGPet& swg_pet) {
|
||||
SWGPetApi::addPet(std::shared_ptr<SWGSWGPet>& swg_pet) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/pet");
|
||||
|
||||
@ -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();
|
||||
@ -337,7 +405,7 @@ SWGPetApi::getPetByIdCallback(SWGHttpRequestWorker * worker) {
|
||||
}
|
||||
|
||||
void
|
||||
SWGPetApi::updatePet(SWGPet& swg_pet) {
|
||||
SWGPetApi::updatePet(std::shared_ptr<SWGSWGPet>& swg_pet) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/pet");
|
||||
|
||||
|
@ -36,12 +36,12 @@ public:
|
||||
QString basePath;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
|
||||
void addPet(SWGPet& swg_pet);
|
||||
void addPet(std::shared_ptr<SWGSWGPet>& swg_pet);
|
||||
void deletePet(qint64 pet_id, QString* api_key);
|
||||
void findPetsByStatus(QList<QString*>* status);
|
||||
void findPetsByTags(QList<QString*>* tags);
|
||||
void getPetById(qint64 pet_id);
|
||||
void updatePet(SWGPet& swg_pet);
|
||||
void updatePet(std::shared_ptr<SWGSWGPet>& swg_pet);
|
||||
void updatePetWithForm(qint64 pet_id, QString* name, QString* status);
|
||||
void uploadFile(qint64 pet_id, QString* additional_metadata, SWGHttpRequestInputFileElement* file);
|
||||
|
||||
|
@ -196,7 +196,7 @@ SWGStoreApi::getOrderByIdCallback(SWGHttpRequestWorker * worker) {
|
||||
}
|
||||
|
||||
void
|
||||
SWGStoreApi::placeOrder(SWGOrder& swg_order) {
|
||||
SWGStoreApi::placeOrder(std::shared_ptr<SWGSWGOrder>& swg_order) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/store/order");
|
||||
|
||||
|
@ -38,7 +38,7 @@ public:
|
||||
void deleteOrder(QString* order_id);
|
||||
void getInventory();
|
||||
void getOrderById(qint64 order_id);
|
||||
void placeOrder(SWGOrder& swg_order);
|
||||
void placeOrder(std::shared_ptr<SWGSWGOrder>& swg_order);
|
||||
|
||||
private:
|
||||
void deleteOrderCallback (SWGHttpRequestWorker * worker);
|
||||
|
@ -30,7 +30,7 @@ SWGUserApi::SWGUserApi(QString host, QString basePath) {
|
||||
}
|
||||
|
||||
void
|
||||
SWGUserApi::createUser(SWGUser& swg_user) {
|
||||
SWGUserApi::createUser(std::shared_ptr<SWGSWGUser>& swg_user) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/user");
|
||||
|
||||
@ -418,7 +418,7 @@ SWGUserApi::logoutUserCallback(SWGHttpRequestWorker * worker) {
|
||||
}
|
||||
|
||||
void
|
||||
SWGUserApi::updateUser(QString* username, SWGUser& swg_user) {
|
||||
SWGUserApi::updateUser(QString* username, std::shared_ptr<SWGSWGUser>& swg_user) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/user/{username}");
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include "SWGHttpRequest.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
#include "SWGUser.h"
|
||||
|
||||
@ -34,14 +35,14 @@ public:
|
||||
QString basePath;
|
||||
QMap<QString, QString> defaultHeaders;
|
||||
|
||||
void createUser(SWGUser& swg_user);
|
||||
void createUser(std::shared_ptr<SWGSWGUser>& swg_user);
|
||||
void createUsersWithArrayInput(QList<SWGUser*>*& swg_user);
|
||||
void createUsersWithListInput(QList<SWGUser*>*& swg_user);
|
||||
void deleteUser(QString* username);
|
||||
void getUserByName(QString* username);
|
||||
void loginUser(QString* username, QString* password);
|
||||
void logoutUser();
|
||||
void updateUser(QString* username, SWGUser& swg_user);
|
||||
void updateUser(QString* username, std::shared_ptr<SWGSWGUser>& swg_user);
|
||||
|
||||
private:
|
||||
void createUserCallback (SWGHttpRequestWorker * worker);
|
||||
|
Loading…
x
Reference in New Issue
Block a user