diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java index 5eb052d1a542..df98e9aa5520 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractCppCodegen.java @@ -300,12 +300,17 @@ public void preprocessOpenAPI(OpenAPI openAPI) { URL url = URLPathUtils.getServerURL(openAPI, serverVariableOverrides()); String port = URLPathUtils.getPort(url, ""); String host = url.getHost(); + String scheme = url.getProtocol(); + if(!port.isEmpty()) { this.additionalProperties.put("serverPort", port); } if(!host.isEmpty()) { this.additionalProperties.put("serverHost", host); } + if(!scheme.isEmpty()) { + this.additionalProperties.put("scheme", scheme); + } } @Override diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache index 9b5d5973b1a7..a4d19e34626f 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-body.mustache @@ -9,49 +9,55 @@ namespace {{this}} { {{/cppNamespaceDeclarations}} -{{classname}}::{{classname}}() : basePath("{{{basePathWithoutHost}}}"), - host("{{#serverHost}}{{#scheme}}{{scheme}}://{{/scheme}}{{serverHost}}{{#serverPort}}:{{serverPort}}{{/serverPort}}{{/serverHost}}"), - timeout(0){ - +{{classname}}::{{classname}}(const QString &scheme, const QString &host, int port, const QString& basePath, const int timeOut) : + _scheme(scheme), + _host(host), + _port(port), + _basePath(basePath), + _timeOut(timeOut) { } {{classname}}::~{{classname}}() { +} +void {{classname}}::setScheme(const QString& scheme){ + _scheme = scheme; } -{{classname}}::{{classname}}(const QString& host, const QString& basePath, const int tout) { - this->host = host; - this->basePath = basePath; - this->timeout = tout; +void {{classname}}::setHost(const QString& host){ + _host = host; } -void {{classname}}::setBasePath(const QString& basePath){ - this->basePath = basePath; +void {{classname}}::setPort(int port){ + _port = port; } -void {{classname}}::setHost(const QString& host){ - this->host = host; +void {{classname}}::setBasePath(const QString& basePath){ + _basePath = basePath; } -void {{classname}}::setApiTimeOutMs(const int tout){ - timeout = tout; +void {{classname}}::setTimeOut(const int timeOut){ + _timeOut = timeOut; } void {{classname}}::setWorkingDirectory(const QString& path){ - workingDirectory = path; + _workingDirectory = path; } void {{classname}}::addHeaders(const QString& key, const QString& value){ defaultHeaders.insert(key, value); } - {{#operations}} {{#operation}} void {{classname}}::{{nickname}}({{#allParams}}const {{{dataType}}}& {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("{{{path}}}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("{{{path}}}"); {{#pathParams}} QString {{paramName}}PathParam("{"); {{paramName}}PathParam.append("{{baseName}}").append("}"); @@ -107,8 +113,8 @@ void } {{/collectionFormat}}{{/queryParams}} {{prefix}}HttpRequestWorker *worker = new {{prefix}}HttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); {{prefix}}HttpRequestInput input(fullPath, "{{httpMethod}}"); {{#formParams}}{{^isFile}} input.add_var("{{baseName}}", ::{{cppNamespace}}::toStringValue({{paramName}}));{{/isFile}}{{#isFile}} diff --git a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache index aca810bfb78b..9595c57d903b 100644 --- a/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-qt5-client/api-header.mustache @@ -17,23 +17,23 @@ class {{classname}}: public QObject { Q_OBJECT public: - {{classname}}(); - {{classname}}(const QString& host, const QString& basePath, const int toutMs = 0); + {{classname}}(const QString &scheme = "{{scheme}}", const QString &host = "{{serverHost}}", int port = {{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}0{{/serverPort}}, const QString& basePath = "{{basePathWithoutHost}}", const int timeOut = 0); ~{{classname}}(); + void setScheme(const QString &scheme); + void setHost(const QString &host); + void setPort(int port); void setBasePath(const QString& basePath); - void setHost(const QString& host); - void setApiTimeOutMs(const int tout); + void setTimeOut(const int timeOut); void setWorkingDirectory(const QString& path); void addHeaders(const QString& key, const QString& value); {{#operations}}{{#operation}}void {{nickname}}({{#allParams}}const {{{dataType}}}& {{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}); {{/operation}}{{/operations}} private: - QString basePath; - QString host; - QString workingDirectory; - int timeout; + QString _scheme, _host, _basePath; + int _port, _timeOut; + QString _workingDirectory; QMap defaultHeaders; {{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker); {{/operation}}{{/operations}} diff --git a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp index 38cf77fd20cf..da684cfc7f59 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp @@ -14,7 +14,6 @@ PFXPet PetApiTests::createRandomPet() { void PetApiTests::findPetsByStatusTest() { PFXPetApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool petFound = false; @@ -34,7 +33,6 @@ void PetApiTests::findPetsByStatusTest() { void PetApiTests::createAndGetPetTest() { PFXPetApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool petCreated = false; @@ -65,12 +63,10 @@ void PetApiTests::createAndGetPetTest() { QTimer::singleShot(14000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY2(petFetched, "didn't finish within timeout"); - } void PetApiTests::updatePetTest() { PFXPetApi api; - api.setHost(PetStoreHost); PFXPet pet = createRandomPet(); PFXPet petToCheck; @@ -134,7 +130,6 @@ void PetApiTests::updatePetTest() { void PetApiTests::updatePetWithFormTest() { PFXPetApi api; - api.setHost(PetStoreHost); PFXPet pet = createRandomPet(); PFXPet petToCheck; diff --git a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.h b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.h index 1046bb664e59..ec126905cf53 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.h +++ b/samples/client/petstore/cpp-qt5/PetStore/PetApiTests.h @@ -14,6 +14,4 @@ private slots: void createAndGetPetTest(); void updatePetTest(); void updatePetWithFormTest(); -private: - const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io"); }; diff --git a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp index 24ed8e662709..282d40cac10e 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp @@ -6,7 +6,6 @@ void StoreApiTests::placeOrderTest() { PFXStoreApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool orderPlaced = false; @@ -33,12 +32,10 @@ void StoreApiTests::placeOrderTest() { QTimer::singleShot(14000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY2(orderPlaced, "didn't finish within timeout"); - } void StoreApiTests::getOrderByIdTest() { PFXStoreApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool orderFetched = false; @@ -54,12 +51,10 @@ void StoreApiTests::getOrderByIdTest() { QTimer::singleShot(14000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY2(orderFetched, "didn't finish within timeout"); - } void StoreApiTests::getInventoryTest() { PFXStoreApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool inventoryFetched = false; @@ -75,5 +70,4 @@ void StoreApiTests::getInventoryTest() { QTimer::singleShot(14000, &loop, &QEventLoop::quit); loop.exec(); QVERIFY2(inventoryFetched, "didn't finish within timeout"); - } diff --git a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.h b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.h index cff9defa249d..440bf181c54a 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.h +++ b/samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.h @@ -11,6 +11,4 @@ private slots: void placeOrderTest(); void getOrderByIdTest(); void getInventoryTest(); -private: - const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io"); }; diff --git a/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp b/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp index d2196a0deb6b..c047724372a9 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp +++ b/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp @@ -19,7 +19,6 @@ PFXUser UserApiTests::createRandomUser() { void UserApiTests::createUserTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userCreated = false; @@ -36,7 +35,6 @@ void UserApiTests::createUserTest(){ void UserApiTests::createUsersWithArrayInputTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool usersCreated = false; @@ -57,7 +55,6 @@ void UserApiTests::createUsersWithArrayInputTest(){ void UserApiTests::createUsersWithListInputTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool usersCreated = false; @@ -82,7 +79,6 @@ void UserApiTests::createUsersWithListInputTest(){ void UserApiTests::deleteUserTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userDeleted = false; @@ -99,7 +95,6 @@ void UserApiTests::deleteUserTest(){ void UserApiTests::getUserByNameTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userFetched = false; @@ -118,7 +113,6 @@ void UserApiTests::getUserByNameTest(){ void UserApiTests::loginUserTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userLogged = false; @@ -136,7 +130,6 @@ void UserApiTests::loginUserTest(){ void UserApiTests::logoutUserTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userLoggedOut = false; @@ -153,7 +146,6 @@ void UserApiTests::logoutUserTest(){ void UserApiTests::updateUserTest(){ PFXUserApi api; - api.setHost(PetStoreHost); QEventLoop loop; bool userUpdated = false; diff --git a/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h b/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h index c866512d0660..3cfd25bd8fe2 100644 --- a/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h +++ b/samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h @@ -18,6 +18,4 @@ private slots: void loginUserTest(); void logoutUserTest(); void updateUserTest(); -private: - const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io"); }; diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp index 616cd2f81aa3..0c03c3cd31c1 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.cpp @@ -18,51 +18,57 @@ namespace test_namespace { -PFXPetApi::PFXPetApi() : basePath("/v2"), - host("petstore.swagger.io"), - timeout(0){ - +PFXPetApi::PFXPetApi(const QString &scheme, const QString &host, int port, const QString& basePath, const int timeOut) : + _scheme(scheme), + _host(host), + _port(port), + _basePath(basePath), + _timeOut(timeOut) { } PFXPetApi::~PFXPetApi() { +} +void PFXPetApi::setScheme(const QString& scheme){ + _scheme = scheme; } -PFXPetApi::PFXPetApi(const QString& host, const QString& basePath, const int tout) { - this->host = host; - this->basePath = basePath; - this->timeout = tout; +void PFXPetApi::setHost(const QString& host){ + _host = host; } -void PFXPetApi::setBasePath(const QString& basePath){ - this->basePath = basePath; +void PFXPetApi::setPort(int port){ + _port = port; } -void PFXPetApi::setHost(const QString& host){ - this->host = host; +void PFXPetApi::setBasePath(const QString& basePath){ + _basePath = basePath; } -void PFXPetApi::setApiTimeOutMs(const int tout){ - timeout = tout; +void PFXPetApi::setTimeOut(const int timeOut){ + _timeOut = timeOut; } void PFXPetApi::setWorkingDirectory(const QString& path){ - workingDirectory = path; + _workingDirectory = path; } void PFXPetApi::addHeaders(const QString& key, const QString& value){ defaultHeaders.insert(key, value); } - void PFXPetApi::addPet(const PFXPet& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); @@ -107,15 +113,19 @@ PFXPetApi::addPetCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::deletePet(const qint64& pet_id, const QString& api_key) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/{petId}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "DELETE"); @@ -160,8 +170,12 @@ PFXPetApi::deletePetCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::findPetsByStatus(const QList& status) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/findByStatus"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/findByStatus"); if (status.size() > 0) { if (QString("csv").indexOf("multi") == 0) { @@ -204,8 +218,8 @@ PFXPetApi::findPetsByStatus(const QList& status) { } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -257,8 +271,12 @@ PFXPetApi::findPetsByStatusCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::findPetsByTags(const QList& tags) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/findByTags"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/findByTags"); if (tags.size() > 0) { if (QString("csv").indexOf("multi") == 0) { @@ -301,8 +319,8 @@ PFXPetApi::findPetsByTags(const QList& tags) { } PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -354,15 +372,19 @@ PFXPetApi::findPetsByTagsCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::getPetById(const qint64& pet_id) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/{petId}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -405,12 +427,16 @@ PFXPetApi::getPetByIdCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::updatePet(const PFXPet& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "PUT"); @@ -455,15 +481,19 @@ PFXPetApi::updatePetCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::updatePetWithForm(const qint64& pet_id, const QString& name, const QString& status) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/{petId}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/{petId}"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); input.add_var("name", ::test_namespace::toStringValue(name)); @@ -507,15 +537,19 @@ PFXPetApi::updatePetWithFormCallback(PFXHttpRequestWorker * worker) { void PFXPetApi::uploadFile(const qint64& pet_id, const QString& additional_metadata, const PFXHttpFileElement& file) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/pet/{petId}/uploadImage"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/pet/{petId}/uploadImage"); QString pet_idPathParam("{"); pet_idPathParam.append("petId").append("}"); fullPath.replace(pet_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(pet_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); input.add_var("additionalMetadata", ::test_namespace::toStringValue(additional_metadata)); diff --git a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h index b7089a07ec89..67fc74d25a0a 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXPetApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXPetApi.h @@ -28,13 +28,14 @@ class PFXPetApi: public QObject { Q_OBJECT public: - PFXPetApi(); - PFXPetApi(const QString& host, const QString& basePath, const int toutMs = 0); + PFXPetApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString& basePath = "/v2", const int timeOut = 0); ~PFXPetApi(); + void setScheme(const QString &scheme); + void setHost(const QString &host); + void setPort(int port); void setBasePath(const QString& basePath); - void setHost(const QString& host); - void setApiTimeOutMs(const int tout); + void setTimeOut(const int timeOut); void setWorkingDirectory(const QString& path); void addHeaders(const QString& key, const QString& value); @@ -48,10 +49,9 @@ class PFXPetApi: public QObject { void uploadFile(const qint64& pet_id, const QString& additional_metadata, const PFXHttpFileElement& file); private: - QString basePath; - QString host; - QString workingDirectory; - int timeout; + QString _scheme, _host, _basePath; + int _port, _timeOut; + QString _workingDirectory; QMap defaultHeaders; void addPetCallback (PFXHttpRequestWorker * worker); void deletePetCallback (PFXHttpRequestWorker * worker); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp index 814a60221ba6..df62ceb15b1b 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.cpp @@ -18,54 +18,60 @@ namespace test_namespace { -PFXStoreApi::PFXStoreApi() : basePath("/v2"), - host("petstore.swagger.io"), - timeout(0){ - +PFXStoreApi::PFXStoreApi(const QString &scheme, const QString &host, int port, const QString& basePath, const int timeOut) : + _scheme(scheme), + _host(host), + _port(port), + _basePath(basePath), + _timeOut(timeOut) { } PFXStoreApi::~PFXStoreApi() { +} +void PFXStoreApi::setScheme(const QString& scheme){ + _scheme = scheme; } -PFXStoreApi::PFXStoreApi(const QString& host, const QString& basePath, const int tout) { - this->host = host; - this->basePath = basePath; - this->timeout = tout; +void PFXStoreApi::setHost(const QString& host){ + _host = host; } -void PFXStoreApi::setBasePath(const QString& basePath){ - this->basePath = basePath; +void PFXStoreApi::setPort(int port){ + _port = port; } -void PFXStoreApi::setHost(const QString& host){ - this->host = host; +void PFXStoreApi::setBasePath(const QString& basePath){ + _basePath = basePath; } -void PFXStoreApi::setApiTimeOutMs(const int tout){ - timeout = tout; +void PFXStoreApi::setTimeOut(const int timeOut){ + _timeOut = timeOut; } void PFXStoreApi::setWorkingDirectory(const QString& path){ - workingDirectory = path; + _workingDirectory = path; } void PFXStoreApi::addHeaders(const QString& key, const QString& value){ defaultHeaders.insert(key, value); } - void PFXStoreApi::deleteOrder(const QString& order_id) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/store/order/{orderId}"); QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "DELETE"); @@ -107,12 +113,16 @@ PFXStoreApi::deleteOrderCallback(PFXHttpRequestWorker * worker) { void PFXStoreApi::getInventory() { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/store/inventory"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/store/inventory"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -164,15 +174,19 @@ PFXStoreApi::getInventoryCallback(PFXHttpRequestWorker * worker) { void PFXStoreApi::getOrderById(const qint64& order_id) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/store/order/{orderId}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/store/order/{orderId}"); QString order_idPathParam("{"); order_idPathParam.append("orderId").append("}"); fullPath.replace(order_idPathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(order_id))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -215,12 +229,16 @@ PFXStoreApi::getOrderByIdCallback(PFXHttpRequestWorker * worker) { void PFXStoreApi::placeOrder(const PFXOrder& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/store/order"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/store/order"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); diff --git a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h index fd48165e5a48..d292d819467d 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXStoreApi.h @@ -27,13 +27,14 @@ class PFXStoreApi: public QObject { Q_OBJECT public: - PFXStoreApi(); - PFXStoreApi(const QString& host, const QString& basePath, const int toutMs = 0); + PFXStoreApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString& basePath = "/v2", const int timeOut = 0); ~PFXStoreApi(); + void setScheme(const QString &scheme); + void setHost(const QString &host); + void setPort(int port); void setBasePath(const QString& basePath); - void setHost(const QString& host); - void setApiTimeOutMs(const int tout); + void setTimeOut(const int timeOut); void setWorkingDirectory(const QString& path); void addHeaders(const QString& key, const QString& value); @@ -43,10 +44,9 @@ class PFXStoreApi: public QObject { void placeOrder(const PFXOrder& body); private: - QString basePath; - QString host; - QString workingDirectory; - int timeout; + QString _scheme, _host, _basePath; + int _port, _timeOut; + QString _workingDirectory; QMap defaultHeaders; void deleteOrderCallback (PFXHttpRequestWorker * worker); void getInventoryCallback (PFXHttpRequestWorker * worker); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp index b47e5a16d380..07c5edb9b907 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.cpp @@ -18,51 +18,57 @@ namespace test_namespace { -PFXUserApi::PFXUserApi() : basePath("/v2"), - host("petstore.swagger.io"), - timeout(0){ - +PFXUserApi::PFXUserApi(const QString &scheme, const QString &host, int port, const QString& basePath, const int timeOut) : + _scheme(scheme), + _host(host), + _port(port), + _basePath(basePath), + _timeOut(timeOut) { } PFXUserApi::~PFXUserApi() { +} +void PFXUserApi::setScheme(const QString& scheme){ + _scheme = scheme; } -PFXUserApi::PFXUserApi(const QString& host, const QString& basePath, const int tout) { - this->host = host; - this->basePath = basePath; - this->timeout = tout; +void PFXUserApi::setHost(const QString& host){ + _host = host; } -void PFXUserApi::setBasePath(const QString& basePath){ - this->basePath = basePath; +void PFXUserApi::setPort(int port){ + _port = port; } -void PFXUserApi::setHost(const QString& host){ - this->host = host; +void PFXUserApi::setBasePath(const QString& basePath){ + _basePath = basePath; } -void PFXUserApi::setApiTimeOutMs(const int tout){ - timeout = tout; +void PFXUserApi::setTimeOut(const int timeOut){ + _timeOut = timeOut; } void PFXUserApi::setWorkingDirectory(const QString& path){ - workingDirectory = path; + _workingDirectory = path; } void PFXUserApi::addHeaders(const QString& key, const QString& value){ defaultHeaders.insert(key, value); } - void PFXUserApi::createUser(const PFXUser& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); @@ -107,12 +113,16 @@ PFXUserApi::createUserCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::createUsersWithArrayInput(const QList& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/createWithArray"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/createWithArray"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); @@ -158,12 +168,16 @@ PFXUserApi::createUsersWithArrayInputCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::createUsersWithListInput(const QList& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/createWithList"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/createWithList"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "POST"); @@ -209,15 +223,19 @@ PFXUserApi::createUsersWithListInputCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::deleteUser(const QString& username) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/{username}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "DELETE"); @@ -259,15 +277,19 @@ PFXUserApi::deleteUserCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::getUserByName(const QString& username) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/{username}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -310,8 +332,12 @@ PFXUserApi::getUserByNameCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::loginUser(const QString& username, const QString& password) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/login"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/login"); if (fullPath.indexOf("?") > 0) fullPath.append("&"); @@ -330,8 +356,8 @@ PFXUserApi::loginUser(const QString& username, const QString& password) { .append(QUrl::toPercentEncoding(::test_namespace::toStringValue(password))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -375,12 +401,16 @@ PFXUserApi::loginUserCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::logoutUser() { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/logout"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/logout"); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "GET"); @@ -422,15 +452,19 @@ PFXUserApi::logoutUserCallback(PFXHttpRequestWorker * worker) { void PFXUserApi::updateUser(const QString& username, const PFXUser& body) { - QString fullPath; - fullPath.append(this->host).append(this->basePath).append("/user/{username}"); + QString fullPath = QString("%0://%1%2%3%4") + .arg(_scheme) + .arg(_host) + .arg(_port ? ":" + QString::number(_port) : "") + .arg(_basePath) + .arg("/user/{username}"); QString usernamePathParam("{"); usernamePathParam.append("username").append("}"); fullPath.replace(usernamePathParam, QUrl::toPercentEncoding(::test_namespace::toStringValue(username))); PFXHttpRequestWorker *worker = new PFXHttpRequestWorker(this); - worker->setTimeOut(timeout); - worker->setWorkingDirectory(workingDirectory); + worker->setTimeOut(_timeOut); + worker->setWorkingDirectory(_workingDirectory); PFXHttpRequestInput input(fullPath, "PUT"); diff --git a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h index b736ab22fc2e..afb098152c73 100644 --- a/samples/client/petstore/cpp-qt5/client/PFXUserApi.h +++ b/samples/client/petstore/cpp-qt5/client/PFXUserApi.h @@ -27,13 +27,14 @@ class PFXUserApi: public QObject { Q_OBJECT public: - PFXUserApi(); - PFXUserApi(const QString& host, const QString& basePath, const int toutMs = 0); + PFXUserApi(const QString &scheme = "http", const QString &host = "petstore.swagger.io", int port = 0, const QString& basePath = "/v2", const int timeOut = 0); ~PFXUserApi(); + void setScheme(const QString &scheme); + void setHost(const QString &host); + void setPort(int port); void setBasePath(const QString& basePath); - void setHost(const QString& host); - void setApiTimeOutMs(const int tout); + void setTimeOut(const int timeOut); void setWorkingDirectory(const QString& path); void addHeaders(const QString& key, const QString& value); @@ -47,10 +48,9 @@ class PFXUserApi: public QObject { void updateUser(const QString& username, const PFXUser& body); private: - QString basePath; - QString host; - QString workingDirectory; - int timeout; + QString _scheme, _host, _basePath; + int _port, _timeOut; + QString _workingDirectory; QMap defaultHeaders; void createUserCallback (PFXHttpRequestWorker * worker); void createUsersWithArrayInputCallback (PFXHttpRequestWorker * worker);