Skip to content

[Qt5 C++] Fix file support in form parameter #2006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions modules/swagger-codegen/src/main/resources/qt5cpp/api-body.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void

{{#queryParams}}
{{^collectionFormat}}
if(fullPath.indexOf("?") > 0)
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
Expand All @@ -40,39 +40,39 @@ 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("?");
fullPath.append("{{{paramName}}}=").append(stringValue(t));
}
}
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));
Expand All @@ -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}}
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/qt5cpp/client/SWGPet.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
#include <QJsonObject>


#include <QString>
#include "SWGCategory.h"
#include <QList>
#include "SWGTag.h"
#include <QList>
#include <QString>

#include "SWGObject.h"

Expand Down
143 changes: 123 additions & 20 deletions samples/client/petstore/qt5cpp/client/SWGPetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,39 +123,39 @@ 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("?");
fullPath.append("status=").append(stringValue(t));
}
}
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));
Expand Down Expand Up @@ -228,39 +228,39 @@ 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("?");
fullPath.append("tags=").append(stringValue(t));
}
}
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));
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}



Expand Down Expand Up @@ -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 */
6 changes: 6 additions & 0 deletions samples/client/petstore/qt5cpp/client/SWGPetApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class SWGPetApi: public QObject {
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);
Expand All @@ -40,6 +42,8 @@ class SWGPetApi: public QObject {
void updatePetWithFormCallback (HttpRequestWorker * worker);
void deletePetCallback (HttpRequestWorker * worker);
void uploadFileCallback (HttpRequestWorker * worker);
void getPetByIdWithByteArrayCallback (HttpRequestWorker * worker);
void addPetUsingByteArrayCallback (HttpRequestWorker * worker);

signals:
void updatePetSignal();
Expand All @@ -50,6 +54,8 @@ class SWGPetApi: public QObject {
void updatePetWithFormSignal();
void deletePetSignal();
void uploadFileSignal();
void getPetByIdWithByteArraySignal(QString* summary);
void addPetUsingByteArraySignal();

};
}
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/qt5cpp/client/SWGUserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ SWGUserApi::loginUser(QString* username, QString* password) {



if(fullPath.indexOf("?") > 0)
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
Expand All @@ -190,7 +190,7 @@ SWGUserApi::loginUser(QString* username, QString* password) {



if(fullPath.indexOf("?") > 0)
if (fullPath.indexOf("?") > 0)
fullPath.append("&");
else
fullPath.append("?");
Expand Down