/** * Swagger Petstore * This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters. * * OpenAPI spec version: 1.0.0 * Contact: apiteam@swagger.io * * NOTE: This class is auto generated by the swagger code generator program. * https://github.com/swagger-api/swagger-codegen.git * Do not edit the class manually. */ #include #include #include #include #include "UserApi.h" namespace io { namespace swagger { namespace server { namespace api { using namespace io::swagger::server::model; UserApi::UserApi() { std::shared_ptr spUserApiCreateUserResource = std::make_shared(); this->publish(spUserApiCreateUserResource); std::shared_ptr spUserApiCreateUsersWithArrayInputResource = std::make_shared(); this->publish(spUserApiCreateUsersWithArrayInputResource); std::shared_ptr spUserApiCreateUsersWithListInputResource = std::make_shared(); this->publish(spUserApiCreateUsersWithListInputResource); std::shared_ptr spUserApiDeleteUserResource = std::make_shared(); this->publish(spUserApiDeleteUserResource); std::shared_ptr spUserApiLoginUserResource = std::make_shared(); this->publish(spUserApiLoginUserResource); std::shared_ptr spUserApiLogoutUserResource = std::make_shared(); this->publish(spUserApiLogoutUserResource); } UserApi::~UserApi() {} void UserApi::startService(int const& port) { std::shared_ptr settings = std::make_shared(); settings->set_port(port); settings->set_root("/v2"); this->start(settings); } void UserApi::stopService() { this->stop(); } UserApiCreateUserResource::UserApiCreateUserResource() { this->set_path("/user/"); this->set_method_handler("POST", std::bind(&UserApiCreateUserResource::POST_method_handler, this, std::placeholders::_1)); } UserApiCreateUserResource::~UserApiCreateUserResource() { } void UserApiCreateUserResource::POST_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Body params are present, therefore we have to fetch them int content_length = request->get_header("Content-Length", 0); session->fetch(content_length, [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) { const auto request = session->get_request(); std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); /** * Get body params or form params here from the requestBody string */ // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 0) { session->close(0, "successful operation", { {"Connection", "close"} }); return; } }); } UserApiCreateUsersWithArrayInputResource::UserApiCreateUsersWithArrayInputResource() { this->set_path("/user/createWithArray/"); this->set_method_handler("POST", std::bind(&UserApiCreateUsersWithArrayInputResource::POST_method_handler, this, std::placeholders::_1)); } UserApiCreateUsersWithArrayInputResource::~UserApiCreateUsersWithArrayInputResource() { } void UserApiCreateUsersWithArrayInputResource::POST_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Body params are present, therefore we have to fetch them int content_length = request->get_header("Content-Length", 0); session->fetch(content_length, [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) { const auto request = session->get_request(); std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); /** * Get body params or form params here from the requestBody string */ // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 0) { session->close(0, "successful operation", { {"Connection", "close"} }); return; } }); } UserApiCreateUsersWithListInputResource::UserApiCreateUsersWithListInputResource() { this->set_path("/user/createWithList/"); this->set_method_handler("POST", std::bind(&UserApiCreateUsersWithListInputResource::POST_method_handler, this, std::placeholders::_1)); } UserApiCreateUsersWithListInputResource::~UserApiCreateUsersWithListInputResource() { } void UserApiCreateUsersWithListInputResource::POST_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Body params are present, therefore we have to fetch them int content_length = request->get_header("Content-Length", 0); session->fetch(content_length, [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) { const auto request = session->get_request(); std::string requestBody = restbed::String::format("%.*s\n", ( int ) body.size( ), body.data( )); /** * Get body params or form params here from the requestBody string */ // Change the value of this variable to the appropriate response before sending the response int status_code = 200; /** * Process the received information here */ if (status_code == 0) { session->close(0, "successful operation", { {"Connection", "close"} }); return; } }); } UserApiDeleteUserResource::UserApiDeleteUserResource() { this->set_path("/user/{username: .*}/"); this->set_method_handler("DELETE", std::bind(&UserApiDeleteUserResource::DELETE_method_handler, this, std::placeholders::_1)); this->set_method_handler("GET", std::bind(&UserApiDeleteUserResource::GET_method_handler, this, std::placeholders::_1)); this->set_method_handler("PUT", std::bind(&UserApiDeleteUserResource::PUT_method_handler, this, std::placeholders::_1)); } UserApiDeleteUserResource::~UserApiDeleteUserResource() { } void UserApiDeleteUserResource::DELETE_method_handler(const std::shared_ptr 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 */ if (status_code == 400) { session->close(400, "Invalid username supplied", { {"Connection", "close"} }); return; } if (status_code == 404) { session->close(404, "User not found", { {"Connection", "close"} }); return; } } void UserApiDeleteUserResource::GET_method_handler(const std::shared_ptr 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 */ if (status_code == 200) { std::shared_ptr response = NULL; session->close(200, "successful operation", { {"Connection", "close"} }); return; } if (status_code == 400) { session->close(400, "Invalid username supplied", { {"Connection", "close"} }); return; } if (status_code == 404) { session->close(404, "User not found", { {"Connection", "close"} }); return; } } void UserApiDeleteUserResource::PUT_method_handler(const std::shared_ptr session) { const auto request = session->get_request(); // Body params are present, therefore we have to fetch them int content_length = request->get_header("Content-Length", 0); session->fetch(content_length, [ this ]( const std::shared_ptr session, const restbed::Bytes & body ) { const auto request = session->get_request(); std::string requestBody = 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 */ if (status_code == 400) { session->close(400, "Invalid user supplied", { {"Connection", "close"} }); return; } if (status_code == 404) { session->close(404, "User not found", { {"Connection", "close"} }); return; } }); } UserApiLoginUserResource::UserApiLoginUserResource() { this->set_path("/user/login/"); this->set_method_handler("GET", std::bind(&UserApiLoginUserResource::GET_method_handler, this, std::placeholders::_1)); } UserApiLoginUserResource::~UserApiLoginUserResource() { } void UserApiLoginUserResource::GET_method_handler(const std::shared_ptr 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 */ 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"} }); return; } if (status_code == 400) { session->close(400, "Invalid username/password supplied", { {"Connection", "close"} }); return; } } UserApiLogoutUserResource::UserApiLogoutUserResource() { this->set_path("/user/logout/"); this->set_method_handler("GET", std::bind(&UserApiLogoutUserResource::GET_method_handler, this, std::placeholders::_1)); } UserApiLogoutUserResource::~UserApiLogoutUserResource() { } void UserApiLogoutUserResource::GET_method_handler(const std::shared_ptr 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 */ if (status_code == 0) { session->close(0, "successful operation", { {"Connection", "close"} }); return; } } } } } }