mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 10:58:55 +00:00
fix file support in form parameter (qt5cpp)
This commit is contained in:
parent
f42f9acf35
commit
d5aa285926
@ -29,7 +29,7 @@ void
|
||||
|
||||
{{#queryParams}}
|
||||
{{^collectionFormat}}
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
@ -40,10 +40,10 @@ void
|
||||
|
||||
{{#collectionFormat}}
|
||||
|
||||
if({{{paramName}}}->size() > 0) {
|
||||
if(QString("{{collectionFormat}}").indexOf("multi") == 0) {
|
||||
if ({{{paramName}}}->size() > 0) {
|
||||
if (QString("{{collectionFormat}}").indexOf("multi") == 0) {
|
||||
foreach({{{baseType}}} t, *{{paramName}}) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
@ -51,28 +51,28 @@ void
|
||||
}
|
||||
}
|
||||
else if (QString("{{collectionFormat}}").indexOf("ssv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("{{paramName}}=");
|
||||
qint32 count = 0;
|
||||
foreach({{{baseType}}} t, *{{paramName}}) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append(" ");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
}
|
||||
}
|
||||
else if (QString("{{collectionFormat}}").indexOf("tsv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("{{paramName}}=");
|
||||
qint32 count = 0;
|
||||
foreach({{{baseType}}} t, *{{paramName}}) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append("\t");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
@ -86,11 +86,10 @@ void
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "{{httpMethod}}");
|
||||
|
||||
{{#formParams}}{{^isFile}}
|
||||
if({{paramName}} != NULL) {
|
||||
input.add_var("{{paramName}}", *{{paramName}});
|
||||
{{#formParams}}if ({{paramName}} != NULL) {
|
||||
{{^isFile}}input.add_var("{{paramName}}", *{{paramName}});{{/isFile}}{{#isFile}}input.add_file("{{paramName}}", *{{paramName}}.local_filename, *{{paramName}}.request_filename, *{{paramName}}.mime_type);{{/isFile}}
|
||||
}
|
||||
{{/isFile}}{{/formParams}}
|
||||
{{/formParams}}
|
||||
|
||||
{{#bodyParams}}
|
||||
{{#isContainer}}
|
||||
|
@ -10,10 +10,10 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
|
||||
#include <QString>
|
||||
#include "SWGCategory.h"
|
||||
#include <QList>
|
||||
#include "SWGTag.h"
|
||||
#include <QList>
|
||||
#include <QString>
|
||||
|
||||
#include "SWGObject.h"
|
||||
|
||||
|
@ -123,10 +123,10 @@ SWGPetApi::findPetsByStatus(QList<QString*>* status) {
|
||||
|
||||
|
||||
|
||||
if(status->size() > 0) {
|
||||
if(QString("multi").indexOf("multi") == 0) {
|
||||
if (status->size() > 0) {
|
||||
if (QString("multi").indexOf("multi") == 0) {
|
||||
foreach(QString* t, *status) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
@ -134,28 +134,28 @@ SWGPetApi::findPetsByStatus(QList<QString*>* status) {
|
||||
}
|
||||
}
|
||||
else if (QString("multi").indexOf("ssv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("status=");
|
||||
qint32 count = 0;
|
||||
foreach(QString* t, *status) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append(" ");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
}
|
||||
}
|
||||
else if (QString("multi").indexOf("tsv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("status=");
|
||||
qint32 count = 0;
|
||||
foreach(QString* t, *status) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append("\t");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
@ -228,10 +228,10 @@ SWGPetApi::findPetsByTags(QList<QString*>* tags) {
|
||||
|
||||
|
||||
|
||||
if(tags->size() > 0) {
|
||||
if(QString("multi").indexOf("multi") == 0) {
|
||||
if (tags->size() > 0) {
|
||||
if (QString("multi").indexOf("multi") == 0) {
|
||||
foreach(QString* t, *tags) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
@ -239,28 +239,28 @@ SWGPetApi::findPetsByTags(QList<QString*>* tags) {
|
||||
}
|
||||
}
|
||||
else if (QString("multi").indexOf("ssv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("tags=");
|
||||
qint32 count = 0;
|
||||
foreach(QString* t, *tags) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append(" ");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
}
|
||||
}
|
||||
else if (QString("multi").indexOf("tsv") == 0) {
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
fullPath.append("tags=");
|
||||
qint32 count = 0;
|
||||
foreach(QString* t, *tags) {
|
||||
if(count > 0) {
|
||||
if (count > 0) {
|
||||
fullPath.append("\t");
|
||||
}
|
||||
fullPath.append(stringValue(t));
|
||||
@ -391,12 +391,10 @@ SWGPetApi::updatePetWithForm(QString* petId, QString* name, QString* status) {
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
if(name != NULL) {
|
||||
if (name != NULL) {
|
||||
input.add_var("name", *name);
|
||||
}
|
||||
|
||||
if(status != NULL) {
|
||||
if (status != NULL) {
|
||||
input.add_var("status", *status);
|
||||
}
|
||||
|
||||
@ -493,10 +491,12 @@ SWGPetApi::uploadFile(qint64 petId, QString* additionalMetadata, SWGHttpRequestI
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
if(additionalMetadata != NULL) {
|
||||
if (additionalMetadata != NULL) {
|
||||
input.add_var("additionalMetadata", *additionalMetadata);
|
||||
}
|
||||
if (file != NULL) {
|
||||
input.add_file("file", *file.local_filename, *file.request_filename, *file.mime_type);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -528,4 +528,107 @@ SWGPetApi::uploadFileCallback(HttpRequestWorker * worker) {
|
||||
|
||||
emit uploadFileSignal();
|
||||
}
|
||||
void
|
||||
SWGPetApi::getPetByIdWithByteArray(qint64 petId) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/pet/{petId}?testing_byte_array=true");
|
||||
|
||||
|
||||
QString petIdPathParam("{"); petIdPathParam.append("petId").append("}");
|
||||
fullPath.replace(petIdPathParam, stringValue(petId));
|
||||
|
||||
|
||||
|
||||
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "GET");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
connect(worker,
|
||||
&HttpRequestWorker::on_execution_finished,
|
||||
this,
|
||||
&SWGPetApi::getPetByIdWithByteArrayCallback);
|
||||
|
||||
worker->execute(&input);
|
||||
}
|
||||
|
||||
void
|
||||
SWGPetApi::getPetByIdWithByteArrayCallback(HttpRequestWorker * worker) {
|
||||
QString msg;
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
}
|
||||
else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QString json(worker->response);
|
||||
QString* output = static_cast<QString*>(create(json, QString("QString")));
|
||||
|
||||
|
||||
|
||||
|
||||
worker->deleteLater();
|
||||
|
||||
emit getPetByIdWithByteArraySignal(output);
|
||||
|
||||
}
|
||||
void
|
||||
SWGPetApi::addPetUsingByteArray(QString* body) {
|
||||
QString fullPath;
|
||||
fullPath.append(this->host).append(this->basePath).append("/pet?testing_byte_array=true");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QString output = body.asJson();
|
||||
input.request_body.append(output);
|
||||
|
||||
|
||||
|
||||
|
||||
connect(worker,
|
||||
&HttpRequestWorker::on_execution_finished,
|
||||
this,
|
||||
&SWGPetApi::addPetUsingByteArrayCallback);
|
||||
|
||||
worker->execute(&input);
|
||||
}
|
||||
|
||||
void
|
||||
SWGPetApi::addPetUsingByteArrayCallback(HttpRequestWorker * worker) {
|
||||
QString msg;
|
||||
if (worker->error_type == QNetworkReply::NoError) {
|
||||
msg = QString("Success! %1 bytes").arg(worker->response.length());
|
||||
}
|
||||
else {
|
||||
msg = "Error: " + worker->error_str;
|
||||
}
|
||||
|
||||
|
||||
|
||||
worker->deleteLater();
|
||||
|
||||
|
||||
emit addPetUsingByteArraySignal();
|
||||
}
|
||||
} /* namespace Swagger */
|
||||
|
@ -30,6 +30,8 @@ public:
|
||||
void updatePetWithForm(QString* petId, QString* name, QString* status);
|
||||
void deletePet(qint64 petId, QString* apiKey);
|
||||
void uploadFile(qint64 petId, QString* additionalMetadata, SWGHttpRequestInputFileElement* file);
|
||||
void getPetByIdWithByteArray(qint64 petId);
|
||||
void addPetUsingByteArray(QString* body);
|
||||
|
||||
private:
|
||||
void updatePetCallback (HttpRequestWorker * worker);
|
||||
@ -40,6 +42,8 @@ private:
|
||||
void updatePetWithFormCallback (HttpRequestWorker * worker);
|
||||
void deletePetCallback (HttpRequestWorker * worker);
|
||||
void uploadFileCallback (HttpRequestWorker * worker);
|
||||
void getPetByIdWithByteArrayCallback (HttpRequestWorker * worker);
|
||||
void addPetUsingByteArrayCallback (HttpRequestWorker * worker);
|
||||
|
||||
signals:
|
||||
void updatePetSignal();
|
||||
@ -50,6 +54,8 @@ signals:
|
||||
void updatePetWithFormSignal();
|
||||
void deletePetSignal();
|
||||
void uploadFileSignal();
|
||||
void getPetByIdWithByteArraySignal(QString* summary);
|
||||
void addPetUsingByteArraySignal();
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -178,7 +178,7 @@ SWGUserApi::loginUser(QString* username, QString* password) {
|
||||
|
||||
|
||||
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
@ -190,7 +190,7 @@ SWGUserApi::loginUser(QString* username, QString* password) {
|
||||
|
||||
|
||||
|
||||
if(fullPath.indexOf("?") > 0)
|
||||
if (fullPath.indexOf("?") > 0)
|
||||
fullPath.append("&");
|
||||
else
|
||||
fullPath.append("?");
|
||||
|
Loading…
Reference in New Issue
Block a user