forked from loafle/openapi-generator-original
* Continuing from #1317 and its PRs for pistache server string enum code generation; * A class that has an `anyOf` specification, in cpp side will have no members: in stead it should have a member having the type `classname_anyOf` * Thus, Its `==` operator is not present or wrongly filled * An string enum, should have a better usage, hence the `setEnumValue` * this PR, is a brigde between `stringenumclassname_anyOf` and `stringenumclassname` * `anyOf` specification is not just about `Enums`, so a better handling is needed from mustache templates, hence new template model parameter `isStringEnumContainer` * PR fix: muttleyxd: `double semicolon` * PR fix: wing328: `I think std::string is C++ only. What about adding x-is-string-enum-container instead in the postProcessModel operation in the C++ pistache server generator?` * PR fix: wing328: `I think std::string is C++ only...` after fix get latest codes and then generate samples Co-authored-by: Mehmet Fatih <mfyuce@netas.com.tr>
This commit is contained in:
parent
463d905664
commit
ccd031a3da
@ -218,6 +218,14 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
if(!codegenModel.isEnum
|
||||
&& codegenModel.anyOf.size()>1
|
||||
&& codegenModel.anyOf.contains("std::string")
|
||||
&& !codegenModel.anyOf.contains("AnyType")
|
||||
&& codegenModel.interfaces.size()==1
|
||||
){
|
||||
codegenModel.vendorExtensions.put("x-is-string-enum-container",true);
|
||||
}
|
||||
return codegenModel;
|
||||
}
|
||||
|
||||
|
@ -70,19 +70,22 @@ public:
|
||||
{{#isEnum}}
|
||||
{{classname}}::e{{classname}} getValue() const;
|
||||
void setValue({{classname}}::e{{classname}} value);
|
||||
{{/isEnum}}
|
||||
|
||||
{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}
|
||||
{{{this}}} getValue() const;
|
||||
void setValue({{{this}}} value);
|
||||
{{{this}}}::e{{{this}}} getEnumValue() const;
|
||||
void setEnumValue({{{this}}}::e{{{this}}} value);{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
friend void to_json(nlohmann::json& j, const {{classname}}& o);
|
||||
friend void from_json(const nlohmann::json& j, {{classname}}& o);
|
||||
friend void from_json(const nlohmann::json& j, {{classname}}& o);{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}
|
||||
friend void to_json(nlohmann::json& j, const {{{this}}}& o);
|
||||
friend void from_json(const nlohmann::json& j, {{{this}}}& o);{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
protected:
|
||||
{{#vars}}
|
||||
{{{dataType}}} m_{{name}};
|
||||
{{^required}}
|
||||
bool m_{{name}}IsSet;{{/required}}
|
||||
{{/vars}}
|
||||
{{#isEnum}}
|
||||
{{classname}}::e{{classname}} m_value = {{classname}}::e{{classname}}::INVALID_VALUE_OPENAPI_GENERATED;
|
||||
{{/isEnum}}
|
||||
{{#isEnum}}{{classname}}::e{{classname}} m_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}}
|
||||
};
|
||||
|
||||
} // namespace {{modelNamespace}}
|
||||
|
@ -60,10 +60,11 @@ bool {{classname}}::validate(std::stringstream& msg, const std::string& pathPref
|
||||
const std::string currentValuePath = _pathPrefix + ".{{nameInCamelCase}}";
|
||||
{{> model-validation-body }}
|
||||
}
|
||||
{{/hasValidation}}{{/isArray}}
|
||||
{{/vars}}
|
||||
{{/isEnum}}
|
||||
|
||||
{{/hasValidation}}{{/isArray}}{{/vars}}{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}
|
||||
if (!m_value.validate(msg))
|
||||
{
|
||||
success = false;
|
||||
}{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
return success;
|
||||
}
|
||||
|
||||
@ -71,10 +72,10 @@ bool {{classname}}::operator==(const {{classname}}& rhs) const
|
||||
{
|
||||
return
|
||||
{{#isEnum}}getValue() == rhs.getValue(){{/isEnum}}
|
||||
{{^isEnum}}{{#vars}}
|
||||
{{^isEnum}}{{#hasVars}}{{#vars}}
|
||||
{{#required}}({{getter}}() == rhs.{{getter}}()){{/required}}
|
||||
{{^required}}((!{{nameInCamelCase}}IsSet() && !rhs.{{nameInCamelCase}}IsSet()) || ({{nameInCamelCase}}IsSet() && rhs.{{nameInCamelCase}}IsSet() && {{getter}}() == rhs.{{getter}}())){{/required}}{{^-last}} &&{{/-last}}
|
||||
{{/vars}}{{/isEnum}}
|
||||
{{/vars}}{{/hasVars}}{{^hasVars}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}getValue() == rhs.getValue(){{/-first}}{{/anyOf}}{{^anyOf}}true{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}{{/hasVars}}{{/isEnum}}
|
||||
;
|
||||
}
|
||||
|
||||
@ -103,7 +104,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o)
|
||||
j = "{{value}}";
|
||||
break;
|
||||
{{/enumVars}}
|
||||
}{{/allowableValues}}{{/isEnum}}
|
||||
}{{/allowableValues}}{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}to_json(j, o.m_value);{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
}
|
||||
|
||||
void from_json(const nlohmann::json& j, {{classname}}& o)
|
||||
@ -127,7 +128,7 @@ void from_json(const nlohmann::json& j, {{classname}}& o)
|
||||
<< " {{classname}}::e{{classname}}";
|
||||
throw std::invalid_argument(ss.str());
|
||||
} {{/-last}}
|
||||
{{/enumVars}}{{/allowableValues}}{{/isEnum}}
|
||||
{{/enumVars}}{{/allowableValues}}{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}from_json(j, o.m_value);{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
}
|
||||
|
||||
{{#vars}}{{{dataType}}} {{classname}}::{{getter}}() const
|
||||
@ -156,7 +157,25 @@ void {{classname}}::unset{{name}}()
|
||||
void {{classname}}::setValue({{classname}}::e{{classname}} value)
|
||||
{
|
||||
m_value = value;
|
||||
}{{/isEnum}}
|
||||
}{{/isEnum}}{{#vendorExtensions.x-is-string-enum-container}}{{#anyOf}}{{#-first}}{{{this}}} {{classname}}::getValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void {{classname}}::setValue({{{this}}} value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
{{{this}}}::e{{{this}}} {{classname}}::getEnumValue() const
|
||||
{
|
||||
return m_value.getValue();
|
||||
}
|
||||
|
||||
void {{classname}}::setEnumValue({{{this}}}::e{{{this}}} value)
|
||||
{
|
||||
m_value.setValue(value);
|
||||
}{{/-first}}{{/anyOf}}{{/vendorExtensions.x-is-string-enum-container}}
|
||||
|
||||
} // namespace {{modelNamespace}}
|
||||
|
||||
|
@ -49,10 +49,7 @@ bool ApiResponse::validate(std::stringstream& msg, const std::string& pathPrefix
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "ApiResponse" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ protected:
|
||||
bool m_TypeIsSet;
|
||||
std::string m_Message;
|
||||
bool m_MessageIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
@ -47,9 +47,7 @@ bool Category::validate(std::stringstream& msg, const std::string& pathPrefix) c
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "Category" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,7 @@ protected:
|
||||
bool m_IdIsSet;
|
||||
std::string m_Name;
|
||||
bool m_NameIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
@ -55,13 +55,7 @@ bool Order::validate(std::stringstream& msg, const std::string& pathPrefix) cons
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "Order" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -116,6 +116,7 @@ protected:
|
||||
bool m_StatusIsSet;
|
||||
bool m_Complete;
|
||||
bool m_CompleteIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
@ -50,10 +50,7 @@ bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "Pet" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* PhotoUrls */ {
|
||||
const std::vector<std::string>& value = m_PhotoUrls;
|
||||
@ -74,8 +71,7 @@ bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (tagsIsSet())
|
||||
{
|
||||
const std::vector<Tag>& value = m_Tags;
|
||||
@ -96,9 +92,7 @@ bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -115,6 +115,7 @@ protected:
|
||||
bool m_TagsIsSet;
|
||||
std::string m_Status;
|
||||
bool m_StatusIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
@ -47,9 +47,7 @@ bool Tag::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "Tag" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,7 @@ protected:
|
||||
bool m_IdIsSet;
|
||||
std::string m_Name;
|
||||
bool m_NameIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
@ -59,15 +59,7 @@ bool User::validate(std::stringstream& msg, const std::string& pathPrefix) const
|
||||
bool success = true;
|
||||
const std::string _pathPrefix = pathPrefix.empty() ? "User" : pathPrefix;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
@ -134,6 +134,7 @@ protected:
|
||||
bool m_PhoneIsSet;
|
||||
int32_t m_UserStatus;
|
||||
bool m_UserStatusIsSet;
|
||||
|
||||
};
|
||||
|
||||
} // namespace org::openapitools::server::model
|
||||
|
Loading…
x
Reference in New Issue
Block a user