forked from loafle/openapi-generator-original
fix file support in form parameter (qt5cpp)
This commit is contained in:
parent
f42f9acf35
commit
d5aa285926
@ -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"
|
||||
|
||||
|
@ -391,11 +391,9 @@ SWGPetApi::updatePetWithForm(QString* petId, QString* name, QString* status) {
|
||||
HttpRequestWorker *worker = new HttpRequestWorker();
|
||||
HttpRequestInput input(fullPath, "POST");
|
||||
|
||||
|
||||
if (name != NULL) {
|
||||
input.add_var("name", *name);
|
||||
}
|
||||
|
||||
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) {
|
||||
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();
|
||||
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user