forked from loafle/openapi-generator-original
[C++][RESTSDK] support enums (#2749)
* Support enums * Updating petstore sample * Use enum class instead of just enum * Use string_t for g++ compatibility * Add enum descriptions * Fix string parsing. Make g++ compatible.
This commit is contained in:
@@ -20,6 +20,48 @@
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
{{#isEnum}}
|
||||
class {{declspec}} {{classname}}
|
||||
: public {{#parent}}{{{parent}}}{{/parent}}{{^parent}}ModelBase{{/parent}}
|
||||
{
|
||||
public:
|
||||
{{classname}}();
|
||||
virtual ~{{classname}}();
|
||||
|
||||
/////////////////////////////////////////////
|
||||
/// ModelBase overrides
|
||||
|
||||
void validate() override;
|
||||
|
||||
web::json::value toJson() const override;
|
||||
void fromJson(const web::json::value& json) override;
|
||||
|
||||
void toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) const override;
|
||||
void fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix) override;
|
||||
|
||||
enum class e{{classname}}
|
||||
{
|
||||
{{#allowableValues}}
|
||||
{{#values}}
|
||||
{{#enumDescription}}
|
||||
/// <summary>
|
||||
/// {{enumDescription}}
|
||||
/// </summary>
|
||||
{{/enumDescription}}
|
||||
{{classname}}_{{.}}{{^last}},{{/last}}
|
||||
{{/values}}
|
||||
{{/allowableValues}}
|
||||
};
|
||||
|
||||
e{{classname}} getValue() const;
|
||||
void setValue(e{{classname}} const value);
|
||||
|
||||
protected:
|
||||
e{{classname}} m_value;
|
||||
};
|
||||
{{/isEnum}}
|
||||
{{^isEnum}}
|
||||
|
||||
/// <summary>
|
||||
/// {{description}}
|
||||
/// </summary>
|
||||
@@ -75,6 +117,8 @@ protected:
|
||||
{{/vars}}
|
||||
};
|
||||
|
||||
{{/isEnum}}
|
||||
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
@@ -7,6 +7,90 @@
|
||||
namespace {{this}} {
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
|
||||
{{#isEnum}}
|
||||
|
||||
{{classname}}::{{classname}}()
|
||||
{
|
||||
}
|
||||
|
||||
{{classname}}::~{{classname}}()
|
||||
{
|
||||
}
|
||||
|
||||
void {{classname}}::validate()
|
||||
{
|
||||
// TODO: implement validation
|
||||
}
|
||||
|
||||
web::json::value {{classname}}::toJson() const
|
||||
{
|
||||
web::json::value val = web::json::value::object();
|
||||
|
||||
{{#allowableValues}}{{#values}}
|
||||
if (m_value == e{{classname}}::{{classname}}_{{.}}) val = web::json::value::string(U("{{.}}"));{{/values}}{{/allowableValues}}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void {{classname}}::fromJson(const web::json::value& val)
|
||||
{
|
||||
auto s = val.as_string();
|
||||
|
||||
{{#allowableValues}}{{#values}}
|
||||
if (s == utility::conversions::to_string_t("{{.}}")) m_value = e{{classname}}::{{classname}}_{{.}};{{/values}}{{/allowableValues}}
|
||||
}
|
||||
|
||||
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("."))
|
||||
{
|
||||
namePrefix += utility::conversions::to_string_t(".");
|
||||
}
|
||||
|
||||
utility::string_t s;
|
||||
|
||||
{{#allowableValues}}{{#values}}
|
||||
if (m_value == e{{classname}}::{{classname}}_{{.}}) s = utility::conversions::to_string_t("{{.}}");{{/values}}{{/allowableValues}}
|
||||
|
||||
multipart->add(ModelBase::toHttpContent(namePrefix, s));
|
||||
}
|
||||
|
||||
void {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
|
||||
{
|
||||
utility::string_t namePrefix = prefix;
|
||||
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t("."))
|
||||
{
|
||||
namePrefix += utility::conversions::to_string_t(".");
|
||||
}
|
||||
|
||||
{
|
||||
utility::string_t s;
|
||||
s = ModelBase::stringFromHttpContent(multipart->getContent(namePrefix));
|
||||
e{{classname}} v;
|
||||
|
||||
{{#allowableValues}}{{#values}}
|
||||
if (s == utility::conversions::to_string_t("{{.}}")) v = e{{classname}}::{{classname}}_{{.}};{{/values}}{{/allowableValues}}
|
||||
|
||||
setValue(v);
|
||||
}
|
||||
}
|
||||
|
||||
{{classname}}::e{{classname}} {{classname}}::getValue() const
|
||||
{
|
||||
return m_value;
|
||||
}
|
||||
|
||||
void {{classname}}::setValue({{classname}}::e{{classname}} const value)
|
||||
{
|
||||
m_value = value;
|
||||
}
|
||||
|
||||
{{/isEnum}}
|
||||
|
||||
{{^isEnum}}
|
||||
|
||||
{{classname}}::{{classname}}()
|
||||
{
|
||||
{{#vars}}
|
||||
@@ -629,9 +713,11 @@ void {{classname}}::unset{{name}}()
|
||||
{{/required}}
|
||||
{{/isInherited}}
|
||||
{{/vars}}
|
||||
{{/isEnum}}
|
||||
{{#modelNamespaceDeclarations}}
|
||||
}
|
||||
{{/modelNamespaceDeclarations}}
|
||||
|
||||
|
||||
{{/model}}
|
||||
{{/models}}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
ApiResponse::ApiResponse()
|
||||
{
|
||||
m_Code = 0;
|
||||
@@ -197,3 +200,4 @@ void ApiResponse::unsetMessage()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Describes the result of uploading an image resource
|
||||
/// </summary>
|
||||
@@ -89,6 +90,7 @@ protected:
|
||||
bool m_MessageIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
Category::Category()
|
||||
{
|
||||
m_Id = 0L;
|
||||
@@ -154,3 +157,4 @@ void Category::unsetName()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A category for a pet
|
||||
/// </summary>
|
||||
@@ -78,6 +79,7 @@ protected:
|
||||
bool m_NameIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
Order::Order()
|
||||
{
|
||||
m_Id = 0L;
|
||||
@@ -326,3 +329,4 @@ void Order::unsetComplete()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// An order for a pets from the pet store
|
||||
/// </summary>
|
||||
@@ -122,6 +123,7 @@ protected:
|
||||
bool m_CompleteIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
Pet::Pet()
|
||||
{
|
||||
m_Id = 0L;
|
||||
@@ -352,3 +355,4 @@ void Pet::unsetStatus()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A pet for sale in the pet store
|
||||
/// </summary>
|
||||
@@ -119,6 +120,7 @@ protected:
|
||||
bool m_StatusIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
Tag::Tag()
|
||||
{
|
||||
m_Id = 0L;
|
||||
@@ -154,3 +157,4 @@ void Tag::unsetName()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A tag for a pet
|
||||
/// </summary>
|
||||
@@ -78,6 +79,7 @@ protected:
|
||||
bool m_NameIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
|
||||
|
||||
User::User()
|
||||
{
|
||||
m_Id = 0L;
|
||||
@@ -412,3 +415,4 @@ void User::unsetUserStatus()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace openapitools {
|
||||
namespace client {
|
||||
namespace model {
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A User who is purchasing from the pet store
|
||||
/// </summary>
|
||||
@@ -144,6 +145,7 @@ protected:
|
||||
bool m_UserStatusIsSet;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user