mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 02:46:10 +00:00
[cpp-restbed-server] make the restbed SERVER generator more extensible (#7679)
* Simple fix to allow users to override the Api class and set handlers * fix definition order * Regen petstore example files
This commit is contained in:
committed by
GitHub
parent
3d6bd48b67
commit
4860eb65e1
@@ -25,16 +25,6 @@ namespace {{this}} {
|
||||
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
class {{declspec}} {{classname}}: public restbed::Service
|
||||
{
|
||||
public:
|
||||
{{classname}}();
|
||||
~{{classname}}();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
};
|
||||
|
||||
|
||||
{{#operation}}
|
||||
/// <summary>
|
||||
/// {{summary}}
|
||||
@@ -84,6 +74,24 @@ private:
|
||||
|
||||
{{/operation}}
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class {{declspec}} {{classname}}: public restbed::Service
|
||||
{
|
||||
public:
|
||||
{{classname}}();
|
||||
~{{classname}}();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
{{#operation}}
|
||||
std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource;
|
||||
{{/operation}}
|
||||
};
|
||||
|
||||
|
||||
{{#apiNamespaceDeclarations}}
|
||||
}
|
||||
{{/apiNamespaceDeclarations}}
|
||||
|
||||
@@ -15,16 +15,21 @@ namespace {{this}} {
|
||||
using namespace {{modelNamespace}};
|
||||
|
||||
{{classname}}::{{classname}}() {
|
||||
{{#operation}}
|
||||
std::shared_ptr<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource> sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource = std::make_shared<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource>();
|
||||
this->publish(sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
|
||||
{{/operation}}
|
||||
}
|
||||
|
||||
{{classname}}::~{{classname}}() {}
|
||||
|
||||
void {{classname}}::startService(int const& port) {
|
||||
// A typical pattern is to derive a class from {{classname}} and allocate the shared pointers for restbed::Resource objects
|
||||
// and manipulate them (e.g. binding GET/POST handler functions) before this startService() gets called.
|
||||
// In such a case we want to use our m_spXXX variables.
|
||||
// However in case these shared pointers are nullptr, then allocate the restbed::Resources now:
|
||||
{{#operation}}
|
||||
if (!m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource)
|
||||
m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource = std::make_shared<{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource>();
|
||||
this->publish(m_sp{{classname}}{{vendorExtensions.x-codegen-resource-name}}Resource);
|
||||
{{/operation}}
|
||||
|
||||
std::shared_ptr<restbed::Settings> settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(port);
|
||||
settings->set_root("{{contextPath}}");
|
||||
|
||||
@@ -1 +1 @@
|
||||
unset
|
||||
5.0.0-SNAPSHOT
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -26,26 +26,31 @@ namespace api {
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
PetApi::PetApi() {
|
||||
std::shared_ptr<PetApiPetResource> spPetApiPetResource = std::make_shared<PetApiPetResource>();
|
||||
this->publish(spPetApiPetResource);
|
||||
|
||||
std::shared_ptr<PetApiPetPetIdResource> spPetApiPetPetIdResource = std::make_shared<PetApiPetPetIdResource>();
|
||||
this->publish(spPetApiPetPetIdResource);
|
||||
|
||||
std::shared_ptr<PetApiPetFindByStatusResource> spPetApiPetFindByStatusResource = std::make_shared<PetApiPetFindByStatusResource>();
|
||||
this->publish(spPetApiPetFindByStatusResource);
|
||||
|
||||
std::shared_ptr<PetApiPetFindByTagsResource> spPetApiPetFindByTagsResource = std::make_shared<PetApiPetFindByTagsResource>();
|
||||
this->publish(spPetApiPetFindByTagsResource);
|
||||
|
||||
std::shared_ptr<PetApiPetPetIdUploadImageResource> spPetApiPetPetIdUploadImageResource = std::make_shared<PetApiPetPetIdUploadImageResource>();
|
||||
this->publish(spPetApiPetPetIdUploadImageResource);
|
||||
|
||||
}
|
||||
|
||||
PetApi::~PetApi() {}
|
||||
|
||||
void PetApi::startService(int const& port) {
|
||||
// A typical pattern is to derive a class from PetApi and allocate the shared pointers for restbed::Resource objects
|
||||
// and manipulate them (e.g. binding GET/POST handler functions) before this startService() gets called.
|
||||
// In such a case we want to use our m_spXXX variables.
|
||||
// However in case these shared pointers are nullptr, then allocate the restbed::Resources now:
|
||||
if (!m_spPetApiPetResource)
|
||||
m_spPetApiPetResource = std::make_shared<PetApiPetResource>();
|
||||
this->publish(m_spPetApiPetResource);
|
||||
if (!m_spPetApiPetPetIdResource)
|
||||
m_spPetApiPetPetIdResource = std::make_shared<PetApiPetPetIdResource>();
|
||||
this->publish(m_spPetApiPetPetIdResource);
|
||||
if (!m_spPetApiPetFindByStatusResource)
|
||||
m_spPetApiPetFindByStatusResource = std::make_shared<PetApiPetFindByStatusResource>();
|
||||
this->publish(m_spPetApiPetFindByStatusResource);
|
||||
if (!m_spPetApiPetFindByTagsResource)
|
||||
m_spPetApiPetFindByTagsResource = std::make_shared<PetApiPetFindByTagsResource>();
|
||||
this->publish(m_spPetApiPetFindByTagsResource);
|
||||
if (!m_spPetApiPetPetIdUploadImageResource)
|
||||
m_spPetApiPetPetIdUploadImageResource = std::make_shared<PetApiPetPetIdUploadImageResource>();
|
||||
this->publish(m_spPetApiPetPetIdUploadImageResource);
|
||||
|
||||
std::shared_ptr<restbed::Settings> settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(port);
|
||||
settings->set_root("/v2");
|
||||
@@ -66,9 +71,6 @@ PetApiPetResource::PetApiPetResource()
|
||||
this->set_method_handler("PUT",
|
||||
std::bind(&PetApiPetResource::PUT_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
body = std::make_shared<Pet>();
|
||||
|
||||
}
|
||||
|
||||
PetApiPetResource::~PetApiPetResource()
|
||||
@@ -175,16 +177,9 @@ PetApiPetPetIdResource::PetApiPetPetIdResource()
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&PetApiPetPetIdResource::DELETE_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetPetIdResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&PetApiPetPetIdResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
petId = 0L;
|
||||
apiKey = "";
|
||||
|
||||
}
|
||||
|
||||
PetApiPetPetIdResource::~PetApiPetPetIdResource()
|
||||
@@ -198,12 +193,6 @@ void PetApiPetPetIdResource::set_handler_DELETE(
|
||||
handler_DELETE_ = std::move(handler);
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
void PetApiPetPetIdResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
@@ -240,41 +229,6 @@ void PetApiPetPetIdResource::DELETE_method_handler(const std::shared_ptr<restbed
|
||||
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = request->get_path_parameter("petId", 0L);
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
petId
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
std::shared_ptr<Pet> response = NULL;
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
session->close(400, result.empty() ? "Invalid ID supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, result.empty() ? "Pet not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void PetApiPetPetIdResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -309,8 +263,6 @@ PetApiPetFindByStatusResource::PetApiPetFindByStatusResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetFindByStatusResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
PetApiPetFindByStatusResource::~PetApiPetFindByStatusResource()
|
||||
@@ -363,8 +315,6 @@ PetApiPetFindByTagsResource::PetApiPetFindByTagsResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetFindByTagsResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
PetApiPetFindByTagsResource::~PetApiPetFindByTagsResource()
|
||||
@@ -417,11 +367,6 @@ PetApiPetPetIdUploadImageResource::PetApiPetPetIdUploadImageResource()
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&PetApiPetPetIdUploadImageResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
petId = 0L;
|
||||
additionalMetadata = "";
|
||||
file = "";
|
||||
|
||||
}
|
||||
|
||||
PetApiPetPetIdUploadImageResource::~PetApiPetPetIdUploadImageResource()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -45,6 +45,13 @@ public:
|
||||
~PetApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,7 +90,7 @@ private:
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler_PUT_;
|
||||
|
||||
std::shared_ptr<Pet> body;
|
||||
std::shared_ptr<Pet> body{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -98,7 +105,6 @@ public:
|
||||
PetApiPetPetIdResource();
|
||||
virtual ~PetApiPetPetIdResource();
|
||||
void DELETE_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void POST_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_DELETE(
|
||||
@@ -107,11 +113,6 @@ public:
|
||||
)> handler
|
||||
);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &
|
||||
)> handler
|
||||
);
|
||||
void set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
@@ -123,15 +124,12 @@ private:
|
||||
int64_t const &, std::string const &
|
||||
)> handler_DELETE_;
|
||||
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &
|
||||
)> handler_GET_;
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler_POST_;
|
||||
|
||||
int64_t petId;
|
||||
std::string apiKey;
|
||||
int64_t petId{};
|
||||
std::string apiKey{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -160,7 +158,7 @@ private:
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::vector<std::string> status;
|
||||
std::vector<std::string> status{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -189,7 +187,7 @@ private:
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::vector<std::string> tags;
|
||||
std::vector<std::string> tags{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -218,9 +216,9 @@ private:
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
int64_t petId;
|
||||
std::string additionalMetadata;
|
||||
std::string file;
|
||||
int64_t petId{};
|
||||
std::string additionalMetadata{};
|
||||
std::string file{};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -26,20 +26,25 @@ namespace api {
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
StoreApi::StoreApi() {
|
||||
std::shared_ptr<StoreApiStoreOrderOrderIdResource> spStoreApiStoreOrderOrderIdResource = std::make_shared<StoreApiStoreOrderOrderIdResource>();
|
||||
this->publish(spStoreApiStoreOrderOrderIdResource);
|
||||
|
||||
std::shared_ptr<StoreApiStoreInventoryResource> spStoreApiStoreInventoryResource = std::make_shared<StoreApiStoreInventoryResource>();
|
||||
this->publish(spStoreApiStoreInventoryResource);
|
||||
|
||||
std::shared_ptr<StoreApiStoreOrderResource> spStoreApiStoreOrderResource = std::make_shared<StoreApiStoreOrderResource>();
|
||||
this->publish(spStoreApiStoreOrderResource);
|
||||
|
||||
}
|
||||
|
||||
StoreApi::~StoreApi() {}
|
||||
|
||||
void StoreApi::startService(int const& port) {
|
||||
// A typical pattern is to derive a class from StoreApi and allocate the shared pointers for restbed::Resource objects
|
||||
// and manipulate them (e.g. binding GET/POST handler functions) before this startService() gets called.
|
||||
// In such a case we want to use our m_spXXX variables.
|
||||
// However in case these shared pointers are nullptr, then allocate the restbed::Resources now:
|
||||
if (!m_spStoreApiStoreOrderOrderIdResource)
|
||||
m_spStoreApiStoreOrderOrderIdResource = std::make_shared<StoreApiStoreOrderOrderIdResource>();
|
||||
this->publish(m_spStoreApiStoreOrderOrderIdResource);
|
||||
if (!m_spStoreApiStoreInventoryResource)
|
||||
m_spStoreApiStoreInventoryResource = std::make_shared<StoreApiStoreInventoryResource>();
|
||||
this->publish(m_spStoreApiStoreInventoryResource);
|
||||
if (!m_spStoreApiStoreOrderResource)
|
||||
m_spStoreApiStoreOrderResource = std::make_shared<StoreApiStoreOrderResource>();
|
||||
this->publish(m_spStoreApiStoreOrderResource);
|
||||
|
||||
std::shared_ptr<restbed::Settings> settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(port);
|
||||
settings->set_root("/v2");
|
||||
@@ -60,9 +65,6 @@ StoreApiStoreOrderOrderIdResource::StoreApiStoreOrderOrderIdResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreApiStoreOrderOrderIdResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
orderId = "";
|
||||
|
||||
}
|
||||
|
||||
StoreApiStoreOrderOrderIdResource::~StoreApiStoreOrderOrderIdResource()
|
||||
@@ -157,8 +159,6 @@ StoreApiStoreInventoryResource::StoreApiStoreInventoryResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreApiStoreInventoryResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
StoreApiStoreInventoryResource::~StoreApiStoreInventoryResource()
|
||||
@@ -206,9 +206,6 @@ StoreApiStoreOrderResource::StoreApiStoreOrderResource()
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&StoreApiStoreOrderResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
body = std::make_shared<Order>();
|
||||
|
||||
}
|
||||
|
||||
StoreApiStoreOrderResource::~StoreApiStoreOrderResource()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -45,6 +45,11 @@ public:
|
||||
~StoreApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<StoreApiStoreOrderOrderIdResource> m_spStoreApiStoreOrderOrderIdResource;
|
||||
std::shared_ptr<StoreApiStoreInventoryResource> m_spStoreApiStoreInventoryResource;
|
||||
std::shared_ptr<StoreApiStoreOrderResource> m_spStoreApiStoreOrderResource;
|
||||
};
|
||||
|
||||
|
||||
@@ -83,7 +88,7 @@ private:
|
||||
int64_t const &
|
||||
)> handler_GET_;
|
||||
|
||||
std::string orderId;
|
||||
std::string orderId{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -140,7 +145,7 @@ private:
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::shared_ptr<Order> body;
|
||||
std::shared_ptr<Order> body{};
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -26,29 +26,34 @@ namespace api {
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
UserApi::UserApi() {
|
||||
std::shared_ptr<UserApiUserResource> spUserApiUserResource = std::make_shared<UserApiUserResource>();
|
||||
this->publish(spUserApiUserResource);
|
||||
|
||||
std::shared_ptr<UserApiUserCreateWithArrayResource> spUserApiUserCreateWithArrayResource = std::make_shared<UserApiUserCreateWithArrayResource>();
|
||||
this->publish(spUserApiUserCreateWithArrayResource);
|
||||
|
||||
std::shared_ptr<UserApiUserCreateWithListResource> spUserApiUserCreateWithListResource = std::make_shared<UserApiUserCreateWithListResource>();
|
||||
this->publish(spUserApiUserCreateWithListResource);
|
||||
|
||||
std::shared_ptr<UserApiUserUsernameResource> spUserApiUserUsernameResource = std::make_shared<UserApiUserUsernameResource>();
|
||||
this->publish(spUserApiUserUsernameResource);
|
||||
|
||||
std::shared_ptr<UserApiUserLoginResource> spUserApiUserLoginResource = std::make_shared<UserApiUserLoginResource>();
|
||||
this->publish(spUserApiUserLoginResource);
|
||||
|
||||
std::shared_ptr<UserApiUserLogoutResource> spUserApiUserLogoutResource = std::make_shared<UserApiUserLogoutResource>();
|
||||
this->publish(spUserApiUserLogoutResource);
|
||||
|
||||
}
|
||||
|
||||
UserApi::~UserApi() {}
|
||||
|
||||
void UserApi::startService(int const& port) {
|
||||
// A typical pattern is to derive a class from UserApi and allocate the shared pointers for restbed::Resource objects
|
||||
// and manipulate them (e.g. binding GET/POST handler functions) before this startService() gets called.
|
||||
// In such a case we want to use our m_spXXX variables.
|
||||
// However in case these shared pointers are nullptr, then allocate the restbed::Resources now:
|
||||
if (!m_spUserApiUserResource)
|
||||
m_spUserApiUserResource = std::make_shared<UserApiUserResource>();
|
||||
this->publish(m_spUserApiUserResource);
|
||||
if (!m_spUserApiUserCreateWithArrayResource)
|
||||
m_spUserApiUserCreateWithArrayResource = std::make_shared<UserApiUserCreateWithArrayResource>();
|
||||
this->publish(m_spUserApiUserCreateWithArrayResource);
|
||||
if (!m_spUserApiUserCreateWithListResource)
|
||||
m_spUserApiUserCreateWithListResource = std::make_shared<UserApiUserCreateWithListResource>();
|
||||
this->publish(m_spUserApiUserCreateWithListResource);
|
||||
if (!m_spUserApiUserUsernameResource)
|
||||
m_spUserApiUserUsernameResource = std::make_shared<UserApiUserUsernameResource>();
|
||||
this->publish(m_spUserApiUserUsernameResource);
|
||||
if (!m_spUserApiUserLoginResource)
|
||||
m_spUserApiUserLoginResource = std::make_shared<UserApiUserLoginResource>();
|
||||
this->publish(m_spUserApiUserLoginResource);
|
||||
if (!m_spUserApiUserLogoutResource)
|
||||
m_spUserApiUserLogoutResource = std::make_shared<UserApiUserLogoutResource>();
|
||||
this->publish(m_spUserApiUserLogoutResource);
|
||||
|
||||
std::shared_ptr<restbed::Settings> settings = std::make_shared<restbed::Settings>();
|
||||
settings->set_port(port);
|
||||
settings->set_root("/v2");
|
||||
@@ -66,9 +71,6 @@ UserApiUserResource::UserApiUserResource()
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
body = std::make_shared<User>();
|
||||
|
||||
}
|
||||
|
||||
UserApiUserResource::~UserApiUserResource()
|
||||
@@ -128,8 +130,6 @@ UserApiUserCreateWithArrayResource::UserApiUserCreateWithArrayResource()
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserCreateWithArrayResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
UserApiUserCreateWithArrayResource::~UserApiUserCreateWithArrayResource()
|
||||
@@ -189,8 +189,6 @@ UserApiUserCreateWithListResource::UserApiUserCreateWithListResource()
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserCreateWithListResource::POST_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
UserApiUserCreateWithListResource::~UserApiUserCreateWithListResource()
|
||||
@@ -250,15 +248,9 @@ UserApiUserUsernameResource::UserApiUserUsernameResource()
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&UserApiUserUsernameResource::DELETE_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserUsernameResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("PUT",
|
||||
std::bind(&UserApiUserUsernameResource::PUT_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
username = "";
|
||||
|
||||
}
|
||||
|
||||
UserApiUserUsernameResource::~UserApiUserUsernameResource()
|
||||
@@ -272,12 +264,6 @@ void UserApiUserUsernameResource::set_handler_DELETE(
|
||||
handler_DELETE_ = std::move(handler);
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
void UserApiUserUsernameResource::set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
@@ -316,41 +302,6 @@ void UserApiUserUsernameResource::DELETE_method_handler(const std::shared_ptr<re
|
||||
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = request->get_path_parameter("username", "");
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
username
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
std::shared_ptr<User> response = NULL;
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
session->close(400, result.empty() ? "Invalid username supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, result.empty() ? "User not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
void UserApiUserUsernameResource::PUT_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -398,10 +349,6 @@ UserApiUserLoginResource::UserApiUserLoginResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserLoginResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
username = "";
|
||||
password = "";
|
||||
|
||||
}
|
||||
|
||||
UserApiUserLoginResource::~UserApiUserLoginResource()
|
||||
@@ -460,8 +407,6 @@ UserApiUserLogoutResource::UserApiUserLogoutResource()
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserLogoutResource::GET_method_handler, this,
|
||||
std::placeholders::_1));
|
||||
|
||||
|
||||
}
|
||||
|
||||
UserApiUserLogoutResource::~UserApiUserLogoutResource()
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -45,6 +45,14 @@ public:
|
||||
~UserApi();
|
||||
void startService(int const& port);
|
||||
void stopService();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<UserApiUserResource> m_spUserApiUserResource;
|
||||
std::shared_ptr<UserApiUserCreateWithArrayResource> m_spUserApiUserCreateWithArrayResource;
|
||||
std::shared_ptr<UserApiUserCreateWithListResource> m_spUserApiUserCreateWithListResource;
|
||||
std::shared_ptr<UserApiUserUsernameResource> m_spUserApiUserUsernameResource;
|
||||
std::shared_ptr<UserApiUserLoginResource> m_spUserApiUserLoginResource;
|
||||
std::shared_ptr<UserApiUserLogoutResource> m_spUserApiUserLogoutResource;
|
||||
};
|
||||
|
||||
|
||||
@@ -74,7 +82,7 @@ private:
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::shared_ptr<User> body;
|
||||
std::shared_ptr<User> body{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -103,7 +111,7 @@ private:
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::vector<std::shared_ptr<User>> body;
|
||||
std::vector<std::shared_ptr<User>> body{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -132,7 +140,7 @@ private:
|
||||
)> handler_POST_;
|
||||
|
||||
|
||||
std::vector<std::shared_ptr<User>> body;
|
||||
std::vector<std::shared_ptr<User>> body{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -147,7 +155,6 @@ public:
|
||||
UserApiUserUsernameResource();
|
||||
virtual ~UserApiUserUsernameResource();
|
||||
void DELETE_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void GET_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
void PUT_method_handler(const std::shared_ptr<restbed::Session> session);
|
||||
|
||||
void set_handler_DELETE(
|
||||
@@ -156,11 +163,6 @@ public:
|
||||
)> handler
|
||||
);
|
||||
|
||||
void set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler
|
||||
);
|
||||
void set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
@@ -172,14 +174,11 @@ private:
|
||||
std::string const &
|
||||
)> handler_DELETE_;
|
||||
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler_GET_;
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
)> handler_PUT_;
|
||||
|
||||
std::string username;
|
||||
std::string username{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
@@ -208,8 +207,8 @@ private:
|
||||
)> handler_GET_;
|
||||
|
||||
|
||||
std::string username;
|
||||
std::string password;
|
||||
std::string username{};
|
||||
std::string password{};
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -75,10 +75,12 @@ ptree Pet::toPropertyTree()
|
||||
pt.add_child("photoUrls", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
// generate tree for vector of pointers of Tags
|
||||
// generate tree for Tags
|
||||
if (!m_Tags.empty()) {
|
||||
for (const auto &childEntry : m_Tags) {
|
||||
tmp_node.push_back(std::make_pair("", childEntry->toPropertyTree()));
|
||||
ptree Tags_node;
|
||||
Tags_node.put("", childEntry);
|
||||
tmp_node.push_back(std::make_pair("", Tags_node));
|
||||
}
|
||||
pt.add_child("tags", tmp_node);
|
||||
tmp_node.clear();
|
||||
@@ -102,11 +104,10 @@ void Pet::fromPropertyTree(ptree const &pt)
|
||||
m_PhotoUrls.emplace_back(childTree.second.data());
|
||||
}
|
||||
}
|
||||
// generate new Tag Object for each item and assign it to the current
|
||||
// push all items of Tags into member vector
|
||||
if (pt.get_child_optional("tags")) {
|
||||
for (const auto &childTree : pt.get_child("tags")) {
|
||||
m_Tags.emplace_back(std::make_shared<Tag>());
|
||||
m_Tags.back()->fromPropertyTree(childTree.second);
|
||||
m_Tags.emplace_back(childTree.second.data());
|
||||
}
|
||||
}
|
||||
setStatus(pt.get("status", ""));
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user