mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-05-17 08:31:23 +00:00
* - Added Restbed Generator * - Added Json processing functions to model - Removed unnused code from restbed codegen class - Added response header processing to api template * Changed it to respect alphabetical order * Made the string joining java 7 compatible * Added samples * - Reworked the getter setter generation
93 lines
2.0 KiB
Plaintext
93 lines
2.0 KiB
Plaintext
{{>licenseInfo}}
|
|
{{#models}}{{#model}}
|
|
|
|
#include "{{classname}}.h"
|
|
|
|
#include <string>
|
|
#include <sstream>
|
|
#include <boost/property_tree/ptree.hpp>
|
|
#include <boost/property_tree/json_parser.hpp>
|
|
|
|
using boost::property_tree::ptree;
|
|
using boost::property_tree::read_json;
|
|
using boost::property_tree::write_json;
|
|
|
|
{{#modelNamespaceDeclarations}}
|
|
namespace {{this}} {
|
|
{{/modelNamespaceDeclarations}}
|
|
|
|
{{classname}}::{{classname}}()
|
|
{
|
|
{{#vars}}{{#isNotContainer}}{{#isPrimitiveType}}m_{{name}} = {{{defaultValue}}};
|
|
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#isString}}m_{{name}} = {{{defaultValue}}};
|
|
{{/isString}}{{#isDateTime}}m_{{name}} = {{{defaultValue}}};
|
|
{{/isDateTime}}{{/isPrimitiveType}}{{/isNotContainer}}{{/vars}}
|
|
}
|
|
|
|
{{classname}}::~{{classname}}()
|
|
{
|
|
}
|
|
|
|
std::string {{classname}}::toJsonString()
|
|
{
|
|
std::stringstream ss;
|
|
ptree pt;
|
|
{{#vars}}
|
|
{{#isNotContainer}}
|
|
{{#isPrimitiveType}}
|
|
pt.put("{{name}}", m_{{name}});
|
|
{{/isPrimitiveType}}
|
|
{{^isPrimitiveType}}
|
|
{{#isString}}
|
|
pt.put("{{name}}", m_{{name}});
|
|
{{/isString}}
|
|
{{#isDateTime}}
|
|
pt.put("{{name}}", m_{{name}});
|
|
{{/isDateTime}}
|
|
{{/isPrimitiveType}}
|
|
{{/isNotContainer}}
|
|
{{/vars}}
|
|
write_json(ss, pt, false);
|
|
return ss.str();
|
|
}
|
|
|
|
void {{classname}}::fromJsonString(std::string const& jsonString)
|
|
{
|
|
std::stringstream ss(jsonString);
|
|
ptree pt;
|
|
read_json(ss,pt);
|
|
{{#vars}}
|
|
{{#isNotContainer}}
|
|
{{#isPrimitiveType}}
|
|
m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
|
|
{{/isPrimitiveType}}
|
|
{{^isPrimitiveType}}
|
|
{{#isString}}
|
|
m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
|
|
{{/isString}}
|
|
{{#isDateTime}}
|
|
m_{{name}} = pt.get("{{name}}", {{{defaultValue}}});
|
|
{{/isDateTime}}
|
|
{{/isPrimitiveType}}
|
|
{{/isNotContainer}}
|
|
{{/vars}}
|
|
}
|
|
|
|
{{#vars}}
|
|
{{{datatype}}} {{classname}}::{{getter}}() const
|
|
{
|
|
return m_{{name}};
|
|
}
|
|
void {{classname}}::{{setter}}({{{datatype}}} value)
|
|
{
|
|
m_{{name}} = value;
|
|
}
|
|
{{/vars}}
|
|
|
|
{{#modelNamespaceDeclarations}}
|
|
}
|
|
{{/modelNamespaceDeclarations}}
|
|
|
|
{{/model}}
|
|
{{/models}}
|