forked from loafle/openapi-generator-original
Cpp restbed server improvements (#13030)
* Keep old implementation of cpp-restbed generator as cpp-restbed-server-deprecated * Refactor operation path processing * Restructure samples directory to better allow writing tests * Improve templates for cpp-restbed-server Improve templates * Add integration tests * Improvement in templates for cpp-restbed-server * Fix tests * Improve cpp-restbed generator * Improve cpp-restbed-server * Add more tests * Add suppoert for arrays of enums in query params * Generate CMakeLists.txt * Small improvements and example in Readme * Add integration tests to maven project * Update doc
This commit is contained in:
819
samples/server/petstore/cpp-restbed-deprecated/api/PetApi.cpp
Normal file
819
samples/server/petstore/cpp-restbed-deprecated/api/PetApi.cpp
Normal file
@@ -0,0 +1,819 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "PetApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
PetApiException::PetApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int PetApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* PetApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
std::shared_ptr<MODEL_T> extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = std::make_shared<MODEL_T>(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<std::shared_ptr<MODEL_T>> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<std::shared_ptr<MODEL_T>>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(std::make_shared<MODEL_T>(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
PetApiPetResource::PetApiPetResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/pet/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&PetApiPetResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("PUT",
|
||||
std::bind(&PetApiPetResource::handler_PUT_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
PetApiPetResource::~PetApiPetResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetResource::handlePetApiException(const PetApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void PetApiPetResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void PetApiPetResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void PetApiPetResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void PetApiPetResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto pet = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(pet);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 405) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 405, result.empty() ? "Invalid input" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
// x-extension
|
||||
void PetApiPetResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// body params or form params here from the body content string
|
||||
auto pet = extractJsonModelBodyParam<Pet>(bodyContent);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_PUT(pet);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid ID supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "Pet not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 405) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 405, result.empty() ? "Validation exception" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
std::pair<int, std::shared_ptr<Pet>> PetApiPetResource::handler_POST(
|
||||
std::shared_ptr<Pet> const & pet)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::pair<int, std::shared_ptr<Pet>> PetApiPetResource::handler_PUT(
|
||||
std::shared_ptr<Pet> const & pet)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::string PetApiPetResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
PetApiPetPetIdResource::PetApiPetPetIdResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/pet/{petId: .*}/");
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&PetApiPetPetIdResource::handler_DELETE_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetPetIdResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&PetApiPetPetIdResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
PetApiPetPetIdResource::~PetApiPetPetIdResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdResource::handlePetApiException(const PetApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::handler_DELETE_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = getPathParam_petId(request);
|
||||
|
||||
|
||||
// Getting the headers
|
||||
const std::string apiKey = getHeader_api_key(request);
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_DELETE(petId, apiKey);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid pet value" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
// x-extension
|
||||
void PetApiPetPetIdResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = getPathParam_petId_x_extension(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Pet> resultObject = std::make_shared<Pet>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(petId);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid ID supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "Pet not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
// x-extension
|
||||
void PetApiPetPetIdResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = getPathParam_petId_x_extension(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(petId, name, status);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 405) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 405, result.empty() ? "Invalid input" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
int PetApiPetPetIdResource::handler_DELETE(
|
||||
int64_t const & petId, std::string const & apiKey)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::pair<int, std::shared_ptr<Pet>> PetApiPetPetIdResource::handler_GET(
|
||||
int64_t const & petId)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
int PetApiPetPetIdResource::handler_POST(
|
||||
int64_t const & petId, std::string const & name, std::string const & status)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::string PetApiPetPetIdResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
PetApiPetFindByStatusResource::PetApiPetFindByStatusResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/pet/findByStatus/");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetFindByStatusResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
PetApiPetFindByStatusResource::~PetApiPetFindByStatusResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByStatusResource::handlePetApiException(const PetApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByStatusResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByStatusResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void PetApiPetFindByStatusResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void PetApiPetFindByStatusResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void PetApiPetFindByStatusResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void PetApiPetFindByStatusResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the query params
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::vector<std::shared_ptr<Pet>> resultObject = std::vector<std::shared_ptr<Pet>>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(status);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid status value" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::vector<std::shared_ptr<Pet>>> PetApiPetFindByStatusResource::handler_GET(
|
||||
std::vector<std::string> const & status)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string PetApiPetFindByStatusResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
PetApiPetFindByTagsResource::PetApiPetFindByTagsResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/pet/findByTags/");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&PetApiPetFindByTagsResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
PetApiPetFindByTagsResource::~PetApiPetFindByTagsResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByTagsResource::handlePetApiException(const PetApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByTagsResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetFindByTagsResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void PetApiPetFindByTagsResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void PetApiPetFindByTagsResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void PetApiPetFindByTagsResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void PetApiPetFindByTagsResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the query params
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::vector<std::shared_ptr<Pet>> resultObject = std::vector<std::shared_ptr<Pet>>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(tags);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid tag value" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::vector<std::shared_ptr<Pet>>> PetApiPetFindByTagsResource::handler_GET(
|
||||
std::vector<std::string> const & tags)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string PetApiPetFindByTagsResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
PetApiPetPetIdUploadImageResource::PetApiPetPetIdUploadImageResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/pet/{petId: .*}/uploadImage/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&PetApiPetPetIdUploadImageResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
PetApiPetPetIdUploadImageResource::~PetApiPetPetIdUploadImageResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdUploadImageResource::handlePetApiException(const PetApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdUploadImageResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> PetApiPetPetIdUploadImageResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = getPathParam_petId(request);
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<ApiResponse> resultObject = std::make_shared<ApiResponse>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(petId, additionalMetadata, file);
|
||||
}
|
||||
catch(const PetApiException& e) {
|
||||
std::tie(status_code, result) = handlePetApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::shared_ptr<ApiResponse>> PetApiPetPetIdUploadImageResource::handler_POST(
|
||||
int64_t const & petId, std::string const & additionalMetadata, std::string const & file)
|
||||
{
|
||||
throw PetApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string PetApiPetPetIdUploadImageResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
PetApi::PetApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
PetApi::~PetApi() {}
|
||||
|
||||
void PetApi::setPetApiPetResource(std::shared_ptr<PetApiPetResource> spPetApiPetResource) {
|
||||
m_spPetApiPetResource = spPetApiPetResource;
|
||||
m_service->publish(m_spPetApiPetResource);
|
||||
}
|
||||
void PetApi::setPetApiPetPetIdResource(std::shared_ptr<PetApiPetPetIdResource> spPetApiPetPetIdResource) {
|
||||
m_spPetApiPetPetIdResource = spPetApiPetPetIdResource;
|
||||
m_service->publish(m_spPetApiPetPetIdResource);
|
||||
}
|
||||
void PetApi::setPetApiPetFindByStatusResource(std::shared_ptr<PetApiPetFindByStatusResource> spPetApiPetFindByStatusResource) {
|
||||
m_spPetApiPetFindByStatusResource = spPetApiPetFindByStatusResource;
|
||||
m_service->publish(m_spPetApiPetFindByStatusResource);
|
||||
}
|
||||
void PetApi::setPetApiPetFindByTagsResource(std::shared_ptr<PetApiPetFindByTagsResource> spPetApiPetFindByTagsResource) {
|
||||
m_spPetApiPetFindByTagsResource = spPetApiPetFindByTagsResource;
|
||||
m_service->publish(m_spPetApiPetFindByTagsResource);
|
||||
}
|
||||
void PetApi::setPetApiPetPetIdUploadImageResource(std::shared_ptr<PetApiPetPetIdUploadImageResource> spPetApiPetPetIdUploadImageResource) {
|
||||
m_spPetApiPetPetIdUploadImageResource = spPetApiPetPetIdUploadImageResource;
|
||||
m_service->publish(m_spPetApiPetPetIdUploadImageResource);
|
||||
}
|
||||
|
||||
|
||||
void PetApi::publishDefaultResources() {
|
||||
if (!m_spPetApiPetResource) {
|
||||
setPetApiPetResource(std::make_shared<PetApiPetResource>());
|
||||
}
|
||||
if (!m_spPetApiPetPetIdResource) {
|
||||
setPetApiPetPetIdResource(std::make_shared<PetApiPetPetIdResource>());
|
||||
}
|
||||
if (!m_spPetApiPetFindByStatusResource) {
|
||||
setPetApiPetFindByStatusResource(std::make_shared<PetApiPetFindByStatusResource>());
|
||||
}
|
||||
if (!m_spPetApiPetFindByTagsResource) {
|
||||
setPetApiPetFindByTagsResource(std::make_shared<PetApiPetFindByTagsResource>());
|
||||
}
|
||||
if (!m_spPetApiPetPetIdUploadImageResource) {
|
||||
setPetApiPetPetIdUploadImageResource(std::make_shared<PetApiPetPetIdUploadImageResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> PetApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
370
samples/server/petstore/cpp-restbed-deprecated/api/PetApi.h
Normal file
370
samples/server/petstore/cpp-restbed-deprecated/api/PetApi.h
Normal file
@@ -0,0 +1,370 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* PetApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef PetApi_H_
|
||||
#define PetApi_H_
|
||||
|
||||
|
||||
#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"
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
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>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetApiPetResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Pet>> handler_POST(
|
||||
std::shared_ptr<Pet> const & pet);
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Pet>> handler_PUT(
|
||||
std::shared_ptr<Pet> const & pet);
|
||||
|
||||
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:
|
||||
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>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetApiPetPetIdResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetPetIdResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetPetIdResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
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:
|
||||
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>
|
||||
/// <remarks>
|
||||
/// Multiple status values can be provided with comma separated strings
|
||||
/// </remarks>
|
||||
class PetApiPetFindByStatusResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetFindByStatusResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetFindByStatusResource();
|
||||
|
||||
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:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Finds Pets by tags
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||
/// </remarks>
|
||||
class PetApiPetFindByTagsResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetFindByTagsResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetFindByTagsResource();
|
||||
|
||||
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:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// uploads an image
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class PetApiPetPetIdUploadImageResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
PetApiPetPetIdUploadImageResource(const std::string& context = "/v2");
|
||||
virtual ~PetApiPetPetIdUploadImageResource();
|
||||
|
||||
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:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class PetApi
|
||||
{
|
||||
public:
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* PetApi_H_ */
|
||||
|
||||
497
samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.cpp
Normal file
497
samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.cpp
Normal file
@@ -0,0 +1,497 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "StoreApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
StoreApiException::StoreApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int StoreApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* StoreApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
std::shared_ptr<MODEL_T> extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = std::make_shared<MODEL_T>(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<std::shared_ptr<MODEL_T>> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<std::shared_ptr<MODEL_T>>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(std::make_shared<MODEL_T>(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
StoreApiStoreOrderOrderIdResource::StoreApiStoreOrderOrderIdResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/order/{orderId: .*}/");
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&StoreApiStoreOrderOrderIdResource::handler_DELETE_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreApiStoreOrderOrderIdResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
StoreApiStoreOrderOrderIdResource::~StoreApiStoreOrderOrderIdResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderOrderIdResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderOrderIdResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderOrderIdResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderOrderIdResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderOrderIdResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderOrderIdResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderOrderIdResource::handler_DELETE_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const std::string orderId = getPathParam_orderId(request);
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_DELETE(orderId);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid ID supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "Order not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
// x-extension
|
||||
void StoreApiStoreOrderOrderIdResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const int64_t orderId = getPathParam_orderId_x_extension(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Order> resultObject = std::make_shared<Order>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(orderId);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid ID supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "Order not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
int StoreApiStoreOrderOrderIdResource::handler_DELETE(
|
||||
std::string const & orderId)
|
||||
{
|
||||
throw StoreApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::pair<int, std::shared_ptr<Order>> StoreApiStoreOrderOrderIdResource::handler_GET(
|
||||
int64_t const & orderId)
|
||||
{
|
||||
throw StoreApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::string StoreApiStoreOrderOrderIdResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
StoreApiStoreInventoryResource::StoreApiStoreInventoryResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/inventory/");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&StoreApiStoreInventoryResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
StoreApiStoreInventoryResource::~StoreApiStoreInventoryResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreInventoryResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreInventoryResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreInventoryResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreApiStoreInventoryResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreApiStoreInventoryResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void StoreApiStoreInventoryResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreApiStoreInventoryResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::map<std::string, int32_t> resultObject = std::map<std::string, int32_t>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET();
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
result = convertMapResponse(resultObject);
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::map<std::string, int32_t>> StoreApiStoreInventoryResource::handler_GET(
|
||||
)
|
||||
{
|
||||
throw StoreApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string StoreApiStoreInventoryResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
StoreApiStoreOrderResource::StoreApiStoreOrderResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/store/order/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&StoreApiStoreOrderResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
StoreApiStoreOrderResource::~StoreApiStoreOrderResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderResource::handleStoreApiException(const StoreApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> StoreApiStoreOrderResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void StoreApiStoreOrderResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto order = extractJsonModelBodyParam<Order>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<Order> resultObject = std::make_shared<Order>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_POST(order);
|
||||
}
|
||||
catch(const StoreApiException& e) {
|
||||
std::tie(status_code, result) = handleStoreApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid Order" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::shared_ptr<Order>> StoreApiStoreOrderResource::handler_POST(
|
||||
std::shared_ptr<Order> const & order)
|
||||
{
|
||||
throw StoreApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string StoreApiStoreOrderResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
StoreApi::StoreApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
StoreApi::~StoreApi() {}
|
||||
|
||||
void StoreApi::setStoreApiStoreOrderOrderIdResource(std::shared_ptr<StoreApiStoreOrderOrderIdResource> spStoreApiStoreOrderOrderIdResource) {
|
||||
m_spStoreApiStoreOrderOrderIdResource = spStoreApiStoreOrderOrderIdResource;
|
||||
m_service->publish(m_spStoreApiStoreOrderOrderIdResource);
|
||||
}
|
||||
void StoreApi::setStoreApiStoreInventoryResource(std::shared_ptr<StoreApiStoreInventoryResource> spStoreApiStoreInventoryResource) {
|
||||
m_spStoreApiStoreInventoryResource = spStoreApiStoreInventoryResource;
|
||||
m_service->publish(m_spStoreApiStoreInventoryResource);
|
||||
}
|
||||
void StoreApi::setStoreApiStoreOrderResource(std::shared_ptr<StoreApiStoreOrderResource> spStoreApiStoreOrderResource) {
|
||||
m_spStoreApiStoreOrderResource = spStoreApiStoreOrderResource;
|
||||
m_service->publish(m_spStoreApiStoreOrderResource);
|
||||
}
|
||||
|
||||
|
||||
void StoreApi::publishDefaultResources() {
|
||||
if (!m_spStoreApiStoreOrderOrderIdResource) {
|
||||
setStoreApiStoreOrderOrderIdResource(std::make_shared<StoreApiStoreOrderOrderIdResource>());
|
||||
}
|
||||
if (!m_spStoreApiStoreInventoryResource) {
|
||||
setStoreApiStoreInventoryResource(std::make_shared<StoreApiStoreInventoryResource>());
|
||||
}
|
||||
if (!m_spStoreApiStoreOrderResource) {
|
||||
setStoreApiStoreOrderResource(std::make_shared<StoreApiStoreOrderResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> StoreApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
250
samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.h
Normal file
250
samples/server/petstore/cpp-restbed-deprecated/api/StoreApi.h
Normal file
@@ -0,0 +1,250 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* StoreApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef StoreApi_H_
|
||||
#define StoreApi_H_
|
||||
|
||||
|
||||
#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 "Order.h"
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
///
|
||||
/// Exception to flag problems in the handlers
|
||||
///
|
||||
class StoreApiException: public std::exception
|
||||
{
|
||||
public:
|
||||
StoreApiException(int status_code, std::string what);
|
||||
|
||||
int getStatus() const;
|
||||
const char* what() const noexcept override;
|
||||
|
||||
private:
|
||||
int m_status;
|
||||
std::string m_what;
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Delete purchase order by ID
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
|
||||
/// </remarks>
|
||||
class StoreApiStoreOrderOrderIdResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreApiStoreOrderOrderIdResource(const std::string& context = "/v2");
|
||||
virtual ~StoreApiStoreOrderOrderIdResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_DELETE(
|
||||
std::string const & orderId);
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Order>> handler_GET(
|
||||
int64_t const & orderId);
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
virtual std::string getPathParam_orderId(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("orderId", "");
|
||||
}
|
||||
|
||||
|
||||
virtual int64_t getPathParam_orderId_x_extension(const std::shared_ptr<const restbed::Request>& request)
|
||||
{
|
||||
return request->get_path_parameter("orderId", 0L);
|
||||
}
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& 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:
|
||||
void handler_DELETE_internal(const std::shared_ptr<restbed::Session> session);
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns pet inventories by status
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Returns a map of status codes to quantities
|
||||
/// </remarks>
|
||||
class StoreApiStoreInventoryResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreApiStoreInventoryResource(const std::string& context = "/v2");
|
||||
virtual ~StoreApiStoreInventoryResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::map<std::string, int32_t>> handler_GET(
|
||||
);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& 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:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Place an order for a pet
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class StoreApiStoreOrderResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
StoreApiStoreOrderResource(const std::string& context = "/v2");
|
||||
virtual ~StoreApiStoreOrderResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual std::pair<int, std::shared_ptr<Order>> handler_POST(
|
||||
std::shared_ptr<Order> const & order);
|
||||
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////
|
||||
// Override these for customization //
|
||||
//////////////////////////////////////
|
||||
|
||||
virtual std::string extractBodyContent(const std::shared_ptr<restbed::Session>& session);
|
||||
|
||||
|
||||
|
||||
virtual std::pair<int, std::string> handleStoreApiException(const StoreApiException& 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:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class StoreApi
|
||||
{
|
||||
public:
|
||||
explicit StoreApi(std::shared_ptr<restbed::Service> const& restbedService);
|
||||
virtual ~StoreApi();
|
||||
|
||||
virtual void setStoreApiStoreOrderOrderIdResource(std::shared_ptr<StoreApiStoreOrderOrderIdResource> spStoreApiStoreOrderOrderIdResource);
|
||||
virtual void setStoreApiStoreInventoryResource(std::shared_ptr<StoreApiStoreInventoryResource> spStoreApiStoreInventoryResource);
|
||||
virtual void setStoreApiStoreOrderResource(std::shared_ptr<StoreApiStoreOrderResource> spStoreApiStoreOrderResource);
|
||||
|
||||
virtual void publishDefaultResources();
|
||||
|
||||
virtual std::shared_ptr<restbed::Service> service();
|
||||
|
||||
protected:
|
||||
std::shared_ptr<StoreApiStoreOrderOrderIdResource> m_spStoreApiStoreOrderOrderIdResource;
|
||||
std::shared_ptr<StoreApiStoreInventoryResource> m_spStoreApiStoreInventoryResource;
|
||||
std::shared_ptr<StoreApiStoreOrderResource> m_spStoreApiStoreOrderResource;
|
||||
|
||||
private:
|
||||
std::shared_ptr<restbed::Service> m_service;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* StoreApi_H_ */
|
||||
|
||||
870
samples/server/petstore/cpp-restbed-deprecated/api/UserApi.cpp
Normal file
870
samples/server/petstore/cpp-restbed-deprecated/api/UserApi.cpp
Normal file
@@ -0,0 +1,870 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
|
||||
#include <corvusoft/restbed/byte.hpp>
|
||||
#include <corvusoft/restbed/string.hpp>
|
||||
#include <corvusoft/restbed/settings.hpp>
|
||||
#include <corvusoft/restbed/request.hpp>
|
||||
#include <corvusoft/restbed/uri.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "UserApi.h"
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
namespace api {
|
||||
|
||||
using namespace org::openapitools::server::model;
|
||||
|
||||
UserApiException::UserApiException(int status_code, std::string what)
|
||||
: m_status(status_code),
|
||||
m_what(what)
|
||||
{
|
||||
|
||||
}
|
||||
int UserApiException::getStatus() const
|
||||
{
|
||||
return m_status;
|
||||
}
|
||||
const char* UserApiException::what() const noexcept
|
||||
{
|
||||
return m_what.c_str();
|
||||
}
|
||||
|
||||
|
||||
template<class MODEL_T>
|
||||
std::shared_ptr<MODEL_T> extractJsonModelBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto model = std::make_shared<MODEL_T>(pt);
|
||||
return model;
|
||||
}
|
||||
|
||||
template<class MODEL_T>
|
||||
std::vector<std::shared_ptr<MODEL_T>> extractJsonArrayBodyParam(const std::string& bodyContent)
|
||||
{
|
||||
std::stringstream sstream(bodyContent);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::json_parser::read_json(sstream, pt);
|
||||
|
||||
auto arrayRet = std::vector<std::shared_ptr<MODEL_T>>();
|
||||
for (const auto& child: pt) {
|
||||
arrayRet.emplace_back(std::make_shared<MODEL_T>(child.second));
|
||||
}
|
||||
return arrayRet;
|
||||
}
|
||||
|
||||
template <class KEY_T, class VAL_T>
|
||||
std::string convertMapResponse(const std::map<KEY_T, VAL_T>& map)
|
||||
{
|
||||
boost::property_tree::ptree pt;
|
||||
for(const auto &kv: map) {
|
||||
pt.push_back(boost::property_tree::ptree::value_type(
|
||||
boost::lexical_cast<std::string>(kv.first),
|
||||
boost::property_tree::ptree(
|
||||
boost::lexical_cast<std::string>(kv.second))));
|
||||
}
|
||||
std::stringstream sstream;
|
||||
write_json(sstream, pt);
|
||||
std::string result = sstream.str();
|
||||
return result;
|
||||
}
|
||||
|
||||
UserApiUserResource::UserApiUserResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserResource::~UserApiUserResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto user = extractJsonModelBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 0) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 0, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
int UserApiUserResource::handler_POST(
|
||||
std::shared_ptr<User> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string UserApiUserResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
UserApiUserCreateWithArrayResource::UserApiUserCreateWithArrayResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/createWithArray/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserCreateWithArrayResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserCreateWithArrayResource::~UserApiUserCreateWithArrayResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithArrayResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithArrayResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithArrayResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithArrayResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithArrayResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithArrayResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithArrayResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto user = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 0) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 0, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
int UserApiUserCreateWithArrayResource::handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string UserApiUserCreateWithArrayResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
UserApiUserCreateWithListResource::UserApiUserCreateWithListResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/createWithList/");
|
||||
this->set_method_handler("POST",
|
||||
std::bind(&UserApiUserCreateWithListResource::handler_POST_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserCreateWithListResource::~UserApiUserCreateWithListResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithListResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithListResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserCreateWithListResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithListResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithListResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithListResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithListResource::handler_POST_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// Get body params or form params here from the body content string
|
||||
auto user = extractJsonArrayBodyParam<User>(bodyContent);
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_POST(user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 0) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 0, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
int UserApiUserCreateWithListResource::handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string UserApiUserCreateWithListResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
UserApiUserUsernameResource::UserApiUserUsernameResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/{username: .*}/");
|
||||
this->set_method_handler("DELETE",
|
||||
std::bind(&UserApiUserUsernameResource::handler_DELETE_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserUsernameResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
this->set_method_handler("PUT",
|
||||
std::bind(&UserApiUserUsernameResource::handler_PUT_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserUsernameResource::~UserApiUserUsernameResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserUsernameResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserUsernameResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserUsernameResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::handler_DELETE_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = getPathParam_username(request);
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_DELETE(username);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid username supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "User not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
// x-extension
|
||||
void UserApiUserUsernameResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = getPathParam_username_x_extension(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::shared_ptr<User> resultObject = std::make_shared<User>();
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(username);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject->toJsonString();
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid username supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "User not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
// x-extension
|
||||
void UserApiUserUsernameResource::handler_PUT_internal(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
std::string bodyContent = extractBodyContent(session);
|
||||
|
||||
// body params or form params here from the body content string
|
||||
auto username = std::make_shared<>(bodyContent);
|
||||
auto user = extractJsonModelBodyParam<User>(bodyContent);
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = getPathParam_username_x_extension(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_PUT(username, user);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid user supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 404, result.empty() ? "User not found" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
int UserApiUserUsernameResource::handler_DELETE(
|
||||
std::string const & username)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::pair<int, std::shared_ptr<User>> UserApiUserUsernameResource::handler_GET(
|
||||
std::string const & username)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
int UserApiUserUsernameResource::handler_PUT(
|
||||
std::string const & username, std::shared_ptr<User> const & user)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
std::string UserApiUserUsernameResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
UserApiUserLoginResource::UserApiUserLoginResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/login/");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserLoginResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserLoginResource::~UserApiUserLoginResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLoginResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLoginResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLoginResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserLoginResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserLoginResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserLoginResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserLoginResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the query params
|
||||
const std::string username = getQueryParam_username(request);
|
||||
const std::string password = getQueryParam_password(request);
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string resultObject = "";
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
std::tie(status_code, resultObject) =
|
||||
handler_GET(username, password);
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
result = resultObject;
|
||||
// Description: Cookie authentication key for use with the `api_key` apiKey authentication.
|
||||
setResponseHeader(session, "Set-Cookie");
|
||||
// Description: calls per hour allowed by the user
|
||||
setResponseHeader(session, "X-Rate-Limit");
|
||||
// Description: date in UTC when token expires
|
||||
setResponseHeader(session, "X-Expires-After");
|
||||
|
||||
const constexpr auto contentType = "application/json";
|
||||
returnResponse(session, 200, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 400, result.empty() ? "Invalid username/password supplied" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
std::pair<int, std::string> UserApiUserLoginResource::handler_GET(
|
||||
std::string const & username, std::string const & password)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string UserApiUserLoginResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
UserApiUserLogoutResource::UserApiUserLogoutResource(const std::string& context /* = "/v2" */)
|
||||
{
|
||||
this->set_path(context + "/user/logout/");
|
||||
this->set_method_handler("GET",
|
||||
std::bind(&UserApiUserLogoutResource::handler_GET_internal, this,
|
||||
std::placeholders::_1));
|
||||
}
|
||||
|
||||
UserApiUserLogoutResource::~UserApiUserLogoutResource()
|
||||
{
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLogoutResource::handleUserApiException(const UserApiException& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(e.getStatus(), e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLogoutResource::handleStdException(const std::exception& e)
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, e.what());
|
||||
}
|
||||
|
||||
std::pair<int, std::string> UserApiUserLogoutResource::handleUnspecifiedException()
|
||||
{
|
||||
return std::make_pair<int, std::string>(500, "Unknown exception occurred");
|
||||
}
|
||||
|
||||
void UserApiUserLogoutResource::setResponseHeader(const std::shared_ptr<restbed::Session>& session, const std::string& header)
|
||||
{
|
||||
session->set_header(header, "");
|
||||
}
|
||||
|
||||
void UserApiUserLogoutResource::returnResponse(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result, const std::string& contentType)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"}, {"Content-Type", contentType} });
|
||||
}
|
||||
|
||||
void UserApiUserLogoutResource::defaultSessionClose(const std::shared_ptr<restbed::Session>& session, const int status, const std::string& result)
|
||||
{
|
||||
session->close(status, result, { {"Connection", "close"} });
|
||||
}
|
||||
|
||||
void UserApiUserLogoutResource::handler_GET_internal(const std::shared_ptr<restbed::Session> session)
|
||||
{
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
int status_code = 500;
|
||||
std::string result = "";
|
||||
|
||||
try {
|
||||
status_code =
|
||||
handler_GET();
|
||||
}
|
||||
catch(const UserApiException& e) {
|
||||
std::tie(status_code, result) = handleUserApiException(e);
|
||||
}
|
||||
catch(const std::exception& e) {
|
||||
std::tie(status_code, result) = handleStdException(e);
|
||||
}
|
||||
catch(...) {
|
||||
std::tie(status_code, result) = handleUnspecifiedException();
|
||||
}
|
||||
|
||||
if (status_code == 0) {
|
||||
|
||||
const constexpr auto contentType = "text/plain";
|
||||
returnResponse(session, 0, result.empty() ? "successful operation" : result, contentType);
|
||||
return;
|
||||
}
|
||||
defaultSessionClose(session, status_code, result);
|
||||
}
|
||||
|
||||
|
||||
int UserApiUserLogoutResource::handler_GET(
|
||||
)
|
||||
{
|
||||
throw UserApiException(501, "Not implemented");
|
||||
}
|
||||
|
||||
|
||||
std::string UserApiUserLogoutResource::extractBodyContent(const std::shared_ptr<restbed::Session>& session) {
|
||||
const auto request = session->get_request();
|
||||
int content_length = request->get_header("Content-Length", 0);
|
||||
std::string bodyContent;
|
||||
session->fetch(content_length,
|
||||
[&bodyContent](const std::shared_ptr<restbed::Session> session,
|
||||
const restbed::Bytes &body) {
|
||||
bodyContent = restbed::String::format(
|
||||
"%.*s\n", (int)body.size(), body.data());
|
||||
});
|
||||
return bodyContent;
|
||||
}
|
||||
|
||||
UserApi::UserApi(std::shared_ptr<restbed::Service> const& restbedService)
|
||||
: m_service(restbedService)
|
||||
{
|
||||
}
|
||||
|
||||
UserApi::~UserApi() {}
|
||||
|
||||
void UserApi::setUserApiUserResource(std::shared_ptr<UserApiUserResource> spUserApiUserResource) {
|
||||
m_spUserApiUserResource = spUserApiUserResource;
|
||||
m_service->publish(m_spUserApiUserResource);
|
||||
}
|
||||
void UserApi::setUserApiUserCreateWithArrayResource(std::shared_ptr<UserApiUserCreateWithArrayResource> spUserApiUserCreateWithArrayResource) {
|
||||
m_spUserApiUserCreateWithArrayResource = spUserApiUserCreateWithArrayResource;
|
||||
m_service->publish(m_spUserApiUserCreateWithArrayResource);
|
||||
}
|
||||
void UserApi::setUserApiUserCreateWithListResource(std::shared_ptr<UserApiUserCreateWithListResource> spUserApiUserCreateWithListResource) {
|
||||
m_spUserApiUserCreateWithListResource = spUserApiUserCreateWithListResource;
|
||||
m_service->publish(m_spUserApiUserCreateWithListResource);
|
||||
}
|
||||
void UserApi::setUserApiUserUsernameResource(std::shared_ptr<UserApiUserUsernameResource> spUserApiUserUsernameResource) {
|
||||
m_spUserApiUserUsernameResource = spUserApiUserUsernameResource;
|
||||
m_service->publish(m_spUserApiUserUsernameResource);
|
||||
}
|
||||
void UserApi::setUserApiUserLoginResource(std::shared_ptr<UserApiUserLoginResource> spUserApiUserLoginResource) {
|
||||
m_spUserApiUserLoginResource = spUserApiUserLoginResource;
|
||||
m_service->publish(m_spUserApiUserLoginResource);
|
||||
}
|
||||
void UserApi::setUserApiUserLogoutResource(std::shared_ptr<UserApiUserLogoutResource> spUserApiUserLogoutResource) {
|
||||
m_spUserApiUserLogoutResource = spUserApiUserLogoutResource;
|
||||
m_service->publish(m_spUserApiUserLogoutResource);
|
||||
}
|
||||
|
||||
|
||||
void UserApi::publishDefaultResources() {
|
||||
if (!m_spUserApiUserResource) {
|
||||
setUserApiUserResource(std::make_shared<UserApiUserResource>());
|
||||
}
|
||||
if (!m_spUserApiUserCreateWithArrayResource) {
|
||||
setUserApiUserCreateWithArrayResource(std::make_shared<UserApiUserCreateWithArrayResource>());
|
||||
}
|
||||
if (!m_spUserApiUserCreateWithListResource) {
|
||||
setUserApiUserCreateWithListResource(std::make_shared<UserApiUserCreateWithListResource>());
|
||||
}
|
||||
if (!m_spUserApiUserUsernameResource) {
|
||||
setUserApiUserUsernameResource(std::make_shared<UserApiUserUsernameResource>());
|
||||
}
|
||||
if (!m_spUserApiUserLoginResource) {
|
||||
setUserApiUserLoginResource(std::make_shared<UserApiUserLoginResource>());
|
||||
}
|
||||
if (!m_spUserApiUserLogoutResource) {
|
||||
setUserApiUserLogoutResource(std::make_shared<UserApiUserLogoutResource>());
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<restbed::Service> UserApi::service() {
|
||||
return m_service;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
417
samples/server/petstore/cpp-restbed-deprecated/api/UserApi.h
Normal file
417
samples/server/petstore/cpp-restbed-deprecated/api/UserApi.h
Normal file
@@ -0,0 +1,417 @@
|
||||
/**
|
||||
* OpenAPI Petstore
|
||||
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
|
||||
*
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
|
||||
/*
|
||||
* UserApi.h
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef UserApi_H_
|
||||
#define UserApi_H_
|
||||
|
||||
|
||||
#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>
|
||||
#include <vector>
|
||||
|
||||
namespace org {
|
||||
namespace openapitools {
|
||||
namespace server {
|
||||
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>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
class UserApiUserResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::shared_ptr<User> const & user);
|
||||
|
||||
|
||||
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:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserApiUserCreateWithArrayResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserCreateWithArrayResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserCreateWithArrayResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & user);
|
||||
|
||||
|
||||
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:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates list of users with given input array
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserApiUserCreateWithListResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserCreateWithListResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserCreateWithListResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
virtual int handler_POST(
|
||||
std::vector<std::shared_ptr<User>> const & user);
|
||||
|
||||
|
||||
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:
|
||||
void handler_POST_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Delete user
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// This can only be done by the logged in user.
|
||||
/// </remarks>
|
||||
class UserApiUserUsernameResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserUsernameResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserUsernameResource();
|
||||
|
||||
protected:
|
||||
//////////////////////////////////////////////////////////
|
||||
// Override these to implement the server functionality //
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
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 & user);
|
||||
|
||||
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:
|
||||
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>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserApiUserLoginResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserLoginResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserLoginResource();
|
||||
|
||||
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:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Logs out current logged in user session
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
class UserApiUserLogoutResource: public restbed::Resource
|
||||
{
|
||||
public:
|
||||
UserApiUserLogoutResource(const std::string& context = "/v2");
|
||||
virtual ~UserApiUserLogoutResource();
|
||||
|
||||
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:
|
||||
void handler_GET_internal(const std::shared_ptr<restbed::Session> session);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//
|
||||
// The restbed service to actually implement the REST server
|
||||
//
|
||||
class UserApi
|
||||
{
|
||||
public:
|
||||
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;
|
||||
std::shared_ptr<UserApiUserCreateWithListResource> m_spUserApiUserCreateWithListResource;
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* UserApi_H_ */
|
||||
|
||||
Reference in New Issue
Block a user