forked from loafle/openapi-generator-original
[cpp-pistache-server]: Fix build with pistache master branch (#10829)
* fix(cpp-pistache-server): meson/cmake build * fix(cpp-pistache-server): Upgrade to C++17 and use std::optional * feat(cpp-pistache-server): Disable running tests during build of nlohmann/json * feat(samples): Update server/petstore/cpp-pistache
This commit is contained in:
parent
70737fb1e6
commit
f2fcff2945
@ -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<Pistache::Http::Header::Raw>";
|
||||
param.baseType = "Pistache::Optional<Pistache::Http::Header::Raw>";
|
||||
param.dataType = "std::optional<Pistache::Http::Header::Raw>";
|
||||
param.baseType = "std::optional<Pistache::Http::Header::Raw>";
|
||||
} 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 + ">";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,8 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
{{^hasModelImport}}#include <nlohmann/json.hpp>{{/hasModelImport}}
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
|
@ -14,10 +14,10 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <{{classname}}.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
{{#imports}}{{{import}}}
|
||||
{{/imports}}
|
||||
|
@ -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}}
|
||||
|
@ -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}}
|
||||
|
@ -12,7 +12,7 @@
|
||||
{{#imports}}{{{this}}}
|
||||
{{/imports}}
|
||||
#include <nlohmann/json.hpp>
|
||||
{{#hasOptional}}#include <pistache/optional.h>{{/hasOptional}}
|
||||
{{#hasOptional}}#include <optional>{{/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;
|
||||
|
@ -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}}
|
||||
}
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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<std::vector<std::string>> status;
|
||||
if(!statusQuery.isEmpty()){
|
||||
std::optional<std::vector<std::string>> status;
|
||||
if(statusQuery.has_value()){
|
||||
std::vector<std::string> 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<std::vector<std::string>> tags;
|
||||
if(!tagsQuery.isEmpty()){
|
||||
std::optional<std::vector<std::string>> tags;
|
||||
if(tagsQuery.has_value()){
|
||||
std::vector<std::string> valueQuery_instance;
|
||||
if(fromStringValue(tagsQuery.get(), valueQuery_instance)){
|
||||
tags = Pistache::Some(valueQuery_instance);
|
||||
if(fromStringValue(tagsQuery.value(), valueQuery_instance)){
|
||||
tags = valueQuery_instance;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "ApiResponse.h"
|
||||
@ -86,7 +86,7 @@ private:
|
||||
/// </remarks>
|
||||
/// <param name="petId">Pet id to delete</param>
|
||||
/// <param name="apiKey"> (optional, default to "")</param>
|
||||
virtual void delete_pet(const int64_t &petId, const Pistache::Optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
|
||||
virtual void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) = 0;
|
||||
/// <summary>
|
||||
/// Finds Pets by status
|
||||
/// </summary>
|
||||
@ -94,7 +94,7 @@ private:
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
/// </remarks>
|
||||
/// <param name="status">Status values that need to be considered for filter</param>
|
||||
virtual void find_pets_by_status(const Pistache::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
|
||||
virtual void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) = 0;
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
@ -102,7 +102,7 @@ private:
|
||||
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
/// </remarks>
|
||||
/// <param name="tags">Tags to filter by</param>
|
||||
virtual void find_pets_by_tags(const Pistache::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
|
||||
virtual void find_pets_by_tags(const std::optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) = 0;
|
||||
/// <summary>
|
||||
/// Find pet by ID
|
||||
/// </summary>
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "Order.h"
|
||||
|
@ -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<std::string> username;
|
||||
if(!usernameQuery.isEmpty()){
|
||||
std::optional<std::string> 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<std::string> password;
|
||||
if(!passwordQuery.isEmpty()){
|
||||
std::optional<std::string> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,8 +22,8 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
|
||||
#include "User.h"
|
||||
@ -118,7 +118,7 @@ private:
|
||||
/// </remarks>
|
||||
/// <param name="username">The user name for login</param>
|
||||
/// <param name="password">The password for login in clear text</param>
|
||||
virtual void login_user(const Pistache::Optional<std::string> &username, const Pistache::Optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
|
||||
virtual void login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) = 0;
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
|
@ -27,13 +27,13 @@ PetApiImpl::PetApiImpl(const std::shared_ptr<Pistache::Rest::Router>& 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<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) {
|
||||
void PetApiImpl::delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::find_pets_by_status(const Pistache::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) {
|
||||
void PetApiImpl::find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void PetApiImpl::find_pets_by_tags(const Pistache::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response) {
|
||||
void PetApiImpl::find_pets_by_tags(const std::optional<std::vector<std::string>> &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) {
|
||||
|
@ -24,10 +24,10 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <PetApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#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<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_status(const Pistache::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_tags(const Pistache::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response);
|
||||
void delete_pet(const int64_t &petId, const std::optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_status(const std::optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response);
|
||||
void find_pets_by_tags(const std::optional<std::vector<std::string>> &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);
|
||||
|
@ -24,10 +24,10 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <StoreApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include "Order.h"
|
||||
#include <map>
|
||||
|
@ -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<std::string> &username, const Pistache::Optional<std::string> &password, Pistache::Http::ResponseWriter &response) {
|
||||
void UserApiImpl::login_user(const std::optional<std::string> &username, const std::optional<std::string> &password, Pistache::Http::ResponseWriter &response) {
|
||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||
}
|
||||
void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) {
|
||||
|
@ -24,10 +24,10 @@
|
||||
#include <pistache/http.h>
|
||||
#include <pistache/router.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
#include <UserApi.h>
|
||||
|
||||
#include <pistache/optional.h>
|
||||
|
||||
#include "User.h"
|
||||
#include <string>
|
||||
@ -48,7 +48,7 @@ public:
|
||||
void create_users_with_list_input(const std::vector<User> &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<std::string> &username, const Pistache::Optional<std::string> &password, Pistache::Http::ResponseWriter &response);
|
||||
void login_user(const std::optional<std::string> &username, const std::optional<std::string> &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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user