Skip to content
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

cpp-qt5-client: remove host since it is not well handled #4429

Merged
merged 5 commits into from Nov 12, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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
Expand Down
Expand Up @@ -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("}");
Expand Down Expand Up @@ -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}}
Expand Down
Expand Up @@ -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<QString, QString> defaultHeaders;
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);
{{/operation}}{{/operations}}
Expand Down
5 changes: 0 additions & 5 deletions samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp
Expand Up @@ -14,7 +14,6 @@ PFXPet PetApiTests::createRandomPet() {

void PetApiTests::findPetsByStatusTest() {
PFXPetApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool petFound = false;

Expand All @@ -34,7 +33,6 @@ void PetApiTests::findPetsByStatusTest() {

void PetApiTests::createAndGetPetTest() {
PFXPetApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool petCreated = false;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -134,7 +130,6 @@ void PetApiTests::updatePetTest() {

void PetApiTests::updatePetWithFormTest() {
PFXPetApi api;
api.setHost(PetStoreHost);

PFXPet pet = createRandomPet();
PFXPet petToCheck;
Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/cpp-qt5/PetStore/PetApiTests.h
Expand Up @@ -14,6 +14,4 @@ private slots:
void createAndGetPetTest();
void updatePetTest();
void updatePetWithFormTest();
private:
const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io");
};
6 changes: 0 additions & 6 deletions samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp
Expand Up @@ -6,7 +6,6 @@

void StoreApiTests::placeOrderTest() {
PFXStoreApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool orderPlaced = false;

Expand All @@ -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;

Expand All @@ -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;

Expand All @@ -75,5 +70,4 @@ void StoreApiTests::getInventoryTest() {
QTimer::singleShot(14000, &loop, &QEventLoop::quit);
loop.exec();
QVERIFY2(inventoryFetched, "didn't finish within timeout");

}
2 changes: 0 additions & 2 deletions samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.h
Expand Up @@ -11,6 +11,4 @@ private slots:
void placeOrderTest();
void getOrderByIdTest();
void getInventoryTest();
private:
const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io");
};
8 changes: 0 additions & 8 deletions samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp
Expand Up @@ -19,7 +19,6 @@ PFXUser UserApiTests::createRandomUser() {

void UserApiTests::createUserTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userCreated = false;

Expand All @@ -36,7 +35,6 @@ void UserApiTests::createUserTest(){

void UserApiTests::createUsersWithArrayInputTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool usersCreated = false;

Expand All @@ -57,7 +55,6 @@ void UserApiTests::createUsersWithArrayInputTest(){

void UserApiTests::createUsersWithListInputTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool usersCreated = false;

Expand All @@ -82,7 +79,6 @@ void UserApiTests::createUsersWithListInputTest(){

void UserApiTests::deleteUserTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userDeleted = false;

Expand All @@ -99,7 +95,6 @@ void UserApiTests::deleteUserTest(){

void UserApiTests::getUserByNameTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userFetched = false;

Expand All @@ -118,7 +113,6 @@ void UserApiTests::getUserByNameTest(){

void UserApiTests::loginUserTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userLogged = false;

Expand All @@ -136,7 +130,6 @@ void UserApiTests::loginUserTest(){

void UserApiTests::logoutUserTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userLoggedOut = false;

Expand All @@ -153,7 +146,6 @@ void UserApiTests::logoutUserTest(){

void UserApiTests::updateUserTest(){
PFXUserApi api;
api.setHost(PetStoreHost);
QEventLoop loop;
bool userUpdated = false;

Expand Down
2 changes: 0 additions & 2 deletions samples/client/petstore/cpp-qt5/PetStore/UserApiTests.h
Expand Up @@ -18,6 +18,4 @@ private slots:
void loginUserTest();
void logoutUserTest();
void updateUserTest();
private:
const QString PetStoreHost = QStringLiteral("http://petstore.swagger.io");
};