mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-21 04:27:08 +00:00
[C++][Restbed] Add handler callback methods (#2911)
* [C++][Restbed] Add handler callback methods * [C++][Restbed] Update Petstore sample
This commit is contained in:
committed by
Stefan Krismann
parent
aae97638a9
commit
87adba9c4b
@@ -2,10 +2,10 @@
|
||||
* 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.
|
||||
*
|
||||
* OpenAPI spec version: 1.0.0
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.1-SNAPSHOT.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -72,6 +72,20 @@ PetApiPetResource::~PetApiPetResource()
|
||||
{
|
||||
}
|
||||
|
||||
void PetApiPetResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
void PetApiPetResource::set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<Pet> const &
|
||||
)> handler) {
|
||||
handler_PUT_ = std::move(handler);
|
||||
}
|
||||
|
||||
void PetApiPetResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -82,23 +96,27 @@ void PetApiPetResource::POST_method_handler(const std::shared_ptr<restbed::Sessi
|
||||
{
|
||||
|
||||
const auto request = session->get_request();
|
||||
std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( ));
|
||||
std::string file = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( ));
|
||||
/**
|
||||
* Get body params or form params here from the requestBody string
|
||||
* Get body params or form params here from the file string
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_POST_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_POST_(
|
||||
body
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 405) {
|
||||
session->close(405, "Invalid input", { {"Connection", "close"} });
|
||||
session->close(405, result.empty() ? "Invalid input" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -115,28 +133,32 @@ void PetApiPetResource::PUT_method_handler(const std::shared_ptr<restbed::Sessio
|
||||
{
|
||||
|
||||
const auto request = session->get_request();
|
||||
std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( ));
|
||||
std::string file = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( ));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_PUT_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_PUT_(
|
||||
body
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid ID supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid ID supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, "Pet not found", { {"Connection", "close"} });
|
||||
session->close(404, result.empty() ? "Pet not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 405) {
|
||||
session->close(405, "Validation exception", { {"Connection", "close"} });
|
||||
session->close(405, result.empty() ? "Validation exception" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -162,26 +184,50 @@ PetApiPetPetIdResource::~PetApiPetPetIdResource()
|
||||
{
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::set_handler_DELETE(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &
|
||||
)> handler) {
|
||||
handler_DELETE_ = std::move(handler);
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
void PetApiPetPetIdResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
void PetApiPetPetIdResource::DELETE_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = request->get_path_parameter("petId", 0L);
|
||||
|
||||
|
||||
|
||||
// Getting the headers
|
||||
const std::string apiKey = request->get_header("apiKey", "");
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_DELETE_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_DELETE_(
|
||||
petId, apiKey
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid pet value", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid pet value" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -193,27 +239,31 @@ void PetApiPetPetIdResource::GET_method_handler(const std::shared_ptr<restbed::S
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = request->get_path_parameter("petId", 0L);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
petId
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
std::shared_ptr<Pet> response = NULL;
|
||||
session->close(200, "successful operation", { {"Connection", "close"} });
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid ID supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid ID supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, "Pet not found", { {"Connection", "close"} });
|
||||
session->close(404, result.empty() ? "Pet not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -224,18 +274,22 @@ void PetApiPetPetIdResource::POST_method_handler(const std::shared_ptr<restbed::
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = request->get_path_parameter("petId", 0L);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_POST_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_POST_(
|
||||
petId, name, status
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 405) {
|
||||
session->close(405, "Invalid input", { {"Connection", "close"} });
|
||||
session->close(405, result.empty() ? "Invalid input" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -254,27 +308,39 @@ PetApiPetFindByStatusResource::~PetApiPetFindByStatusResource()
|
||||
{
|
||||
}
|
||||
|
||||
void PetApiPetFindByStatusResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::string> const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void PetApiPetFindByStatusResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
// Getting the query params
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
status
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
session->close(200, "successful operation", { {"Connection", "close"} });
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid status value", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid status value" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -294,27 +360,39 @@ PetApiPetFindByTagsResource::~PetApiPetFindByTagsResource()
|
||||
{
|
||||
}
|
||||
|
||||
void PetApiPetFindByTagsResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::string> const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void PetApiPetFindByTagsResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
// Getting the query params
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
tags
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
session->close(200, "successful operation", { {"Connection", "close"} });
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid tag value", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid tag value" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -334,24 +412,36 @@ PetApiPetPetIdUploadImageResource::~PetApiPetPetIdUploadImageResource()
|
||||
{
|
||||
}
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
int64_t const &, std::string const &, std::string const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void PetApiPetPetIdUploadImageResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the path params
|
||||
const int64_t petId = request->get_path_parameter("petId", 0L);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_POST_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_POST_(
|
||||
petId, additionalMetadata, file
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
session->close(200, "successful operation", { {"Connection", "close"} });
|
||||
session->close(200, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user