Created by: etherealjoy
PR checklist
-
Read the contribution guidelines. -
Ran the shell script under ./bin/
to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\
. If contributing template-only or documentation-only changes which will change sample output, be sure to build the project first. -
Filed the PR against the correct branch: master
,4.1.x
,5.0.x
. Default:master
. -
Copied the technical committee to review the pull request if your PR is targeting a particular programming language.
Description of the PR
- Add File Upload support for the Qt5 client
- Add File download support for the Qt5 client
- Setup file handling for the Qt5 server only for the common part with client
ToDo
:
- Setup file handling for the Qt5 server
- The
HttpFileElement
can be extended to passQIODevice
streams instead which includes files, sockets and so on.
Fixes:
#3651
#3421 (closed)
#3457 (closed)
Note:
Not a breaking change for the File handling changes, as it never worked to begin with.
Sample Usage:
#include <QDebug>
#include <QCoreApplication>
#include <QTimer>
#include <OAIDefaultApi.h>
using namespace OpenAPI;
int main(int argc, char *argv[]) {
QCoreApplication a(argc, argv);
OAIDefaultApi api;
api.setHost("http://127.0.0.1:8081");
OpenAPI::OAIHttpFileElement fileElement;
fileElement.setMimeType("image/png;charset=UTF-8");
fileElement.setRequestFileName("FileExt2.png");
fileElement.setFileName("/home/dev/testapp/ext2.png");
QString fileId = "fileId";
qint32 orderId = 555;
qint32 userId = 777;
QObject::connect(&api, &OpenAPI::OAIDefaultApi::downLoadFileSignal,
[&](OAIHttpFileElement summary)
{
qDebug() << "Downloaded the file " << summary.local_filename;
});
QObject::connect(&api, &OpenAPI::OAIDefaultApi::upLoadFileSignal,
[]()
{
qDebug() << "Uploaded the file ";
});
QObject::connect(&api, &OpenAPI::OAIDefaultApi::upLoadFileWithInfoSignal,
[]()
{
qDebug() << "Uploaded the file with info";
});
QTimer::singleShot(0, [&]()
{
api.downLoadFile(QString("appsettings.json"));
api.upLoadFile(fileId, fileElement);
api.upLoadFileWithInfo(fileId, orderId, userId, fileElement);
}
);
a.exec();
return 0;
}
sample spec for test
openapi: 3.0.0
servers:
- url: 'https://api.testapp.com'
info:
description: Test API for download and upload features.
version: 1.0.0
title: testapp.com
paths:
/downLoadFile/{fileId}:
get:
operationId: downLoadFile
parameters:
- name: fileId
in: path
schema:
type: string
required: true
responses:
'200':
description: A picture file
content:
image/png:
schema:
type: string
format: binary
/upLoadFile/{fileId}:
post:
operationId: upLoadFile
parameters:
- name: fileId
in: path
schema:
type: string
required: true
requestBody:
content:
image/png:
schema:
type: string
format: binary
responses:
'200':
description: success
/upLoadFileWithInfo/{fileId}:
post:
operationId: upLoadFileWithInfo
parameters:
- name: fileId
in: path
schema:
type: string
required: true
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
orderId:
type: integer
userId:
type: integer
fileName:
type: string
format: binary
responses:
'200':
description: success
cc:
@stkrwork @MartinDelille @muttleyxd @ravinikam