From f2fe4fc200ada86bb7c023a20c9e5d529e5901ad Mon Sep 17 00:00:00 2001 From: "Mateusz Szychowski (Muttley)" Date: Sat, 7 Sep 2019 12:20:04 +0200 Subject: [PATCH] [C++][Pistache] Add missing setter for arrays (#3837) * [C++][Pistache] Add missing setter for arrays Fixes #3769 * [C++][Pistache] Update Petstore sample --- .../cpp-pistache-server/model-header.mustache | 10 ++++------ .../cpp-pistache-server/model-source.mustache | 13 ++++--------- .../cpp-pistache/.openapi-generator/VERSION | 2 +- samples/server/petstore/cpp-pistache/model/Pet.cpp | 12 ++++++++++-- samples/server/petstore/cpp-pistache/model/Pet.h | 6 ++++-- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-header.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-header.mustache index a05667766a9f..b999e5997b4e 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-header.mustache @@ -35,12 +35,10 @@ public: /// /// {{description}} /// - {{#isContainer}}{{{dataType}}}& {{getter}}(); - {{/isContainer}}{{^isContainer}}{{{dataType}}} {{getter}}() const; - void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value); - {{/isContainer}}{{^required}}bool {{nameInCamelCase}}IsSet() const; - void unset{{name}}(); - {{/required}} + {{{dataType}}}{{#isContainer}}&{{/isContainer}} {{getter}}(){{^isContainer}} const{{/isContainer}}; + void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);{{^required}} + bool {{nameInCamelCase}}IsSet() const; + void unset{{name}}();{{/required}} {{/vars}} friend void to_json(nlohmann::json& j, const {{classname}}& o); diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache index e69d65cafc68..03b8d574df46 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache @@ -29,7 +29,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o) { j = nlohmann::json(); {{#vars}} - {{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet()) + {{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet(){{#isContainer}} || !o.m_{{name}}.empty(){{/isContainer}}) j["{{baseName}}"] = o.m_{{name}};{{/required}} {{/vars}} } @@ -45,20 +45,15 @@ void from_json(const nlohmann::json& j, {{classname}}& o) {{/vars}} } -{{#vars}}{{#isContainer}}{{{dataType}}}& {{classname}}::{{getter}}() -{ - return m_{{name}}; -} -{{/isContainer}}{{^isContainer}}{{{dataType}}} {{classname}}::{{getter}}() const +{{#vars}}{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{classname}}::{{getter}}(){{^isContainer}} const{{/isContainer}} { return m_{{name}}; } void {{classname}}::{{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value) { - m_{{name}} = value; - {{^required}}m_{{name}}IsSet = true;{{/required}} + m_{{name}} = value;{{^required}} + m_{{name}}IsSet = true;{{/required}} } -{{/isContainer}} {{^required}}bool {{classname}}::{{nameInCamelCase}}IsSet() const { return m_{{name}}IsSet; diff --git a/samples/server/petstore/cpp-pistache/.openapi-generator/VERSION b/samples/server/petstore/cpp-pistache/.openapi-generator/VERSION index 83a328a9227e..d1a8f58b3884 100644 --- a/samples/server/petstore/cpp-pistache/.openapi-generator/VERSION +++ b/samples/server/petstore/cpp-pistache/.openapi-generator/VERSION @@ -1 +1 @@ -4.1.0-SNAPSHOT \ No newline at end of file +4.1.2-SNAPSHOT \ No newline at end of file diff --git a/samples/server/petstore/cpp-pistache/model/Pet.cpp b/samples/server/petstore/cpp-pistache/model/Pet.cpp index 1bceb861ad48..0ff016b545f0 100644 --- a/samples/server/petstore/cpp-pistache/model/Pet.cpp +++ b/samples/server/petstore/cpp-pistache/model/Pet.cpp @@ -48,7 +48,7 @@ void to_json(nlohmann::json& j, const Pet& o) j["category"] = o.m_Category; j["name"] = o.m_Name; j["photoUrls"] = o.m_PhotoUrls; - if(o.tagsIsSet()) + if(o.tagsIsSet() || !o.m_Tags.empty()) j["tags"] = o.m_Tags; if(o.statusIsSet()) j["status"] = o.m_Status; @@ -121,16 +121,24 @@ std::string Pet::getName() const void Pet::setName(std::string const& value) { m_Name = value; - } std::vector& Pet::getPhotoUrls() { return m_PhotoUrls; } +void Pet::setPhotoUrls(std::vector const& value) +{ + m_PhotoUrls = value; +} std::vector& Pet::getTags() { return m_Tags; } +void Pet::setTags(std::vector const& value) +{ + m_Tags = value; + m_TagsIsSet = true; +} bool Pet::tagsIsSet() const { return m_TagsIsSet; diff --git a/samples/server/petstore/cpp-pistache/model/Pet.h b/samples/server/petstore/cpp-pistache/model/Pet.h index f23ef47832d2..eddf475f6ee3 100644 --- a/samples/server/petstore/cpp-pistache/model/Pet.h +++ b/samples/server/petstore/cpp-pistache/model/Pet.h @@ -63,14 +63,16 @@ class Pet /// std::string getName() const; void setName(std::string const& value); - /// + /// /// /// std::vector& getPhotoUrls(); - /// + void setPhotoUrls(std::vector const& value); + /// /// /// std::vector& getTags(); + void setTags(std::vector const& value); bool tagsIsSet() const; void unsetTags(); ///