Skip to content

Commit

Permalink
- [WIP] handling enum as api parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
mlebihan committed May 17, 2024
1 parent 52f5493 commit f675d2e
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public interface IJsonSchemaValidationProperties {
* - <code>categoryOneOf</code> is a parameter of class <code>GetAccountVideos_categoryOneOf_parameter</code>, a model parameter that correctly prefixed by its namespace: <code>org::openapitools::server::model::GetAccountVideos_categoryOneOf_parameter</code><br>
* - but that <code>GetAccountVideos_categoryOneOf_parameter</code> class is inside an <code>std::optional</code><br>
* <br>
* Then a correct generation of that parameter can be (for C++) <code>const org::openapitools::server::model::std::optional<org::openapitools::server::model::GetAccountVideos_categoryOneOf_parameter> &categoryOneOf</code><br>
* but using #isModel alone without #isOptional in mustache might produce <code>const org::openapitools::server::model::std::optional<org::openapitools::server::model::GetAccountVideos_categoryOneOf_parameter> &categoryOneOf</code> instead, that do not compile.
* Then a correct generation of that parameter can be (for C++) <code>const std::optional<org::openapitools::server::model::GetAccountVideos_categoryOneOf_parameter> &categoryOneOf</code><br>
* but using #isModel alone without #isOptional in mustache might produce <code>const org::openapitools::server::model::std::optional<org::openapitools::server::model::GetAccountVideos_categoryOneOf_parameter> &categoryOneOf</code> instead, that do not compile.
*/
boolean getIsOptional();
void setIsOptional(boolean isOptional);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private:
{{#allParams}}
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
{{/allParams}}
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{#isModel}}{{modelNamespace}}::{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
virtual void {{operationIdSnakeCase}}({{#allParams}}const {{#isModel}}{{^isOptional}}{{modelNamespace}}::{{/isOptional}}{{/isModel}}{{{dataType}}} &{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#hasParams}}, {{/hasParams}}Pistache::Http::ResponseWriter &response) = 0;
{{/vendorExtensions.x-codegen-pistache-is-parsing-supported}}
{{^vendorExtensions.x-codegen-pistache-is-parsing-supported}}
virtual void {{operationIdSnakeCase}}(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response) = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,23 @@ public:
friend {{declspec}} void from_json(const nlohmann::json& j, {{classname}}& o);{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}
friend {{declspec}} void to_json(nlohmann::json& j, const {{{this}}}& o);
friend {{declspec}} void from_json(const nlohmann::json& j, {{{this}}}& o);{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}

{{#isEnum}}
/// <summary>
/// From enumerated value e{{classname}} to string value
/// </summary>
static std::string toStringValue(const {{classname}}::e{{classname}} &value) const;
static std::string toStringValue(const {{classname}} &value) const;
{{/isEnum}}

{{#isEnum}}
/// <summary>
/// From string value to enumerated value e{{classname}}
/// </summary>
static bool fromStringValue(const std::string &inStr, {{classname}}::e{{classname}} &value);
static bool fromStringValue(const std::string &inStr, {{classname}} &value);
{{/isEnum}}

protected:
{{#vars}}
{{{dataType}}} m_{{name}};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,41 @@ void {{classname}}::setEnumValue({{{this}}}::e{{{this}}} value)
m_value.setValue(value);
}{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}

{{#isEnum}}
/// <summary>
/// From enumerated value eVideoPrivacySet to string value
/// </summary>
std::string {{classname}}::toStringValue(const {{classname}}::e{{classname}} &value)
{
return "ukn";
}

std::string {{classname}}::toStringValue(const {{classname}} &value)
{
return "ukn";
}

/// <summary>
/// From string value to enumerated value e{{classname}}
/// </summary>
bool {{classname}}::fromStringValue(const std::string &inStr, {{classname}}::e{{classname}} &value)
{
// TODO get value
{{classname}}::e{{classname}} dummy;
return true;
// TODO throw if invalid value
}

bool {{classname}}::fromStringValue(const std::string &inStr, {{classname}} &value)
{
// TODO get value
{{classname}}::e{{classname}} dummy;
return true;
// TODO throw if invalid value
}

{{/isEnum}}

} // namespace {{modelNamespace}}

{{/model}}
Expand Down

0 comments on commit f675d2e

Please sign in to comment.