diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache index 149d7e8dc886..868f98f7ac77 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-header.mustache @@ -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 multipart, const utility::string_t& namePrefix) const override; + void fromMultiPart(std::shared_ptr multipart, const utility::string_t& namePrefix) override; + + enum class e{{classname}} + { + {{#allowableValues}} + {{#values}} + {{#enumDescription}} + /// + /// {{enumDescription}} + /// + {{/enumDescription}} + {{classname}}_{{.}}{{^last}},{{/last}} + {{/values}} + {{/allowableValues}} + }; + + e{{classname}} getValue() const; + void setValue(e{{classname}} const value); + + protected: + e{{classname}} m_value; +}; +{{/isEnum}} +{{^isEnum}} + /// /// {{description}} /// @@ -75,6 +117,8 @@ protected: {{/vars}} }; +{{/isEnum}} + {{#modelNamespaceDeclarations}} } {{/modelNamespaceDeclarations}} diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache index 1805e44d58d6..08bb16e16982 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache @@ -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 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 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}} diff --git a/samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp b/samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp index 501d81308b31..4122b863fb64 100644 --- a/samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp +++ b/samples/client/petstore/cpp-restsdk/model/ApiResponse.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + ApiResponse::ApiResponse() { m_Code = 0; @@ -197,3 +200,4 @@ void ApiResponse::unsetMessage() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/ApiResponse.h b/samples/client/petstore/cpp-restsdk/model/ApiResponse.h index ae6800aee9d1..83115c794ab9 100644 --- a/samples/client/petstore/cpp-restsdk/model/ApiResponse.h +++ b/samples/client/petstore/cpp-restsdk/model/ApiResponse.h @@ -28,6 +28,7 @@ namespace openapitools { namespace client { namespace model { + /// /// Describes the result of uploading an image resource /// @@ -89,6 +90,7 @@ protected: bool m_MessageIsSet; }; + } } } diff --git a/samples/client/petstore/cpp-restsdk/model/Category.cpp b/samples/client/petstore/cpp-restsdk/model/Category.cpp index f332d75fc291..ad6422cb906a 100644 --- a/samples/client/petstore/cpp-restsdk/model/Category.cpp +++ b/samples/client/petstore/cpp-restsdk/model/Category.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + Category::Category() { m_Id = 0L; @@ -154,3 +157,4 @@ void Category::unsetName() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/Category.h b/samples/client/petstore/cpp-restsdk/model/Category.h index 281764a6e22e..026ec8607287 100644 --- a/samples/client/petstore/cpp-restsdk/model/Category.h +++ b/samples/client/petstore/cpp-restsdk/model/Category.h @@ -28,6 +28,7 @@ namespace openapitools { namespace client { namespace model { + /// /// A category for a pet /// @@ -78,6 +79,7 @@ protected: bool m_NameIsSet; }; + } } } diff --git a/samples/client/petstore/cpp-restsdk/model/Order.cpp b/samples/client/petstore/cpp-restsdk/model/Order.cpp index 328810e0da28..a15f779237c4 100644 --- a/samples/client/petstore/cpp-restsdk/model/Order.cpp +++ b/samples/client/petstore/cpp-restsdk/model/Order.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + Order::Order() { m_Id = 0L; @@ -326,3 +329,4 @@ void Order::unsetComplete() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/Order.h b/samples/client/petstore/cpp-restsdk/model/Order.h index e0ac20b85433..c5d4153cfcdb 100644 --- a/samples/client/petstore/cpp-restsdk/model/Order.h +++ b/samples/client/petstore/cpp-restsdk/model/Order.h @@ -28,6 +28,7 @@ namespace openapitools { namespace client { namespace model { + /// /// An order for a pets from the pet store /// @@ -122,6 +123,7 @@ protected: bool m_CompleteIsSet; }; + } } } diff --git a/samples/client/petstore/cpp-restsdk/model/Pet.cpp b/samples/client/petstore/cpp-restsdk/model/Pet.cpp index 29603278d979..6e4ebb69c4d7 100644 --- a/samples/client/petstore/cpp-restsdk/model/Pet.cpp +++ b/samples/client/petstore/cpp-restsdk/model/Pet.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + Pet::Pet() { m_Id = 0L; @@ -352,3 +355,4 @@ void Pet::unsetStatus() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/Pet.h b/samples/client/petstore/cpp-restsdk/model/Pet.h index e151a071c282..881685336df5 100644 --- a/samples/client/petstore/cpp-restsdk/model/Pet.h +++ b/samples/client/petstore/cpp-restsdk/model/Pet.h @@ -31,6 +31,7 @@ namespace openapitools { namespace client { namespace model { + /// /// A pet for sale in the pet store /// @@ -119,6 +120,7 @@ protected: bool m_StatusIsSet; }; + } } } diff --git a/samples/client/petstore/cpp-restsdk/model/Tag.cpp b/samples/client/petstore/cpp-restsdk/model/Tag.cpp index e68b21094271..9f5f5b14636c 100644 --- a/samples/client/petstore/cpp-restsdk/model/Tag.cpp +++ b/samples/client/petstore/cpp-restsdk/model/Tag.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + Tag::Tag() { m_Id = 0L; @@ -154,3 +157,4 @@ void Tag::unsetName() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/Tag.h b/samples/client/petstore/cpp-restsdk/model/Tag.h index 67556cc2c400..9df0f2c2e7e9 100644 --- a/samples/client/petstore/cpp-restsdk/model/Tag.h +++ b/samples/client/petstore/cpp-restsdk/model/Tag.h @@ -28,6 +28,7 @@ namespace openapitools { namespace client { namespace model { + /// /// A tag for a pet /// @@ -78,6 +79,7 @@ protected: bool m_NameIsSet; }; + } } } diff --git a/samples/client/petstore/cpp-restsdk/model/User.cpp b/samples/client/petstore/cpp-restsdk/model/User.cpp index 9f8645431b43..93a64fbb3604 100644 --- a/samples/client/petstore/cpp-restsdk/model/User.cpp +++ b/samples/client/petstore/cpp-restsdk/model/User.cpp @@ -18,6 +18,9 @@ namespace openapitools { namespace client { namespace model { + + + User::User() { m_Id = 0L; @@ -412,3 +415,4 @@ void User::unsetUserStatus() } } + diff --git a/samples/client/petstore/cpp-restsdk/model/User.h b/samples/client/petstore/cpp-restsdk/model/User.h index b4a858d837db..851dcc57a25f 100644 --- a/samples/client/petstore/cpp-restsdk/model/User.h +++ b/samples/client/petstore/cpp-restsdk/model/User.h @@ -28,6 +28,7 @@ namespace openapitools { namespace client { namespace model { + /// /// A User who is purchasing from the pet store /// @@ -144,6 +145,7 @@ protected: bool m_UserStatusIsSet; }; + } } }