Improve templates for C++ Restbed (#10543)

* Improve templates for C++ Restbed

The templates now generate classes which have virtual functions that can
be overridden to implement handlers.

* Fix missing HTTP methods in generated restbed C++ code

There was a wrong handling of "x-codegen-other-methods".

Change-Id: If6526d2672434beb5ebb0871d84cb80d84c34c38
This commit is contained in:
Lukas Woodtli
2021-10-13 07:57:40 +02:00
committed by GitHub
parent 80c3a0e4c3
commit 0023f3b7ce
24 changed files with 3569 additions and 1511 deletions

View File

@@ -5,7 +5,7 @@
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI-Generator 5.0.0-SNAPSHOT.
* NOTE: This class is auto generated by OpenAPI-Generator unset.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
@@ -15,7 +15,9 @@
#include "User.h"
#include <string>
#include <vector>
#include <sstream>
#include <stdexcept>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
@@ -28,30 +30,39 @@ namespace openapitools {
namespace server {
namespace model {
User::User()
User::User(boost::property_tree::ptree const& pt)
{
m_Id = 0L;
m_Username = "";
m_FirstName = "";
m_LastName = "";
m_Email = "";
m_Password = "";
m_Phone = "";
m_UserStatus = 0;
fromPropertyTree(pt);
}
User::~User()
std::string User::toJsonString(bool prettyJson /* = false */)
{
return toJsonString_internal(prettyJson);
}
std::string User::toJsonString(bool prettyJson)
void User::fromJsonString(std::string const& jsonString)
{
fromJsonString_internal(jsonString);
}
boost::property_tree::ptree User::toPropertyTree()
{
return toPropertyTree_internal();
}
void User::fromPropertyTree(boost::property_tree::ptree const& pt)
{
fromPropertyTree_internal(pt);
}
std::string User::toJsonString_internal(bool prettyJson)
{
std::stringstream ss;
write_json(ss, this->toPropertyTree(), prettyJson);
return ss.str();
}
void User::fromJsonString(std::string const& jsonString)
void User::fromJsonString_internal(std::string const& jsonString)
{
std::stringstream ss(jsonString);
ptree pt;
@@ -59,7 +70,7 @@ void User::fromJsonString(std::string const& jsonString)
this->fromPropertyTree(pt);
}
ptree User::toPropertyTree()
ptree User::toPropertyTree_internal()
{
ptree pt;
ptree tmp_node;
@@ -74,7 +85,7 @@ ptree User::toPropertyTree()
return pt;
}
void User::fromPropertyTree(ptree const &pt)
void User::fromPropertyTree_internal(ptree const &pt)
{
ptree tmp_node;
m_Id = pt.get("id", 0L);
@@ -91,6 +102,7 @@ int64_t User::getId() const
{
return m_Id;
}
void User::setId(int64_t value)
{
m_Id = value;
@@ -99,6 +111,7 @@ std::string User::getUsername() const
{
return m_Username;
}
void User::setUsername(std::string value)
{
m_Username = value;
@@ -107,6 +120,7 @@ std::string User::getFirstName() const
{
return m_FirstName;
}
void User::setFirstName(std::string value)
{
m_FirstName = value;
@@ -115,6 +129,7 @@ std::string User::getLastName() const
{
return m_LastName;
}
void User::setLastName(std::string value)
{
m_LastName = value;
@@ -123,6 +138,7 @@ std::string User::getEmail() const
{
return m_Email;
}
void User::setEmail(std::string value)
{
m_Email = value;
@@ -131,6 +147,7 @@ std::string User::getPassword() const
{
return m_Password;
}
void User::setPassword(std::string value)
{
m_Password = value;
@@ -139,6 +156,7 @@ std::string User::getPhone() const
{
return m_Phone;
}
void User::setPhone(std::string value)
{
m_Phone = value;
@@ -147,11 +165,26 @@ int32_t User::getUserStatus() const
{
return m_UserStatus;
}
void User::setUserStatus(int32_t value)
{
m_UserStatus = value;
}
std::vector<User> createUserVectorFromJsonString(const std::string& json)
{
std::stringstream sstream(json);
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json(sstream,pt);
auto vec = std::vector<User>();
for (const auto& child: pt) {
vec.emplace_back(User(child.second));
}
return vec;
}
}
}
}