All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cpp-pistache-server.model-struct-header.mustache Maven / Gradle / Ivy

There is a newer version: 7.7.0
Show newest version
{{>licenseInfo}}
{{#models}}{{#model}}/*
 * {{classname}}.h
 *
 * {{description}}
 */

#ifndef {{classname}}_H_
#define {{classname}}_H_

{{{defaultInclude}}}
{{#imports}}{{{this}}}
{{/imports}}
#include 
{{#hasOptional}}#include {{/hasOptional}}

namespace {{modelNamespace}}
{

struct {{declspec}} {{classname}}
{
    {{#isEnum}}{{#allowableValues}}
    enum e{{classname}} {
        // To have a valid default value.
        // Avoiding name clashes with user defined
        // enum values
        INVALID_VALUE_OPENAPI_GENERATED = 0,
        {{#enumVars}}
        {{{name}}}{{^-last}}, {{/-last}}
        {{/enumVars}}
    };{{/allowableValues}}{{/isEnum}}

    {{#vars}}
    {{^required}}std::optional<{{/required}}{{{dataType}}}{{^required}}>{{/required}} {{name}};
    {{/vars}}
    {{#isEnum}}{{classname}}::e{{classname}} value = {{classname}}::e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}{{{this}}} m_value;{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}

    bool operator==(const {{classname}}& other) const;
    bool operator!=(const {{classname}}& other) const;

    /// 
    /// Validate the current data in the model. Throws a ValidationException on failure.
    /// 
    void validate() const;

    /// 
    /// Validate the current data in the model. Returns false on error and writes an error
    /// message into the given stringstream.
    /// 
    bool validate(std::stringstream& msg) const;

    /// 
    /// Helper overload for validate. Used when one model stores another model and calls it's validate.
    /// Not meant to be called outside that case.
    /// 
    bool validate(std::stringstream& msg, const std::string& pathPrefix) const;

    nlohmann::json to_json() const;
    static {{classname}} from_json(const nlohmann::json& j);
};

{{declspec}} void to_json(nlohmann::json& j, const {{classname}}& o);
{{declspec}} void from_json(const nlohmann::json& j, {{classname}}& o);


} // namespace {{modelNamespace}}


#endif /* {{classname}}_H_ */
{{/model}}
{{/models}}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy