Skip to content

Commit f2fe4fc

Browse files
muttleyxdetherealjoy
authored andcommitted
[C++][Pistache] Add missing setter for arrays (#3837)
* [C++][Pistache] Add missing setter for arrays Fixes #3769 * [C++][Pistache] Update Petstore sample
1 parent 096f2d0 commit f2fe4fc

File tree

5 files changed

+23
-20
lines changed

5 files changed

+23
-20
lines changed

modules/openapi-generator/src/main/resources/cpp-pistache-server/model-header.mustache

+4-6
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ public:
3535
/// <summary>
3636
/// {{description}}
3737
/// </summary>
38-
{{#isContainer}}{{{dataType}}}& {{getter}}();
39-
{{/isContainer}}{{^isContainer}}{{{dataType}}} {{getter}}() const;
40-
void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);
41-
{{/isContainer}}{{^required}}bool {{nameInCamelCase}}IsSet() const;
42-
void unset{{name}}();
43-
{{/required}}
38+
{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{getter}}(){{^isContainer}} const{{/isContainer}};
39+
void {{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value);{{^required}}
40+
bool {{nameInCamelCase}}IsSet() const;
41+
void unset{{name}}();{{/required}}
4442
{{/vars}}
4543

4644
friend void to_json(nlohmann::json& j, const {{classname}}& o);

modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache

+4-9
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o)
2929
{
3030
j = nlohmann::json();
3131
{{#vars}}
32-
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet())
32+
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet(){{#isContainer}} || !o.m_{{name}}.empty(){{/isContainer}})
3333
j["{{baseName}}"] = o.m_{{name}};{{/required}}
3434
{{/vars}}
3535
}
@@ -45,20 +45,15 @@ void from_json(const nlohmann::json& j, {{classname}}& o)
4545
{{/vars}}
4646
}
4747

48-
{{#vars}}{{#isContainer}}{{{dataType}}}& {{classname}}::{{getter}}()
49-
{
50-
return m_{{name}};
51-
}
52-
{{/isContainer}}{{^isContainer}}{{{dataType}}} {{classname}}::{{getter}}() const
48+
{{#vars}}{{{dataType}}}{{#isContainer}}&{{/isContainer}} {{classname}}::{{getter}}(){{^isContainer}} const{{/isContainer}}
5349
{
5450
return m_{{name}};
5551
}
5652
void {{classname}}::{{setter}}({{{dataType}}} const{{^isPrimitiveType}}&{{/isPrimitiveType}} value)
5753
{
58-
m_{{name}} = value;
59-
{{^required}}m_{{name}}IsSet = true;{{/required}}
54+
m_{{name}} = value;{{^required}}
55+
m_{{name}}IsSet = true;{{/required}}
6056
}
61-
{{/isContainer}}
6257
{{^required}}bool {{classname}}::{{nameInCamelCase}}IsSet() const
6358
{
6459
return m_{{name}}IsSet;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
4.1.0-SNAPSHOT
1+
4.1.2-SNAPSHOT

samples/server/petstore/cpp-pistache/model/Pet.cpp

+10-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void to_json(nlohmann::json& j, const Pet& o)
4848
j["category"] = o.m_Category;
4949
j["name"] = o.m_Name;
5050
j["photoUrls"] = o.m_PhotoUrls;
51-
if(o.tagsIsSet())
51+
if(o.tagsIsSet() || !o.m_Tags.empty())
5252
j["tags"] = o.m_Tags;
5353
if(o.statusIsSet())
5454
j["status"] = o.m_Status;
@@ -121,16 +121,24 @@ std::string Pet::getName() const
121121
void Pet::setName(std::string const& value)
122122
{
123123
m_Name = value;
124-
125124
}
126125
std::vector<std::string>& Pet::getPhotoUrls()
127126
{
128127
return m_PhotoUrls;
129128
}
129+
void Pet::setPhotoUrls(std::vector<std::string> const& value)
130+
{
131+
m_PhotoUrls = value;
132+
}
130133
std::vector<Tag>& Pet::getTags()
131134
{
132135
return m_Tags;
133136
}
137+
void Pet::setTags(std::vector<Tag> const& value)
138+
{
139+
m_Tags = value;
140+
m_TagsIsSet = true;
141+
}
134142
bool Pet::tagsIsSet() const
135143
{
136144
return m_TagsIsSet;

samples/server/petstore/cpp-pistache/model/Pet.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,16 @@ class Pet
6363
/// </summary>
6464
std::string getName() const;
6565
void setName(std::string const& value);
66-
/// <summary>
66+
/// <summary>
6767
///
6868
/// </summary>
6969
std::vector<std::string>& getPhotoUrls();
70-
/// <summary>
70+
void setPhotoUrls(std::vector<std::string> const& value);
71+
/// <summary>
7172
///
7273
/// </summary>
7374
std::vector<Tag>& getTags();
75+
void setTags(std::vector<Tag> const& value);
7476
bool tagsIsSet() const;
7577
void unsetTags();
7678
/// <summary>

0 commit comments

Comments
 (0)