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 "ApiResponse.h"
#include <string>
#include <vector>
#include <sstream>
#include <stdexcept>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
@@ -28,25 +30,39 @@ namespace openapitools {
namespace server {
namespace model {
ApiResponse::ApiResponse()
ApiResponse::ApiResponse(boost::property_tree::ptree const& pt)
{
m_Code = 0;
m_Type = "";
m_Message = "";
fromPropertyTree(pt);
}
ApiResponse::~ApiResponse()
std::string ApiResponse::toJsonString(bool prettyJson /* = false */)
{
return toJsonString_internal(prettyJson);
}
std::string ApiResponse::toJsonString(bool prettyJson)
void ApiResponse::fromJsonString(std::string const& jsonString)
{
fromJsonString_internal(jsonString);
}
boost::property_tree::ptree ApiResponse::toPropertyTree()
{
return toPropertyTree_internal();
}
void ApiResponse::fromPropertyTree(boost::property_tree::ptree const& pt)
{
fromPropertyTree_internal(pt);
}
std::string ApiResponse::toJsonString_internal(bool prettyJson)
{
std::stringstream ss;
write_json(ss, this->toPropertyTree(), prettyJson);
return ss.str();
}
void ApiResponse::fromJsonString(std::string const& jsonString)
void ApiResponse::fromJsonString_internal(std::string const& jsonString)
{
std::stringstream ss(jsonString);
ptree pt;
@@ -54,7 +70,7 @@ void ApiResponse::fromJsonString(std::string const& jsonString)
this->fromPropertyTree(pt);
}
ptree ApiResponse::toPropertyTree()
ptree ApiResponse::toPropertyTree_internal()
{
ptree pt;
ptree tmp_node;
@@ -64,7 +80,7 @@ ptree ApiResponse::toPropertyTree()
return pt;
}
void ApiResponse::fromPropertyTree(ptree const &pt)
void ApiResponse::fromPropertyTree_internal(ptree const &pt)
{
ptree tmp_node;
m_Code = pt.get("code", 0);
@@ -76,6 +92,7 @@ int32_t ApiResponse::getCode() const
{
return m_Code;
}
void ApiResponse::setCode(int32_t value)
{
m_Code = value;
@@ -84,6 +101,7 @@ std::string ApiResponse::getType() const
{
return m_Type;
}
void ApiResponse::setType(std::string value)
{
m_Type = value;
@@ -92,11 +110,26 @@ std::string ApiResponse::getMessage() const
{
return m_Message;
}
void ApiResponse::setMessage(std::string value)
{
m_Message = value;
}
std::vector<ApiResponse> createApiResponseVectorFromJsonString(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<ApiResponse>();
for (const auto& child: pt) {
vec.emplace_back(ApiResponse(child.second));
}
return vec;
}
}
}
}