Skip to content
New issue

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

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

Already on GitHub? # to your account

[C++] [Qt5] Set default base path and change constructor to const ref #2973

Merged
merged 1 commit into from
May 26, 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.
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 @@ -19,17 +19,21 @@

import com.google.common.collect.ImmutableMap;
import com.samskivert.mustache.Mustache;

import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.media.Schema;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.CodegenConfig;
import org.openapitools.codegen.CodegenProperty;
import org.openapitools.codegen.DefaultCodegen;
import org.openapitools.codegen.templating.mustache.IndentedLambda;
import org.openapitools.codegen.utils.URLPathUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.net.URL;
import java.util.Arrays;
import java.util.Map;

Expand Down Expand Up @@ -300,4 +304,17 @@ public void postProcessFile(File file, String fileType) {
}
}
}

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
URL url = URLPathUtils.getServerURL(openAPI);
String port = URLPathUtils.getPort(url, "");
String host = url.getHost();
if(!port.isEmpty()) {
this.additionalProperties.put("serverPort", port);
}
if(!host.isEmpty()) {
this.additionalProperties.put("serverHost", host);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -404,14 +404,7 @@ public String getSchemaType(Schema p) {
public String getTypeDeclaration(String str) {
return toModelName(str);
}

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
URL url = URLPathUtils.getServerURL(openAPI);
String port = URLPathUtils.getPort(url, "8080");
this.additionalProperties.put("serverPort", port);
}


/**
* Specify whether external libraries will be added during the generation
* @param value the value to be set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,6 @@ public String apiFilename(String templateName, String tag) {
return result;
}

@Override
public void preprocessOpenAPI(OpenAPI openAPI) {
URL url = URLPathUtils.getServerURL(openAPI);
String port = URLPathUtils.getPort(url, "8080");
this.additionalProperties.put("serverPort", port);
}

@Override
public String toApiFilename(String name) {
return modelNamePrefix + sanitizeName(camelize(name)) + "ApiHandler";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ int main() {
std::vector<int> sigs{SIGQUIT, SIGINT, SIGTERM, SIGHUP};
setUpUnixSignals(sigs);
#endif
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port({{serverPort}}));
Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port({{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}));

httpEndpoint = new Pistache::Http::Endpoint((addr));
auto router = std::make_shared<Pistache::Rest::Router>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,33 @@
namespace {{this}} {
{{/cppNamespaceDeclarations}}

{{classname}}::{{classname}}() {
{{classname}}::{{classname}}() : basePath("{{{basePathWithoutHost}}}"),
host("{{#serverHost}}{{#scheme}}{{scheme}}://{{/scheme}}{{serverHost}}{{#serverPort}}:{{serverPort}}{{/serverPort}}{{/serverHost}}") {

}

{{classname}}::~{{classname}}() {

}

{{classname}}::{{classname}}(QString host, QString basePath) {
{{classname}}::{{classname}}(const QString& host, const QString& basePath) {
this->host = host;
this->basePath = basePath;
}

void {{classname}}::setBasePath(const QString& basePath){
this->basePath = basePath;
}

void {{classname}}::setHost(const QString& host){
this->host = host;
}

void {{classname}}::addHeaders(const QString& key, const QString& value){
defaultHeaders.insert(key, value);
}


{{#operations}}
{{#operation}}
void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ class {{classname}}: public QObject {

public:
{{classname}}();
{{classname}}(QString host, QString basePath);
{{classname}}(const QString& host, const QString& basePath);
~{{classname}}();

QString host;
QString basePath;
QMap<QString, QString> defaultHeaders;

void setBasePath(const QString& basePath);
void setHost(const QString& host);
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;
QMap<QString, QString> defaultHeaders;
{{#operations}}{{#operation}}void {{nickname}}Callback ({{prefix}}HttpRequestWorker * worker);
{{/operation}}{{/operations}}
signals:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int main(int argc, char * argv[])
QStringList() << "p" << "port",
"port to listen on",
"port",
"{{serverPort}}"
"{{#serverPort}}{{serverPort}}{{/serverPort}}{{^serverPort}}8080{{/serverPort}}"
);
parser.addOption(portOption);
parser.addHelpOption();
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.0.1-SNAPSHOT
4.0.1-SNAPSHOT
3 changes: 1 addition & 2 deletions samples/client/petstore/cpp-qt5/PetStore/PetApiTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ PetApiTests::~PetApiTests () {

OAIPetApi* PetApiTests::getApi() {
auto api = new OAIPetApi();
api->host = "http://petstore.swagger.io";
api->basePath = "/v2";
api->setHost("http://petstore.swagger.io");
return api;
}

Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/cpp-qt5/PetStore/StoreApiTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ StoreApiTests::~StoreApiTests () {

OAIStoreApi* StoreApiTests::getApi() {
auto api = new OAIStoreApi();
api->host = "http://petstore.swagger.io";
api->basePath = "/v2";
api->setHost("http://petstore.swagger.io");
return api;
}

Expand Down Expand Up @@ -43,6 +42,7 @@ void StoreApiTests::placeOrderTest() {
};
connect(this, &StoreApiTests::quit, finalizer);
connect(api, &OAIStoreApi::placeOrderSignal, this, validator);
connect(api, &OAIStoreApi::placeOrderSignalE, this, finalizer);
connect(&timer, &QTimer::timeout, &loop, finalizer);

OAIOrder order;
Expand Down
3 changes: 1 addition & 2 deletions samples/client/petstore/cpp-qt5/PetStore/UserApiTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ UserApiTests::~UserApiTests () {

OAIUserApi* UserApiTests::getApi() {
auto api = new OAIUserApi();
api->host = "http://petstore.swagger.io";
api->basePath = "/v2";
api->setHost("http://petstore.swagger.io");
return api;
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIApiResponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIApiResponse.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAICategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAICategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIHttpRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIHttpRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIOrder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIOrder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIPet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-qt5/client/OAIPet.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand Down
22 changes: 18 additions & 4 deletions samples/client/petstore/cpp-qt5/client/OAIPetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Expand All @@ -18,19 +18,33 @@

namespace OpenAPI {

OAIPetApi::OAIPetApi() {
OAIPetApi::OAIPetApi() : basePath("/v2"),
host("petstore.swagger.io") {

}

OAIPetApi::~OAIPetApi() {

}

OAIPetApi::OAIPetApi(QString host, QString basePath) {
OAIPetApi::OAIPetApi(const QString& host, const QString& basePath) {
this->host = host;
this->basePath = basePath;
}

void OAIPetApi::setBasePath(const QString& basePath){
this->basePath = basePath;
}

void OAIPetApi::setHost(const QString& host){
this->host = host;
}

void OAIPetApi::addHeaders(const QString& key, const QString& value){
defaultHeaders.insert(key, value);
}


void
OAIPetApi::addPet(const OAIPet& body) {
QString fullPath;
Expand Down Expand Up @@ -91,7 +105,7 @@ OAIPetApi::deletePet(const qint64& pet_id, const QString& api_key) {
OAIHttpRequestInput input(fullPath, "DELETE");

if (api_key != nullptr) {
input.headers.insert("api_key", "api_key");
input.headers.insert("api_key", api_key);
}

foreach(QString key, this->defaultHeaders.keys()) {
Expand Down
Loading