Files
zeekayandHanzo Dev 384cc08eba cpp is a row, and the version floor it left over was a fact about a document
C++ was the last language owning its own invocation, and it gave two reasons.
`templates:` retired the first one for rust already; this retires the second,
which needs saying precisely because it was true when it was written.

The floor said generator 7.24.0 against the 7.14.0 pinned here, because on
7.14.0 ten translation units would not compile through two defects in the
generator's type resolution that no template reaches — mustache interpolates the
strings resolution produces, it cannot recompute a type. Both defects were real.
Both lived in SCHEMAS THE DOCUMENT NO LONGER CARRIES: vector_NamedVectors /
vector_DenseVector under additionalProperties (9 TUs), and an integer-backed
enum declared over utility::string_t and defined over int32_t,
framework_Document.docstatus (1 TU). Neither schema exists at the ref this fleet
reads, so neither defect is reachable and the floor expired with its cause.

Re-measured rather than argued: at cloud@49389cf9, ignoring blank lines and the
generator string each file's header carries, exactly one of 5327 files differs
between 7.14.0 and 7.24.0 — a doc comment on ConsoleSettings::getOidcConfig. On
7.14.0 the library builds with 0 errors (2663 sources, 192 API classes, 2462
models, 2502 operations) and the six example flows build with 0 errors, on
aarch64 Ubuntu 24.04 with g++ 13.3. So the row needs no version of its own and
this does not raise the pin.

The four cpp-restsdk overrides move here as templates/cpp-restsdk/, next to the
flags they go with. They are load-bearing and measured: generating without them
fails with 8 errors, all in ModelBase.h.

One flag, and it is the one six other rows already carry.
o11y.GettableAgentCheckIn publishes integration_config beside integrationConfig
and removed_at beside removedAt so older agents keep working; C++ camel-cases a
property into its accessor, so each pair declared one method twice. Renaming the
accessor keeps both wire keys — measured, all four are present in the emitted
model, each under the document's own name.

`take` is include/ and src/. The generator's CMakeLists.txt, Config.cmake.in,
git_push.sh and README.md sit at the output root under neither, so they are
never copied and need no `drop` entry — the repo keeps its own build contract.

Verified against the tree the departed script produced: `generate.py cpp --check`
reports clean, byte for byte, 5327 files.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-14 20:37:43 -07:00

632 lines
18 KiB
Plaintext

