Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ QJsonValue {{prefix}}HttpFileElement::asJsonValue() const {
if (!result) {
qDebug() << "Error opening file " << local_filename;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
return QJsonDocument::fromJson(bArray.data()).object();
#else
return QJsonDocument::fromBinaryData(bArray.data()).object();
#endif
}

bool {{prefix}}HttpFileElement::fromStringValue(const QString &instr) {
Expand All @@ -86,11 +82,7 @@ bool {{prefix}}HttpFileElement::fromJsonValue(const QJsonValue &jval) {
file.remove();
}
result = file.open(QIODevice::WriteOnly);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
file.write(QJsonDocument(jval.toObject()).toJson());
#else
file.write(QJsonDocument(jval.toObject()).toBinaryData());
#endif
file.close();
if (!result) {
qDebug() << "Error creating file " << local_filename;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
#include <QUrl>
#include <QUuid>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts
#else
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts
#endif{{#contentCompression}}
{{#contentCompression}}
#include <zlib.h>{{/contentCompression}}

#include "{{prefix}}HttpRequest.h"
Expand Down Expand Up @@ -440,14 +436,14 @@ void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
}

if (!contentDispositionHdr.isEmpty()) {
auto contentDisposition = contentDispositionHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto contentDisposition = contentDispositionHdr.split(QString(";"), Qt::SkipEmptyParts);
auto contentType =
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS).first() : QString();
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts).first() : QString();
if ((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))) {
QString filename = QUuid::createUuid().toString();
for (const auto &file : contentDisposition) {
if (file.contains(QString("filename"))) {
filename = file.split(QString("="), SKIP_EMPTY_PARTS).at(1);
filename = file.split(QString("="), Qt::SkipEmptyParts).at(1);
break;
}
}
Expand All @@ -457,14 +453,14 @@ void {{prefix}}HttpRequestWorker::process_response(QNetworkReply *reply) {
}

} else if (!contentTypeHdr.isEmpty()) {
auto contentType = contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto contentType = contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts);
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
// TODO : Handle Multipart responses
} else {
if(!contentEncodingHdr.isEmpty()){
auto encoding = contentEncodingHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto encoding = contentEncodingHdr.split(QString(";"), Qt::SkipEmptyParts);
if(encoding.count() > 0){
auto compressionTypes = encoding.first().split(',', SKIP_EMPTY_PARTS);
auto compressionTypes = encoding.first().split(',', Qt::SkipEmptyParts);
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
response = decompress(reply->readAll());
} else if(compressionTypes.contains("identity", Qt::CaseInsensitive)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
#include <QObject>
#include <QString>
#include <QTimer>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif
#include <QRandomGenerator>

#include "{{prefix}}HttpFileElement.h"

Expand Down Expand Up @@ -89,9 +87,7 @@ private:
bool isResponseCompressionEnabled;
bool isRequestCompressionEnabled;
int httpResponseCode;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRandomGenerator randomGenerator;
#endif

void on_reply_timeout(QNetworkReply *reply);
void on_reply_finished(QNetworkReply *reply);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,9 @@ int {{classname}}::addServerConfiguration(const QString &operation, const QUrl &
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
*/
void {{classname}}::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, {{prefix}}ServerVariable> &variables) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
}
#else
for (auto &e : _serverIndices.keys()) {
setServerIndex(e, addServerConfiguration(e, url, description, variables));
}
#endif
}

/**
Expand Down Expand Up @@ -662,15 +656,9 @@ void {{classname}}::{{nickname}}({{#allParams}}{{#required}}const {{{dataType}}}
}
}
{{/cookieParams}}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &{{prefix}}HttpRequestWorker::on_execution_finished, this, &{{classname}}::{{nickname}}Callback);
connect(this, &{{classname}}::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down
8 changes: 0 additions & 8 deletions samples/client/petstore/cpp-qt/client/PFXHttpFileElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ QJsonValue PFXHttpFileElement::asJsonValue() const {
if (!result) {
qDebug() << "Error opening file " << local_filename;
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
return QJsonDocument::fromJson(bArray.data()).object();
#else
return QJsonDocument::fromBinaryData(bArray.data()).object();
#endif
}

bool PFXHttpFileElement::fromStringValue(const QString &instr) {
Expand All @@ -94,11 +90,7 @@ bool PFXHttpFileElement::fromJsonValue(const QJsonValue &jval) {
file.remove();
}
result = file.open(QIODevice::WriteOnly);
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
file.write(QJsonDocument(jval.toObject()).toJson());
#else
file.write(QJsonDocument(jval.toObject()).toBinaryData());
#endif
file.close();
if (!result) {
qDebug() << "Error creating file " << local_filename;
Expand Down
18 changes: 7 additions & 11 deletions samples/client/petstore/cpp-qt/client/PFXHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
#include <QUrl>
#include <QUuid>
#include <QtGlobal>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#define SKIP_EMPTY_PARTS Qt::SkipEmptyParts
#else
#define SKIP_EMPTY_PARTS QString::SkipEmptyParts
#endif


#include "PFXHttpRequest.h"

Expand Down Expand Up @@ -447,14 +443,14 @@ void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
}

if (!contentDispositionHdr.isEmpty()) {
auto contentDisposition = contentDispositionHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto contentDisposition = contentDispositionHdr.split(QString(";"), Qt::SkipEmptyParts);
auto contentType =
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS).first() : QString();
!contentTypeHdr.isEmpty() ? contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts).first() : QString();
if ((contentDisposition.count() > 0) && (contentDisposition.first() == QString("attachment"))) {
QString filename = QUuid::createUuid().toString();
for (const auto &file : contentDisposition) {
if (file.contains(QString("filename"))) {
filename = file.split(QString("="), SKIP_EMPTY_PARTS).at(1);
filename = file.split(QString("="), Qt::SkipEmptyParts).at(1);
break;
}
}
Expand All @@ -464,14 +460,14 @@ void PFXHttpRequestWorker::process_response(QNetworkReply *reply) {
}

} else if (!contentTypeHdr.isEmpty()) {
auto contentType = contentTypeHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto contentType = contentTypeHdr.split(QString(";"), Qt::SkipEmptyParts);
if ((contentType.count() > 0) && (contentType.first() == QString("multipart/form-data"))) {
// TODO : Handle Multipart responses
} else {
if(!contentEncodingHdr.isEmpty()){
auto encoding = contentEncodingHdr.split(QString(";"), SKIP_EMPTY_PARTS);
auto encoding = contentEncodingHdr.split(QString(";"), Qt::SkipEmptyParts);
if(encoding.count() > 0){
auto compressionTypes = encoding.first().split(',', SKIP_EMPTY_PARTS);
auto compressionTypes = encoding.first().split(',', Qt::SkipEmptyParts);
if(compressionTypes.contains("gzip", Qt::CaseInsensitive) || compressionTypes.contains("deflate", Qt::CaseInsensitive)){
response = decompress(reply->readAll());
} else if(compressionTypes.contains("identity", Qt::CaseInsensitive)){
Expand Down
6 changes: 1 addition & 5 deletions samples/client/petstore/cpp-qt/client/PFXHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
#include <QObject>
#include <QString>
#include <QTimer>
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
#include <QRandomGenerator>
#endif
#include <QRandomGenerator>

#include "PFXHttpFileElement.h"

Expand Down Expand Up @@ -97,9 +95,7 @@ class PFXHttpRequestWorker : public QObject {
bool isResponseCompressionEnabled;
bool isRequestCompressionEnabled;
int httpResponseCode;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRandomGenerator randomGenerator;
#endif

void on_reply_timeout(QNetworkReply *reply);
void on_reply_finished(QNetworkReply *reply);
Expand Down
60 changes: 0 additions & 60 deletions samples/client/petstore/cpp-qt/client/PFXPetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,9 @@ int PFXPetApi::addServerConfiguration(const QString &operation, const QUrl &url,
* @param variables A map between a variable name and its value. The value is used for substitution in the server's URL template.
*/
void PFXPetApi::setNewServerForAllOperations(const QUrl &url, const QString &description, const QMap<QString, PFXServerVariable> &variables) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 12, 0)
for (auto keyIt = _serverIndices.keyBegin(); keyIt != _serverIndices.keyEnd(); keyIt++) {
setServerIndex(*keyIt, addServerConfiguration(*keyIt, url, description, variables));
}
#else
for (auto &e : _serverIndices.keys()) {
setServerIndex(e, addServerConfiguration(e, url, description, variables));
}
#endif
}

