diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java index 460def58afc..4ab177e21a3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppPistacheServerCodegen.java @@ -290,14 +290,14 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen { //TODO: This changes the info about the real type but it is needed to parse the header params if (param.isHeaderParam) { - param.dataType = "Pistache::Optional"; - param.baseType = "Pistache::Optional"; + param.dataType = "std::optional"; + param.baseType = "std::optional"; } else if (param.isQueryParam) { if (param.isPrimitiveType) { - param.dataType = "Pistache::Optional<" + param.dataType + ">"; + param.dataType = "std::optional<" + param.dataType + ">"; } else { - param.dataType = "Pistache::Optional<" + param.dataType + ">"; - param.baseType = "Pistache::Optional<" + param.baseType + ">"; + param.dataType = "std::optional<" + param.dataType + ">"; + param.baseType = "std::optional<" + param.baseType + ">"; } } } diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache index e386ffb74c5..1cbfb6fa6af 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-header.mustache @@ -12,8 +12,8 @@ #include #include #include -#include {{^hasModelImport}}#include {{/hasModelImport}} +#include #include {{#imports}}{{{import}}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache index bd20c1bdf5a..7a2a604bf31 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-impl-header.mustache @@ -14,10 +14,10 @@ #include #include #include +#include #include <{{classname}}.h> -#include {{#imports}}{{{import}}} {{/imports}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache index 7418caa9cdd..6bf2d10eb01 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/api-source.mustache @@ -74,11 +74,11 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque // Getting the query params {{#queryParams}} auto {{paramName}}Query = request.query().get("{{baseName}}"); - Pistache::Optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}}; - if(!{{paramName}}Query.isEmpty()){ + std::optional<{{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}}> {{paramName}}; + if({{paramName}}Query.has_value()){ {{^isContainer}}{{dataType}}{{/isContainer}}{{#isArray}}std::vector<{{items.baseType}}>{{/isArray}} valueQuery_instance; - if(fromStringValue({{paramName}}Query.get(), valueQuery_instance)){ - {{paramName}} = Pistache::Some(valueQuery_instance); + if(fromStringValue({{paramName}}Query.value(), valueQuery_instance)){ + {{paramName}} = valueQuery_instance; } } {{/queryParams}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache index 8fc1b19b7e7..992e26fae4e 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/cmake.mustache @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.2) project(api-server) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" ) {{#addExternalLibs}} include(ExternalProject) @@ -10,15 +10,16 @@ include(ExternalProject) set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external) ExternalProject_Add(PISTACHE - GIT_REPOSITORY https://github.com/oktal/pistache.git - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} + GIT_REPOSITORY https://github.com/pistacheio/pistache.git + BUILD_IN_SOURCE true + INSTALL_COMMAND meson setup build --prefix=${EXTERNAL_INSTALL_LOCATION} --libdir=lib && meson install -C build ) ExternalProject_Add(NLOHMANN GIT_REPOSITORY https://github.com/nlohmann/json.git - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} - + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DJSON_BuildTests=OFF ) + include_directories(${EXTERNAL_INSTALL_LOCATION}/include) link_directories(${EXTERNAL_INSTALL_LOCATION}/lib) {{/addExternalLibs}} diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-header.mustache index be0ea874da8..8c152b757a0 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-header.mustache @@ -12,7 +12,7 @@ {{#imports}}{{{this}}} {{/imports}} #include -{{#hasOptional}}#include {{/hasOptional}} +{{#hasOptional}}#include {{/hasOptional}} namespace {{modelNamespace}} { @@ -20,7 +20,7 @@ namespace {{modelNamespace}} struct {{classname}} { {{#vars}} - {{^required}}Pistache::Optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{name}}; + {{^required}}std::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{name}}; {{/vars}} bool operator==(const {{classname}}& other) const; diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-source.mustache index 987926b7c4e..f1a0c0fee31 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-struct-source.mustache @@ -45,7 +45,7 @@ void from_json(const nlohmann::json& j, {{classname}}& o) {{^required}}if (j.find("{{baseName}}") != j.end()) { {{{dataType}}} temporary_{{name}}; j.at("{{baseName}}").get_to(temporary_{{name}}); - o.{{name}} = Pistache::Some(temporary_{{name}}); + o.{{name}} = temporary_{{name}}; }{{/required}} {{/vars}} } diff --git a/samples/server/petstore/cpp-pistache/CMakeLists.txt b/samples/server/petstore/cpp-pistache/CMakeLists.txt index 992a04bf681..23269deb0ff 100644 --- a/samples/server/petstore/cpp-pistache/CMakeLists.txt +++ b/samples/server/petstore/cpp-pistache/CMakeLists.txt @@ -2,22 +2,23 @@ cmake_minimum_required (VERSION 3.2) project(api-server) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -pg -g3" ) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pg -g3" ) include(ExternalProject) set(EXTERNAL_INSTALL_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/external) ExternalProject_Add(PISTACHE - GIT_REPOSITORY https://github.com/oktal/pistache.git - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} + GIT_REPOSITORY https://github.com/pistacheio/pistache.git + BUILD_IN_SOURCE true + INSTALL_COMMAND meson setup build --prefix=${EXTERNAL_INSTALL_LOCATION} --libdir=lib && meson install -C build ) ExternalProject_Add(NLOHMANN GIT_REPOSITORY https://github.com/nlohmann/json.git - CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} - + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_LOCATION} -DJSON_BuildTests=OFF ) + include_directories(${EXTERNAL_INSTALL_LOCATION}/include) link_directories(${EXTERNAL_INSTALL_LOCATION}/lib) diff --git a/samples/server/petstore/cpp-pistache/api/PetApi.cpp b/samples/server/petstore/cpp-pistache/api/PetApi.cpp index c3b19e937b7..6d9e331804c 100644 --- a/samples/server/petstore/cpp-pistache/api/PetApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/PetApi.cpp @@ -128,11 +128,11 @@ void PetApi::find_pets_by_status_handler(const Pistache::Rest::Request &request, // Getting the query params auto statusQuery = request.query().get("status"); - Pistache::Optional> status; - if(!statusQuery.isEmpty()){ + std::optional> status; + if(statusQuery.has_value()){ std::vector valueQuery_instance; - if(fromStringValue(statusQuery.get(), valueQuery_instance)){ - status = Pistache::Some(valueQuery_instance); + if(fromStringValue(statusQuery.value(), valueQuery_instance)){ + status = valueQuery_instance; } } @@ -158,11 +158,11 @@ void PetApi::find_pets_by_tags_handler(const Pistache::Rest::Request &request, P // Getting the query params auto tagsQuery = request.query().get("tags"); - Pistache::Optional> tags; - if(!tagsQuery.isEmpty()){ + std::optional> tags; + if(tagsQuery.has_value()){ std::vector valueQuery_instance; - if(fromStringValue(tagsQuery.get(), valueQuery_instance)){ - tags = Pistache::Some(valueQuery_instance); + if(fromStringValue(tagsQuery.value(), valueQuery_instance)){ + tags = valueQuery_instance; } } diff --git a/samples/server/petstore/cpp-pistache/api/PetApi.h b/samples/server/petstore/cpp-pistache/api/PetApi.h index 408fbf9c7a0..b6aeb555c7a 100644 --- a/samples/server/petstore/cpp-pistache/api/PetApi.h +++ b/samples/server/petstore/cpp-pistache/api/PetApi.h @@ -22,8 +22,8 @@ #include #include #include -#include +#include #include #include "ApiResponse.h" @@ -86,7 +86,7 @@ private: /// /// Pet id to delete /// (optional, default to "") - virtual void delete_pet(const int64_t &petId, const Pistache::Optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; + virtual void delete_pet(const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by status /// @@ -94,7 +94,7 @@ private: /// Multiple status values can be provided with comma separated strings /// /// Status values that need to be considered for filter - virtual void find_pets_by_status(const Pistache::Optional> &status, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_status(const std::optional> &status, Pistache::Http::ResponseWriter &response) = 0; /// /// Finds Pets by tags /// @@ -102,7 +102,7 @@ private: /// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing. /// /// Tags to filter by - virtual void find_pets_by_tags(const Pistache::Optional> &tags, Pistache::Http::ResponseWriter &response) = 0; + virtual void find_pets_by_tags(const std::optional> &tags, Pistache::Http::ResponseWriter &response) = 0; /// /// Find pet by ID /// diff --git a/samples/server/petstore/cpp-pistache/api/StoreApi.h b/samples/server/petstore/cpp-pistache/api/StoreApi.h index 39516e5c823..f6419da20f5 100644 --- a/samples/server/petstore/cpp-pistache/api/StoreApi.h +++ b/samples/server/petstore/cpp-pistache/api/StoreApi.h @@ -22,8 +22,8 @@ #include #include #include -#include +#include #include #include "Order.h" diff --git a/samples/server/petstore/cpp-pistache/api/UserApi.cpp b/samples/server/petstore/cpp-pistache/api/UserApi.cpp index 2aff5aa9dda..43873a3d3fe 100644 --- a/samples/server/petstore/cpp-pistache/api/UserApi.cpp +++ b/samples/server/petstore/cpp-pistache/api/UserApi.cpp @@ -211,19 +211,19 @@ void UserApi::login_user_handler(const Pistache::Rest::Request &request, Pistach // Getting the query params auto usernameQuery = request.query().get("username"); - Pistache::Optional username; - if(!usernameQuery.isEmpty()){ + std::optional username; + if(usernameQuery.has_value()){ std::string valueQuery_instance; - if(fromStringValue(usernameQuery.get(), valueQuery_instance)){ - username = Pistache::Some(valueQuery_instance); + if(fromStringValue(usernameQuery.value(), valueQuery_instance)){ + username = valueQuery_instance; } } auto passwordQuery = request.query().get("password"); - Pistache::Optional password; - if(!passwordQuery.isEmpty()){ + std::optional password; + if(passwordQuery.has_value()){ std::string valueQuery_instance; - if(fromStringValue(passwordQuery.get(), valueQuery_instance)){ - password = Pistache::Some(valueQuery_instance); + if(fromStringValue(passwordQuery.value(), valueQuery_instance)){ + password = valueQuery_instance; } } diff --git a/samples/server/petstore/cpp-pistache/api/UserApi.h b/samples/server/petstore/cpp-pistache/api/UserApi.h index 76f3e55e43c..0c2fc319f57 100644 --- a/samples/server/petstore/cpp-pistache/api/UserApi.h +++ b/samples/server/petstore/cpp-pistache/api/UserApi.h @@ -22,8 +22,8 @@ #include #include #include -#include +#include #include #include "User.h" @@ -118,7 +118,7 @@ private: /// /// The user name for login /// The password for login in clear text - virtual void login_user(const Pistache::Optional &username, const Pistache::Optional &password, Pistache::Http::ResponseWriter &response) = 0; + virtual void login_user(const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) = 0; /// /// Logs out current logged in user session /// diff --git a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp index 94b49b151e4..b27e5d4d584 100644 --- a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.cpp @@ -27,13 +27,13 @@ PetApiImpl::PetApiImpl(const std::shared_ptr& rtr) void PetApiImpl::add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::delete_pet(const int64_t &petId, const Pistache::Optional &apiKey, Pistache::Http::ResponseWriter &response) { +void PetApiImpl::delete_pet(const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::find_pets_by_status(const Pistache::Optional> &status, Pistache::Http::ResponseWriter &response) { +void PetApiImpl::find_pets_by_status(const std::optional> &status, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void PetApiImpl::find_pets_by_tags(const Pistache::Optional> &tags, Pistache::Http::ResponseWriter &response) { +void PetApiImpl::find_pets_by_tags(const std::optional> &tags, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.h b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.h index 82c10b0a410..ba87dd0d7d6 100644 --- a/samples/server/petstore/cpp-pistache/impl/PetApiImpl.h +++ b/samples/server/petstore/cpp-pistache/impl/PetApiImpl.h @@ -24,10 +24,10 @@ #include #include #include +#include #include -#include #include "ApiResponse.h" #include "Pet.h" @@ -44,9 +44,9 @@ public: ~PetApiImpl() override = default; void add_pet(const Pet &body, Pistache::Http::ResponseWriter &response); - void delete_pet(const int64_t &petId, const Pistache::Optional &apiKey, Pistache::Http::ResponseWriter &response); - void find_pets_by_status(const Pistache::Optional> &status, Pistache::Http::ResponseWriter &response); - void find_pets_by_tags(const Pistache::Optional> &tags, Pistache::Http::ResponseWriter &response); + void delete_pet(const int64_t &petId, const std::optional &apiKey, Pistache::Http::ResponseWriter &response); + void find_pets_by_status(const std::optional> &status, Pistache::Http::ResponseWriter &response); + void find_pets_by_tags(const std::optional> &tags, Pistache::Http::ResponseWriter &response); void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response); void update_pet(const Pet &body, Pistache::Http::ResponseWriter &response); void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response); diff --git a/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.h b/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.h index c5dda64490f..e9fec939ca2 100644 --- a/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.h +++ b/samples/server/petstore/cpp-pistache/impl/StoreApiImpl.h @@ -24,10 +24,10 @@ #include #include #include +#include #include -#include #include "Order.h" #include diff --git a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp index b477f053c5c..252895e8d36 100644 --- a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp +++ b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.cpp @@ -39,7 +39,7 @@ void UserApiImpl::delete_user(const std::string &username, Pistache::Http::Respo void UserApiImpl::get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } -void UserApiImpl::login_user(const Pistache::Optional &username, const Pistache::Optional &password, Pistache::Http::ResponseWriter &response) { +void UserApiImpl::login_user(const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response) { response.send(Pistache::Http::Code::Ok, "Do some magic\n"); } void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) { diff --git a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.h b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.h index 856a30db5bb..920d94846ed 100644 --- a/samples/server/petstore/cpp-pistache/impl/UserApiImpl.h +++ b/samples/server/petstore/cpp-pistache/impl/UserApiImpl.h @@ -24,10 +24,10 @@ #include #include #include +#include #include -#include #include "User.h" #include @@ -48,7 +48,7 @@ public: void create_users_with_list_input(const std::vector &body, Pistache::Http::ResponseWriter &response); void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response); void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response); - void login_user(const Pistache::Optional &username, const Pistache::Optional &password, Pistache::Http::ResponseWriter &response); + void login_user(const std::optional &username, const std::optional &password, Pistache::Http::ResponseWriter &response); void logout_user(Pistache::Http::ResponseWriter &response); void update_user(const std::string &username, const User &body, Pistache::Http::ResponseWriter &response);