Skip to content

[C++][RESTSDK] support enums #2749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont it be better to add {{#enumDescription}} ?

{{#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>
Expand Down Expand Up @@ -75,6 +117,8 @@ protected:
{{/vars}}
};

{{/isEnum}}

{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down Expand Up @@ -629,9 +713,11 @@ void {{classname}}::unset{{name}}()
{{/required}}
{{/isInherited}}
{{/vars}}
{{/isEnum}}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}


{{/model}}
{{/models}}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.3.4
4.0.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ApiException.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/HttpContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/IHttpBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/JsonBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/MultipartFormData.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.3.4.
* NOTE: This class is auto generated by OpenAPI-Generator 4.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
Expand Down
Loading