mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-21 12:47:07 +00:00
[cpp-restbed] Added "out-of-the-box" functionality (#4759)
* Added cpp-restbed "out-of-the-box" functionality * handling class dependencies * added method override to clean interfaces of ambiguity * added default values for shared pointers * fixed _name and name parameters generating the same getters and setters * updated enum handling * updated Petstore samples * updated templates for automated object generation * fix whitespace * removed model initialisation * added model brace initialisation
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
* The version of the OpenAPI document: 1.0.0
|
||||
*
|
||||
*
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator 4.2.0-SNAPSHOT.
|
||||
* NOTE: This class is auto generated by OpenAPI-Generator unset.
|
||||
* https://openapi-generator.tech
|
||||
* Do not edit the class manually.
|
||||
*/
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
@@ -30,24 +31,20 @@ namespace model {
|
||||
|
||||
Pet::Pet()
|
||||
{
|
||||
m_Id = 0L;
|
||||
m_Name = "";
|
||||
m_Status = "";
|
||||
|
||||
m_Id = 0L;
|
||||
m_Name = "";
|
||||
m_Status = "";
|
||||
m_StatusEnum = { "available", "pending", "sold" };
|
||||
}
|
||||
|
||||
Pet::~Pet()
|
||||
{
|
||||
}
|
||||
|
||||
std::string Pet::toJsonString()
|
||||
std::string Pet::toJsonString(bool prettyJson)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ptree pt;
|
||||
pt.put("id", m_Id);
|
||||
pt.put("name", m_Name);
|
||||
pt.put("status", m_Status);
|
||||
write_json(ss, pt, false);
|
||||
write_json(ss, this->toPropertyTree(), prettyJson);
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
@@ -56,9 +53,63 @@ void Pet::fromJsonString(std::string const& jsonString)
|
||||
std::stringstream ss(jsonString);
|
||||
ptree pt;
|
||||
read_json(ss,pt);
|
||||
this->fromPropertyTree(pt);
|
||||
}
|
||||
|
||||
ptree Pet::toPropertyTree()
|
||||
{
|
||||
ptree pt;
|
||||
ptree tmp_node;
|
||||
pt.put("id", m_Id);
|
||||
if (m_Category != nullptr) {
|
||||
pt.add_child("category", m_Category->toPropertyTree());
|
||||
}
|
||||
pt.put("name", m_Name);
|
||||
// generate tree for PhotoUrls
|
||||
if (!m_PhotoUrls.empty()) {
|
||||
for (const auto &childEntry : m_PhotoUrls) {
|
||||
ptree PhotoUrls_node;
|
||||
PhotoUrls_node.put("", childEntry);
|
||||
tmp_node.push_back(std::make_pair("", PhotoUrls_node));
|
||||
}
|
||||
pt.add_child("photoUrls", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
// generate tree for vector of pointers of Tags
|
||||
if (!m_Tags.empty()) {
|
||||
for (const auto &childEntry : m_Tags) {
|
||||
tmp_node.push_back(std::make_pair("", childEntry->toPropertyTree()));
|
||||
}
|
||||
pt.add_child("tags", tmp_node);
|
||||
tmp_node.clear();
|
||||
}
|
||||
pt.put("status", m_Status);
|
||||
return pt;
|
||||
}
|
||||
|
||||
void Pet::fromPropertyTree(ptree const &pt)
|
||||
{
|
||||
ptree tmp_node;
|
||||
m_Id = pt.get("id", 0L);
|
||||
if (pt.get_child_optional("category")) {
|
||||
m_Category = std::make_shared<Category>();
|
||||
m_Category->fromPropertyTree(pt.get_child("category"));
|
||||
}
|
||||
m_Name = pt.get("name", "");
|
||||
m_Status = pt.get("status", "");
|
||||
// push all items of PhotoUrls into member vector
|
||||
if (pt.get_child_optional("photoUrls")) {
|
||||
for (const auto &childTree : pt.get_child("photoUrls")) {
|
||||
m_PhotoUrls.emplace_back(childTree.second.data());
|
||||
}
|
||||
}
|
||||
// generate new Tag Object for each item and assign it to the current
|
||||
if (pt.get_child_optional("tags")) {
|
||||
for (const auto &childTree : pt.get_child("tags")) {
|
||||
m_Tags.emplace_back(std::make_shared<Tag>());
|
||||
m_Tags.back()->fromPropertyTree(childTree.second);
|
||||
}
|
||||
}
|
||||
setStatus(pt.get("status", ""));
|
||||
}
|
||||
|
||||
int64_t Pet::getId() const
|
||||
@@ -67,7 +118,7 @@ int64_t Pet::getId() const
|
||||
}
|
||||
void Pet::setId(int64_t value)
|
||||
{
|
||||
m_Id = value;
|
||||
m_Id = value;
|
||||
}
|
||||
std::shared_ptr<Category> Pet::getCategory() const
|
||||
{
|
||||
@@ -75,7 +126,7 @@ std::shared_ptr<Category> Pet::getCategory() const
|
||||
}
|
||||
void Pet::setCategory(std::shared_ptr<Category> value)
|
||||
{
|
||||
m_Category = value;
|
||||
m_Category = value;
|
||||
}
|
||||
std::string Pet::getName() const
|
||||
{
|
||||
@@ -83,7 +134,7 @@ std::string Pet::getName() const
|
||||
}
|
||||
void Pet::setName(std::string value)
|
||||
{
|
||||
m_Name = value;
|
||||
m_Name = value;
|
||||
}
|
||||
std::vector<std::string> Pet::getPhotoUrls() const
|
||||
{
|
||||
@@ -91,7 +142,7 @@ std::vector<std::string> Pet::getPhotoUrls() const
|
||||
}
|
||||
void Pet::setPhotoUrls(std::vector<std::string> value)
|
||||
{
|
||||
m_PhotoUrls = value;
|
||||
m_PhotoUrls = value;
|
||||
}
|
||||
std::vector<std::shared_ptr<Tag>> Pet::getTags() const
|
||||
{
|
||||
@@ -99,7 +150,7 @@ std::vector<std::shared_ptr<Tag>> Pet::getTags() const
|
||||
}
|
||||
void Pet::setTags(std::vector<std::shared_ptr<Tag>> value)
|
||||
{
|
||||
m_Tags = value;
|
||||
m_Tags = value;
|
||||
}
|
||||
std::string Pet::getStatus() const
|
||||
{
|
||||
@@ -107,7 +158,9 @@ std::string Pet::getStatus() const
|
||||
}
|
||||
void Pet::setStatus(std::string value)
|
||||
{
|
||||
m_Status = value;
|
||||
if (std::find(m_StatusEnum.begin(), m_StatusEnum.end(), value) != m_StatusEnum.end()) {
|
||||
m_Status = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user