forked from loafle/openapi-generator-original
Improve templates for C++ Restbed (#10543)
* Improve templates for C++ Restbed The templates now generate classes which have virtual functions that can be overridden to implement handlers. * Fix missing HTTP methods in generated restbed C++ code There was a wrong handling of "x-codegen-other-methods". Change-Id: If6526d2672434beb5ebb0871d84cb80d84c34c38
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -22,10 +22,13 @@
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <exception>
|
||||
|
||||
#include <corvusoft/restbed/session.hpp>
|
||||
#include <corvusoft/restbed/resource.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/service.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
|
||||
#include "User.h"
|
||||
#include <string>
|
||||
@@ -38,6 +41,22 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class UserApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
UserApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Create user
|
||||
/// </summary>
|
||||
@@ -47,26 +66,45 @@ using namespace org::openapitools::server::model;
|
||||
class UserApiUserResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserResource();
|
||||
UserApiUserResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserResource();
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<User> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::shared_ptr<User> const & body);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<User> const &
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::shared_ptr<User> body{};
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
@@ -76,26 +114,45 @@ private:
|
||||
class UserApiUserCreateWithArrayResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserCreateWithArrayResource();
|
||||
UserApiUserCreateWithArrayResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserCreateWithArrayResource();
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::vector<std::shared_ptr<User>> body{};
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
@@ -105,26 +162,45 @@ private:
|
||||
class UserApiUserCreateWithListResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserCreateWithListResource();
|
||||
UserApiUserCreateWithListResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserCreateWithListResource();
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & body);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::vector<std::shared_ptr<User>> body{};
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete user
|
||||
/// </summary>
|
||||
@@ -134,35 +210,64 @@ private:
|
||||
class UserApiUserUsernameResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserUsernameResource();
|
||||
UserApiUserUsernameResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserUsernameResource();
|
||||
void DELETE_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void PUT_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_DELETE(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
void set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
)> handler
|
||||
);
|
||||
virtual int handler_DELETE(
|
||||
std::string const & username);
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<User>> handler_GET(
|
||||
std::string const & username);
|
||||
virtual int handler_PUT(
|
||||
std::string const & username, std::shared_ptr<User> const & body);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
virtual std::string getPathParam_username(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("username", "");
|
||||
}
|
||||
|
||||
|
||||
virtual std::string getPathParam_username_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("username", "");
|
||||
}
|
||||
virtual std::string getPathParam_username_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("username", "");
|
||||
}
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler_DELETE_;
|
||||
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
)> handler_PUT_;
|
||||
|
||||
std::string username{};
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_PUT_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Logs user into the system
|
||||
/// </summary>
|
||||
@@ -172,27 +277,55 @@ private:
|
||||
class UserApiUserLoginResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserLoginResource();
|
||||
UserApiUserLoginResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserLoginResource();
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::string const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::string> handler_GET(
|
||||
std::string const & username, std::string const & password);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
virtual std::string getQueryParam_username(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("username", "");
|
||||
}
|
||||
|
||||
virtual std::string getQueryParam_password(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_query_parameter("password", "");
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::string const &
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::string username{};
|
||||
std::string password{};
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
@@ -202,37 +335,66 @@ private:
|
||||
class UserApiUserLogoutResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserLogoutResource();
|
||||
UserApiUserLogoutResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserLogoutResource();
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_GET(
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleUserApiException(const UserApiException& e);
|
||||
virtual std::pair<int, std::string> handleStdException(const std::exception& e);
|
||||
virtual std::pair<int, std::string> handleUnspecifiedException();
|
||||
|
||||
virtual void setResponseHeader(const std::shared_ptr<restbed::Session>& session,
|
||||
const std::string& header);
|
||||
|
||||
|
||||
virtual void returnResponse(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result, const std::string& contentType);
|
||||
virtual void defaultSessionClose(const std::shared_ptr<restbed::Session>& session,
|
||||
const int status, const std::string& result);
|
||||
|
||||
private:
|
||||
std::function<std::pair<int, std::string>(
|
||||
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class UserApi: public restbed::Service
|
||||
class UserApi
|
||||
{
|
||||
public:
|
||||
UserApi();
|
||||
~UserApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
explicit UserApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~UserApi();
|
||||
|
||||
virtual void setUserApiUserResource(std::shared_ptr<UserApiUserResource> spUserApiUserResource);
|
||||
virtual void setUserApiUserCreateWithArrayResource(std::shared_ptr<UserApiUserCreateWithArrayResource> spUserApiUserCreateWithArrayResource);
|
||||
virtual void setUserApiUserCreateWithListResource(std::shared_ptr<UserApiUserCreateWithListResource> spUserApiUserCreateWithListResource);
|
||||
virtual void setUserApiUserUsernameResource(std::shared_ptr<UserApiUserUsernameResource> spUserApiUserUsernameResource);
|
||||
virtual void setUserApiUserLoginResource(std::shared_ptr<UserApiUserLoginResource> spUserApiUserLoginResource);
|
||||
virtual void setUserApiUserLogoutResource(std::shared_ptr<UserApiUserLogoutResource> spUserApiUserLogoutResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<UserApiUserResource> m_spUserApiUserResource;
|
||||
std::shared_ptr<UserApiUserCreateWithArrayResource> m_spUserApiUserCreateWithArrayResource;
|
||||
@@ -240,6 +402,9 @@ protected:
|
||||
std::shared_ptr<UserApiUserUsernameResource> m_spUserApiUserUsernameResource;
|
||||
std::shared_ptr<UserApiUserLoginResource> m_spUserApiUserLoginResource;
|
||||
std::shared_ptr<UserApiUserLogoutResource> m_spUserApiUserLogoutResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user