forked from loafle/openapi-generator-original
[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,14 @@ UserApiUserResource::~UserApiUserResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::shared_ptr<User> const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void UserApiUserResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -82,23 +90,27 @@ void UserApiUserResource::POST_method_handler(const std::shared_ptr<restbed::Ses
|
||||
{
|
||||
|
||||
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 == 0) {
|
||||
session->close(0, "successful operation", { {"Connection", "close"} });
|
||||
session->close(0, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -119,6 +131,14 @@ UserApiUserCreateWithArrayResource::~UserApiUserCreateWithArrayResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithArrayResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void UserApiUserCreateWithArrayResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -129,23 +149,27 @@ void UserApiUserCreateWithArrayResource::POST_method_handler(const std::shared_p
|
||||
{
|
||||
|
||||
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 == 0) {
|
||||
session->close(0, "successful operation", { {"Connection", "close"} });
|
||||
session->close(0, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -166,6 +190,14 @@ UserApiUserCreateWithListResource::~UserApiUserCreateWithListResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserCreateWithListResource::set_handler_POST(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::vector<std::shared_ptr<User>> const &
|
||||
)> handler) {
|
||||
handler_POST_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void UserApiUserCreateWithListResource::POST_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
@@ -176,23 +208,27 @@ void UserApiUserCreateWithListResource::POST_method_handler(const std::shared_pt
|
||||
{
|
||||
|
||||
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 == 0) {
|
||||
session->close(0, "successful operation", { {"Connection", "close"} });
|
||||
session->close(0, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -219,28 +255,52 @@ UserApiUserUsernameResource::~UserApiUserUsernameResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::set_handler_DELETE(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler) {
|
||||
handler_DELETE_ = std::move(handler);
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
void UserApiUserUsernameResource::set_handler_PUT(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::shared_ptr<User> const &
|
||||
)> handler) {
|
||||
handler_PUT_ = std::move(handler);
|
||||
}
|
||||
|
||||
void UserApiUserUsernameResource::DELETE_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = request->get_path_parameter("username", "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_DELETE_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_DELETE_(
|
||||
username
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid username supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid username supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, "User not found", { {"Connection", "close"} });
|
||||
session->close(404, result.empty() ? "User not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -252,27 +312,31 @@ void UserApiUserUsernameResource::GET_method_handler(const std::shared_ptr<restb
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = request->get_path_parameter("username", "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_GET_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_GET_(
|
||||
username
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
std::shared_ptr<User> response = NULL;
|
||||
session->close(200, "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 username supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid username supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, "User not found", { {"Connection", "close"} });
|
||||
session->close(404, result.empty() ? "User not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -287,26 +351,30 @@ void UserApiUserUsernameResource::PUT_method_handler(const std::shared_ptr<restb
|
||||
{
|
||||
|
||||
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( ));
|
||||
|
||||
// Getting the path params
|
||||
const std::string username = request->get_path_parameter("username", "");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Change the value of this variable to the appropriate response before sending the response
|
||||
int status_code = 200;
|
||||
|
||||
/**
|
||||
* Process the received information here
|
||||
*/
|
||||
|
||||
std::string result = "successful operation";
|
||||
|
||||
if (handler_PUT_)
|
||||
{
|
||||
std::tie(status_code, result) = handler_PUT_(
|
||||
username, body
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 400) {
|
||||
session->close(400, "Invalid user supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid user supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
if (status_code == 404) {
|
||||
session->close(404, "User not found", { {"Connection", "close"} });
|
||||
session->close(404, result.empty() ? "User not found" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -326,33 +394,45 @@ UserApiUserLoginResource::~UserApiUserLoginResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserLoginResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
std::string const &, std::string const &
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void UserApiUserLoginResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
// Getting the query params
|
||||
const std::string username = request->get_query_parameter("username", "");
|
||||
const std::string password = request->get_query_parameter("password", "");
|
||||
|
||||
|
||||
|
||||
// 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_(
|
||||
username, password
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 200) {
|
||||
// Description: calls per hour allowed by the user
|
||||
session->set_header("X-Rate-Limit", ""); // Change second param to your header value
|
||||
// Description: date in UTC when toekn expires
|
||||
session->set_header("X-Expires-After", ""); // Change second param to your header value
|
||||
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 username/password supplied", { {"Connection", "close"} });
|
||||
session->close(400, result.empty() ? "Invalid username/password supplied" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -372,22 +452,34 @@ UserApiUserLogoutResource::~UserApiUserLogoutResource()
|
||||
{
|
||||
}
|
||||
|
||||
void UserApiUserLogoutResource::set_handler_GET(
|
||||
std::function<std::pair<int, std::string>(
|
||||
|
||||
)> handler) {
|
||||
handler_GET_ = std::move(handler);
|
||||
}
|
||||
|
||||
|
||||
void UserApiUserLogoutResource::GET_method_handler(const std::shared_ptr<restbed::Session> session) {
|
||||
|
||||
const auto request = session->get_request();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 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_(
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
if (status_code == 0) {
|
||||
session->close(0, "successful operation", { {"Connection", "close"} });
|
||||
session->close(0, result.empty() ? "successful operation" : std::move(result), { {"Connection", "close"} });
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user