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 "ApiResponse.h"
|
||||
#include "Pet.h"
|
||||
@@ -38,6 +41,22 @@ namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class PetApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
PetApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Add a new pet to the store
|
||||
/// </summary>
|
||||
@@ -47,35 +66,48 @@ using namespace org::openapitools::server::model;
|
||||
class PetApiPetResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetResource();
|
||||
PetApiPetResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetResource();
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void PUT_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
void set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler
|
||||
);
|
||||
virtual int handler_POST(
|
||||
std::shared_ptr<Pet> const & body);
|
||||
|
||||
virtual int handler_PUT(
|
||||
std::shared_ptr<Pet> const & body);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& 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<Pet> const &
|
||||
)> handler_POST_;
|
||||
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler_PUT_;
|
||||
|
||||
std::shared_ptr<Pet> body{};
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_PUT_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deletes a pet
|
||||
/// </summary>
|
||||
@@ -85,36 +117,69 @@ private:
|
||||
class PetApiPetPetIdResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetPetIdResource();
|
||||
PetApiPetPetIdResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetPetIdResource();
|
||||
void DELETE_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_DELETE(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler
|
||||
);
|
||||
virtual int handler_DELETE(
|
||||
int64_t const & petId, std::string const & apiKey);
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Pet>> handler_GET(
|
||||
int64_t const & petId);
|
||||
virtual int handler_POST(
|
||||
int64_t const & petId, std::string const & name, std::string const & status);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
virtual int64_t getPathParam_petId(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("petId", 0L);
|
||||
}
|
||||
|
||||
virtual std::string getHeader_api_key(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_header("api_key", "");
|
||||
}
|
||||
|
||||
|
||||
virtual int64_t getPathParam_petId_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("petId", 0L);
|
||||
}
|
||||
virtual int64_t getPathParam_petId_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("petId", 0L);
|
||||
}
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& 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>(
|
||||
int64_t const &, std::string const &
|
||||
)> handler_DELETE_;
|
||||
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler_POST_;
|
||||
|
||||
int64_t petId{};
|
||||
std::string apiKey{};
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by status
|
||||
/// </summary>
|
||||
@@ -124,26 +189,45 @@ private:
|
||||
class PetApiPetFindByStatusResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetFindByStatusResource();
|
||||
PetApiPetFindByStatusResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetFindByStatusResource();
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::string> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::vector<std::shared_ptr<Pet>>> handler_GET(
|
||||
std::vector<std::string> const & status);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& 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::string> const &
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::vector<std::string> status{};
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
@@ -153,26 +237,45 @@ private:
|
||||
class PetApiPetFindByTagsResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetFindByTagsResource();
|
||||
PetApiPetFindByTagsResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetFindByTagsResource();
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::string> const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::vector<std::shared_ptr<Pet>>> handler_GET(
|
||||
std::vector<std::string> const & tags);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& 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::string> const &
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::vector<std::string> tags{};
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
@@ -182,46 +285,79 @@ private:
|
||||
class PetApiPetPetIdUploadImageResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetPetIdUploadImageResource();
|
||||
PetApiPetPetIdUploadImageResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetPetIdUploadImageResource();
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler
|
||||
);
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<ApiResponse>> handler_POST(
|
||||
int64_t const & petId, std::string const & additionalMetadata, std::string const & file);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
virtual int64_t getPathParam_petId(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("petId", 0L);
|
||||
}
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handlePetApiException(const PetApiException& 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>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
int64_t petId{};
|
||||
std::string additionalMetadata{};
|
||||
std::string file{};
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class PetApi: public restbed::Service
|
||||
class PetApi
|
||||
{
|
||||
public:
|
||||
PetApi();
|
||||
~PetApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
explicit PetApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~PetApi();
|
||||
|
||||
virtual void setPetApiPetResource(std::shared_ptr<PetApiPetResource> spPetApiPetResource);
|
||||
virtual void setPetApiPetPetIdResource(std::shared_ptr<PetApiPetPetIdResource> spPetApiPetPetIdResource);
|
||||
virtual void setPetApiPetFindByStatusResource(std::shared_ptr<PetApiPetFindByStatusResource> spPetApiPetFindByStatusResource);
|
||||
virtual void setPetApiPetFindByTagsResource(std::shared_ptr<PetApiPetFindByTagsResource> spPetApiPetFindByTagsResource);
|
||||
virtual void setPetApiPetPetIdUploadImageResource(std::shared_ptr<PetApiPetPetIdUploadImageResource> spPetApiPetPetIdUploadImageResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<PetApiPetResource> m_spPetApiPetResource;
|
||||
std::shared_ptr<PetApiPetPetIdResource> m_spPetApiPetPetIdResource;
|
||||
std::shared_ptr<PetApiPetFindByStatusResource> m_spPetApiPetFindByStatusResource;
|
||||
std::shared_ptr<PetApiPetFindByTagsResource> m_spPetApiPetFindByTagsResource;
|
||||
std::shared_ptr<PetApiPetPetIdUploadImageResource> m_spPetApiPetPetIdUploadImageResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user