[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:
Francesco Montorsi
2020-10-27 08:35:10 +01:00
committed by GitHub
parent 3d6bd48b67
commit 4860eb65e1
21 changed files with 146 additions and 243 deletions

View 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()