{{! openapi-generator 7.24.0 cpp-rest-sdk-client/model-source.mustache, overridden.
Forked from the stock template at that exact version, so a bump
re-derives these rather than merging them. Every changed hunk carries
a comment saying which generator defect it fixes; the measurement is
in LLM.md. Nothing here says anything about the Hanzo API. }}
{{>licenseInfo}}
{{#models}}{{#model}}
#include "{{packageName}}/model/{{classFilename}}.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
{{#oneOf}}
{{#-first}}
void {{classname}}::validate()
{
// A oneOf is validated by the alternative it holds.
}
const {{classname}}::VariantType& {{classname}}::getVariant() const
{
return m_variantValue;
}
void {{classname}}::setVariant({{classname}}::VariantType value)
{
m_variantValue = value;
}
web::json::value {{classname}}::toJson() const
{
web::json::value val = web::json::value::object();
std::visit([&](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, std::monostate>) {
val = web::json::value::null();
} else {
{{! arg is a std::shared_ptr<Model> or a primitive; neither has a
toJson member. ModelBase overloads every alternative kind. }}
val = ModelBase::toJson(arg);
}
}, m_variantValue);
return val;
}
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
{
std::visit([&](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (!std::is_same_v<T, std::monostate>) {
multipart->add(ModelBase::toHttpContent(prefix, arg));
}
}, m_variantValue);
}
bool {{classname}}::fromJson(const web::json::value& json)
{
// oneOf: the first alternative that accepts the document wins, in the order
// the schema declares them.
{{#oneOf}}
{
{{{.}}} target;
if (ModelBase::fromJson(json, target))
{
m_variantValue = target;
return true;
}
}
{{/oneOf}}
return false;
}
bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix)
{
{{#oneOf}}
{
{{{.}}} target;
if (ModelBase::fromHttpContent(multipart->getContent(namePrefix), target))
{
m_variantValue = target;
return true;
}
}
{{/oneOf}}
return false;
}
{{! Triple-stache: the double form HTML-escapes an alternative whose spelling
is a template, emitting fromJson<std::shared_ptr&lt;Object&gt;>, which is
never valid C++. }}
{{#oneOf}}
template bool {{classname}}::fromJson<{{{.}}}>(const web::json::value& json);
template bool {{classname}}::fromMultiPart<{{{.}}}>(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix);
{{/oneOf}}
{{/-first}}
{{/oneOf}}
{{^oneOf}}
{{#isEnum}}
namespace
{
using EnumUnderlyingType = {{#isNumeric}}int64_t{{/isNumeric}}{{^isNumeric}}utility::string_t{{/isNumeric}};
{{classname}}::e{{classname}} toEnum(const EnumUnderlyingType& val)
{
{{#allowableValues}}
{{#isNumeric}}
switch (val)
{
{{#enumVars}}
case {{value}}:
return {{classname}}::e{{classname}}::{{name}};
{{#-last}}
default:
break;
{{/-last}}
{{/enumVars}}
}
{{/isNumeric}}
{{^isNumeric}}
{{#enumVars}}
if (val == utility::conversions::to_string_t(_XPLATSTR("{{{value}}}")))
return {{classname}}::e{{classname}}::{{name}};
{{/enumVars}}
{{/isNumeric}}
{{/allowableValues}}
return {};
}
EnumUnderlyingType fromEnum({{classname}}::e{{classname}} e)
{
{{#allowableValues}}
switch (e)
{
{{#enumVars}}
case {{classname}}::e{{classname}}::{{name}}:
return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}_XPLATSTR("{{value}}"){{/isNumeric}};
{{#-last}}
default:
break;
{{/-last}}
{{/enumVars}}
}
{{/allowableValues}}
return {};
}
}
{{classname}}::{{classname}}()
{
}
{{classname}}::~{{classname}}()
{
}
void {{classname}}::validate()
{
// TODO: implement validation
}
web::json::value {{classname}}::toJson() const
{
auto val = fromEnum(m_value);
return web::json::value(val);
}
bool {{classname}}::fromJson(const web::json::value& val)
{
m_value = toEnum({{#isNumeric}}val.as_number().to_int64(){{/isNumeric}}{{^isNumeric}}val.as_string(){{/isNumeric}});
return true;
}
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
{
utility::string_t namePrefix = prefix;
if (!namePrefix.empty() && namePrefix.back() != _XPLATSTR('.'))
{
namePrefix.push_back(_XPLATSTR('.'));
}
auto e = fromEnum(m_value);
multipart->add(ModelBase::toHttpContent(namePrefix, e));
}
bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if (!namePrefix.empty() && namePrefix.back() != _XPLATSTR('.'))
{
namePrefix.push_back(_XPLATSTR('.'));
}
{
EnumUnderlyingType e;
ok = ModelBase::fromHttpContent(multipart->getContent(namePrefix), e);
if (ok)
{
auto v = toEnum(e);
setValue(v);
}
}
return ok;
}
{{classname}}::e{{classname}} {{classname}}::getValue() const
{
return m_value;
}
void {{classname}}::setValue({{classname}}::e{{classname}} const value)
{
m_value = value;
}
{{classname}}::{{classname}}(utility::string_t str){
setValue( strToEnumMap[str] );
}
{{/isEnum}}
{{^isEnum}}
{{classname}}::{{classname}}()
{
{{#vars}}
{{^isInherited}}
{{^isNullable}}
{{^isContainer}}
{{^isEnum}}
{{#isPrimitiveType}}
m_{{name}} = {{{defaultValue}}};
{{/isPrimitiveType}}
{{^isPrimitiveType}}
{{#isString}}
m_{{name}} = {{{defaultValue}}};
{{/isString}}
{{#isDateTime}}
m_{{name}} = {{{defaultValue}}};
{{/isDateTime}}
{{/isPrimitiveType}}
{{/isEnum}}
{{/isContainer}}
m_{{name}}IsSet = false;
{{/isNullable}}
{{/isInherited}}
{{/vars}}
{{#additionalPropertiesType}}
m_AdditionalPropertiesIsSet = false;
{{/additionalPropertiesType}}
}
{{classname}}::~{{classname}}()
{
}
void {{classname}}::validate()
{
// TODO: implement validation
}
web::json::value {{classname}}::toJson() const
{
{{#parent}}
web::json::value val = this->{{{.}}}::toJson();
{{/parent}}
{{^parent}}
web::json::value val = web::json::value::object();
{{/parent}}
{{#vars}}
{{^isInherited}}
{{#isNullable}}
if(m_{{name}}.has_value())
{
{{#isEnum}}{{#isContainer}}{{#isArray}}
{{{dataType}}} refVal = from{{{enumName}}}(m_{{name}}.get());
{{/isArray}}{{#isMap}}
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}}.get());
{{/isMap}}{{/isContainer}}{{^isContainer}}
{{{dataType}}} refVal = from{{{datatypeWithEnum}}}(m_{{name}}.get());
{{/isContainer}}{{^isMap}}val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(refVal);
{{/isMap}}{{/isEnum}}
{{^isEnum}}
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}}.get());
{{/isEnum}}
}
{{/isNullable}}
{{^isNullable}}
if(m_{{name}}IsSet)
{
{{#isEnum}}{{#isContainer}}{{#isArray}}
{{{dataType}}} refVal = from{{{enumName}}}(m_{{name}});
{{/isArray}}{{#isMap}}
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
{{/isMap}}{{/isContainer}}{{^isContainer}}
{{{dataType}}} refVal = from{{{datatypeWithEnum}}}(m_{{name}});
{{/isContainer}}{{^isMap}}val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(refVal);
{{/isMap}}{{/isEnum}}
{{^isEnum}}
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
{{/isEnum}}
}
{{/isNullable}}
{{/isInherited}}
{{/vars}}
{{#additionalPropertiesType}}
// Serialize additional properties
if(m_AdditionalPropertiesIsSet)
{
for(const auto& item : m_AdditionalProperties)
{
val[item.first] = item.second;
}
}
{{/additionalPropertiesType}}
return val;
}
bool {{classname}}::fromJson(const web::json::value& val)
{
bool ok = true;
{{#parent}}
ok &= this->{{{.}}}::fromJson(val);
{{/parent}}
{{#vars}}
{{^isInherited}}
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))))
{
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")));
if(!fieldValue.is_null())
{
{{{dataType}}} refVal_{{setter}};
ok &= ModelBase::fromJson(fieldValue, refVal_{{setter}});
{{^isEnum}}
{{setter}}(refVal_{{setter}});
{{/isEnum}}
{{#isEnum}}{{#isContainer}}{{#isArray}}
{{setter}}(to{{{enumName}}}(refVal_{{setter}}));
{{/isArray}}{{#isMap}}
{{setter}}(refVal_{{setter}});
{{/isMap}}{{/isContainer}}{{^isContainer}}
{{setter}}(to{{{datatypeWithEnum}}}(refVal_{{setter}}));
{{/isContainer}}{{/isEnum}}
}
}
{{/isInherited}}
{{/vars}}
{{#additionalPropertiesType}}
// Capture additional properties (keys not defined in the schema)
if(val.is_object())
{
for(const auto& item : val.as_object())
{
// Skip known properties
{{#vars}}
{{^isInherited}}
if(item.first == utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))) continue;
{{/isInherited}}
{{/vars}}
// This is an additional property
m_AdditionalProperties[item.first] = item.second;
m_AdditionalPropertiesIsSet = true;
}
}
{{/additionalPropertiesType}}
return ok;
}
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
{
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
{
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
}
{{#vars}}
{{#isNullable}}
if(m_{{name}}.has_value())
{
{{^isEnum}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}.get()));
{{/isEnum}}
{{#isEnum}}
{{#isContainer}}
{{#isArray}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{enumName}}}(m_{{name}}.get())));
{{/isArray}}{{#isMap}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}.get()));
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{datatypeWithEnum}}}(m_{{name}}.get())));
{{/isContainer}}
{{/isEnum}}
}
{{/isNullable}}
{{^isNullable}}
if(m_{{name}}IsSet)
{
{{^isEnum}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}));
{{/isEnum}}
{{#isEnum}}
{{#isContainer}}
{{#isArray}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{enumName}}}(m_{{name}})));
{{/isArray}}{{#isMap}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}));
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{datatypeWithEnum}}}(m_{{name}})));
{{/isContainer}}
{{/isEnum}}
}
{{/isNullable}}
{{/vars}}
}
bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
{
bool ok = true;
utility::string_t namePrefix = prefix;
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
{
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
}
{{#vars}}
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))))
{
{{{dataType}}} refVal_{{setter}};
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))), refVal_{{setter}} );
{{^isEnum}}
{{setter}}(refVal_{{setter}});
{{/isEnum}}
{{#isEnum}}
{{#isContainer}}
{{#isArray}}
{{setter}}(to{{{enumName}}}(refVal_{{setter}}));
{{/isArray}}
{{#isMap}}
{{setter}}(refVal_{{setter}});
{{/isMap}}
{{/isContainer}}
{{^isContainer}}
{{setter}}(to{{{datatypeWithEnum}}}(refVal_{{setter}}));
{{/isContainer}}
{{/isEnum}}
}
{{/vars}}
return ok;
}
{{#vars}}
{{^isInherited}}
{{#isEnum}}
{{#isContainer}}
{{classname}}::{{{enumName}}} {{classname}}::to{{{enumName}}}(const utility::string_t& value) const
{{/isContainer}}
{{^isContainer}}
{{classname}}::{{{datatypeWithEnum}}} {{classname}}::to{{{datatypeWithEnum}}}(const {{dataType}}& value) const
{{/isContainer}}
{
{{#allowableValues}}{{#enumVars}}
{{! the property is numeric: its enum values are C++ literals, not
quoted strings, and the helper above now takes the numeric type. }}
if (value == {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}utility::conversions::to_string_t("{{value}}"){{/isNumeric}}) {
return {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{name}};
}
{{/enumVars}}{{/allowableValues}}
throw std::invalid_argument("Invalid value for conversion to {{{datatypeWithEnum}}}");
}
{{#isContainer}}
const utility::string_t {{classname}}::from{{{enumName}}}(const {{{enumName}}} value) const
{{/isContainer}}{{^isContainer}}
const {{dataType}} {{classname}}::from{{{datatypeWithEnum}}}(const {{{datatypeWithEnum}}} value) const
{{/isContainer}}
{
switch(value)
{
{{#allowableValues}}{{#enumVars}}
case {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{name}}: return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}utility::conversions::to_string_t("{{value}}"){{/isNumeric}};
{{/enumVars}}{{/allowableValues}}
}
}
{{#isContainer}}
{{#isArray}}
{{{dataType}}} {{{classname}}}::from{{{enumName}}}(const {{{datatypeWithEnum}}}& value) const
{
{{{dataType}}} ret;
for (auto it = value.begin(); it != value.end(); it++) {
ret.push_back(from{{{enumName}}}(*it));
}
return ret;
}
{{{baseType}}}<{{classname}}::{{{enumName}}}> {{{classname}}}::to{{{enumName}}}(const {{{dataType}}}& value) const
{
{{{datatypeWithEnum}}} ret;
for (auto it = value.begin(); it != value.end(); it++) {
ret.push_back(to{{{enumName}}}(*it));
}
return ret;
}
{{/isArray}}
{{/isContainer}}
{{/isEnum}}
{{/isInherited}}
{{/vars}}
{{#vars}}
{{^isInherited}}
{{#isContainer}}
{{^isEnum}}
{{{dataType}}} {{classname}}::{{getter}}() const
{
{{#isNullable}}
return m_{{name}}.get();
{{/isNullable}}
{{^isNullable}}
return m_{{name}};
{{/isNullable}}
}
{{/isEnum}}
{{/isContainer}}
{{^isContainer}}
{{^isEnum}}
{{{dataType}}} {{classname}}::{{getter}}() const
{
{{#isNullable}}
return m_{{name}}.get();
{{/isNullable}}
{{^isNullable}}
return m_{{name}};
{{/isNullable}}
}
{{/isEnum}}
{{/isContainer}}
{{#isEnum}}
{{^isMap}}{{#isArray}}{{{baseType}}}<{{/isArray}}{{{classname}}}::{{{enumName}}}{{#isArray}}>{{/isArray}}{{/isMap}}{{#isMap}}{{{dataType}}}{{/isMap}} {{classname}}::{{getter}}() const
{
{{#isNullable}}
return m_{{name}}.get();
{{/isNullable}}
{{^isNullable}}
return m_{{name}};
{{/isNullable}}
}
{{/isEnum}}
{{#isPrimitiveType}}{{^isEnum}}
void {{classname}}::{{setter}}({{{dataType}}} value)
{{/isEnum}}{{/isPrimitiveType}}{{^isPrimitiveType}}{{^isEnum}}
void {{classname}}::{{setter}}(const {{{dataType}}}& value)
{{/isEnum}}{{/isPrimitiveType}}{{#isEnum}}
void {{classname}}::{{setter}}(const {{^isMap}}{{{datatypeWithEnum}}}{{/isMap}}{{#isMap}}{{{dataType}}}{{/isMap}} value)
{{/isEnum}}
{
m_{{name}} = value;
{{^isNullable}}
m_{{name}}IsSet = true;
{{/isNullable}}
}
bool {{classname}}::{{nameInCamelCase}}IsSet() const
{
{{#isNullable}}
return m_{{name}}.has_value();
{{/isNullable}}
{{^isNullable}}
return m_{{name}}IsSet;
{{/isNullable}}
}
void {{classname}}::unset{{name}}()
{
{{#isNullable}}
m_{{name}}.reset();
{{/isNullable}}
{{^isNullable}}
m_{{name}}IsSet = false;
{{/isNullable}}
}
{{/isInherited}}{{/vars}}
{{#additionalPropertiesType}}
std::map<utility::string_t, web::json::value> {{classname}}::getAdditionalProperties() const
{
return m_AdditionalProperties;
}
void {{classname}}::setAdditionalProperties(const std::map<utility::string_t, web::json::value>& value)
{
m_AdditionalProperties = value;
m_AdditionalPropertiesIsSet = true;
}
void {{classname}}::addAdditionalProperty(const utility::string_t& key, const web::json::value& value)
{
m_AdditionalProperties[key] = value;
m_AdditionalPropertiesIsSet = true;
}
bool {{classname}}::additionalPropertiesIsSet() const
{
return m_AdditionalPropertiesIsSet;
}
void {{classname}}::unsetAdditionalProperties()
{
m_AdditionalProperties.clear();
m_AdditionalPropertiesIsSet = false;
}
{{/additionalPropertiesType}}
{{/isEnum}}
{{/oneOf}}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
{{/model}}
{{/models}}