/**
Expand Down Expand Up @@ -242,15 +236,9 @@ void PFXPetApi::addPet(const PFXPet &pfx_pet) {
QByteArray output = pfx_pet.asJson().toUtf8();
input.request_body.append(output);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::addPetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -356,15 +344,9 @@ void PFXPetApi::allPets() {
PFXHttpRequestInput input(fullPath, "GET");


#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::allPetsCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -460,15 +442,9 @@ void PFXPetApi::deletePet(const qint64 &pet_id, const ::test_namespace::Optional
input.headers.insert("api_key", ::test_namespace::toStringValue(api_key.value()));
}
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::deletePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -660,15 +636,9 @@ void PFXPetApi::findPetsByStatus(const QList<QString> &status) {
PFXHttpRequestInput input(fullPath, "GET");


#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByStatusCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -870,15 +840,9 @@ void PFXPetApi::findPetsByTags(const QList<QString> &tags) {
PFXHttpRequestInput input(fullPath, "GET");


#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::findPetsByTagsCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -1012,15 +976,9 @@ void PFXPetApi::getPetById(const qint64 &pet_id) {
PFXHttpRequestInput input(fullPath, "GET");


#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::getPetByIdCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -1092,15 +1050,9 @@ void PFXPetApi::updatePet(const PFXPet &pfx_pet) {
QByteArray output = pfx_pet.asJson().toUtf8();
input.request_body.append(output);
}
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -1228,15 +1180,9 @@ void PFXPetApi::updatePetWithForm(const qint64 &pet_id, const ::test_namespace::
input.add_var("status", ::test_namespace::toStringValue(status.value()));
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::updatePetWithFormCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down Expand Up @@ -1364,15 +1310,9 @@ void PFXPetApi::uploadFile(const qint64 &pet_id, const ::test_namespace::Optiona
input.add_file("file", file.value().local_filename, file.value().request_filename, file.value().mime_type);
}

#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
for (auto keyValueIt = _defaultHeaders.keyValueBegin(); keyValueIt != _defaultHeaders.keyValueEnd(); keyValueIt++) {
input.headers.insert(keyValueIt->first, keyValueIt->second);
}
#else
for (auto key : _defaultHeaders.keys()) {
input.headers.insert(key, _defaultHeaders[key]);
}
#endif

connect(worker, &PFXHttpRequestWorker::on_execution_finished, this, &PFXPetApi::uploadFileCallback);
connect(this, &PFXPetApi::abortRequestsSignal, worker, &QObject::deleteLater);
Expand Down
Loading