Skip to content

Commit 2e5c8c1

Browse files
committed
[cpp-restsdk] add test for object property
1 parent d11c131 commit 2e5c8c1

File tree

6 files changed

+67
-7
lines changed

6 files changed

+67
-7
lines changed

modules/openapi-generator/src/test/resources/3_0/cpp-restsdk/petstore.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,8 @@ components:
798798
- available
799799
- pending
800800
- sold
801+
metadata:
802+
type: object
801803
xml:
802804
name: Pet
803805
Color:

samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/CreateUserOrPet_request.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "CppRestPetstoreClient/model/Tag.h"
2828
#include "CppRestPetstoreClient/model/Category.h"
2929
#include <cpprest/details/basic_types.h>
30+
#include "CppRestPetstoreClient/Object.h"
3031
#include "CppRestPetstoreClient/model/Pet.h"
3132
#include <vector>
3233

samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Page.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ class Page
6464
void unsetPerPage();
6565
void setPerPage(int32_t value);
6666

67-
std::vector<utility::string_t> getReferenceTest() const;
67+
std::vector<std::shared_ptr<utility::string_t>> getReferenceTest() const;
6868
bool referenceTestIsSet() const;
6969
void unsetReference_test();
70-
void setReferenceTest(const std::vector<utility::string_t>& value);
70+
void setReferenceTest(const std::vector<std::shared_ptr<utility::string_t>>& value);
7171

7272

7373
protected:
@@ -77,7 +77,7 @@ class Page
7777
int32_t m_PerPage;
7878
bool m_PerPageIsSet;
7979

80-
std::vector<utility::string_t> m_Reference_test;
80+
std::vector<std::shared_ptr<utility::string_t>> m_Reference_test;
8181
bool m_Reference_testIsSet;
8282

8383
};

samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/model/Pet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "CppRestPetstoreClient/model/Tag.h"
2626
#include "CppRestPetstoreClient/model/Category.h"
2727
#include <cpprest/details/basic_types.h>
28+
#include "CppRestPetstoreClient/Object.h"
2829
#include <vector>
2930

3031
namespace org {
@@ -109,6 +110,11 @@ class Pet
109110
void unsetStatus();
110111
void setStatus(const StatusEnum value);
111112

113+
std::shared_ptr<Object> getMetadata() const;
114+
bool metadataIsSet() const;
115+
void unsetMetadata();
116+
void setMetadata(const std::shared_ptr<Object>& value);
117+
112118

113119
protected:
114120
int64_t m_Id;
@@ -129,6 +135,9 @@ class Pet
129135
StatusEnum m_Status;
130136
bool m_StatusIsSet;
131137

138+
std::shared_ptr<Object> m_Metadata;
139+
bool m_MetadataIsSet;
140+
132141
};
133142

134143

samples/client/petstore/cpp-restsdk/client/src/model/Page.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool Page::fromJson(const web::json::value& val)
8888
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("reference_test")));
8989
if(!fieldValue.is_null())
9090
{
91-
std::vector<utility::string_t> refVal_setReferenceTest;
91+
std::vector<std::shared_ptr<utility::string_t>> refVal_setReferenceTest;
9292
ok &= ModelBase::fromJson(fieldValue, refVal_setReferenceTest);
9393
setReferenceTest(refVal_setReferenceTest);
9494

@@ -141,7 +141,7 @@ bool Page::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const uti
141141
}
142142
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("reference_test"))))
143143
{
144-
std::vector<utility::string_t> refVal_setReferenceTest;
144+
std::vector<std::shared_ptr<utility::string_t>> refVal_setReferenceTest;
145145
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("reference_test"))), refVal_setReferenceTest );
146146
setReferenceTest(refVal_setReferenceTest);
147147
}
@@ -189,13 +189,13 @@ void Page::unsetPerPage()
189189
{
190190
m_PerPageIsSet = false;
191191
}
192-
std::vector<utility::string_t> Page::getReferenceTest() const
192+
std::vector<std::shared_ptr<utility::string_t>> Page::getReferenceTest() const
193193
{
194194
return m_Reference_test;
195195
}
196196

197197

198-
void Page::setReferenceTest(const std::vector<utility::string_t>& value)
198+
void Page::setReferenceTest(const std::vector<std::shared_ptr<utility::string_t>>& value)
199199
{
200200
m_Reference_test = value;
201201
m_Reference_testIsSet = true;

samples/client/petstore/cpp-restsdk/client/src/model/Pet.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Pet::Pet()
2828
m_PhotoUrlsIsSet = false;
2929
m_TagsIsSet = false;
3030
m_StatusIsSet = false;
31+
m_MetadataIsSet = false;
3132
}
3233

3334
Pet::~Pet()
@@ -74,6 +75,11 @@ web::json::value Pet::toJson() const
7475
val[utility::conversions::to_string_t(_XPLATSTR("status"))] = ModelBase::toJson(refVal);
7576

7677
}
78+
if(m_MetadataIsSet)
79+
{
80+
81+
val[utility::conversions::to_string_t(_XPLATSTR("metadata"))] = ModelBase::toJson(m_Metadata);
82+
}
7783

7884
return val;
7985
}
@@ -148,6 +154,17 @@ bool Pet::fromJson(const web::json::value& val)
148154

149155
}
150156
}
157+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("metadata"))))
158+
{
159+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("metadata")));
160+
if(!fieldValue.is_null())
161+
{
162+
std::shared_ptr<Object> refVal_setMetadata;
163+
ok &= ModelBase::fromJson(fieldValue, refVal_setMetadata);
164+
setMetadata(refVal_setMetadata);
165+
166+
}
167+
}
151168
return ok;
152169
}
153170

@@ -182,6 +199,10 @@ void Pet::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utilit
182199
{
183200
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("status")), fromStatusEnum(m_Status)));
184201
}
202+
if(m_MetadataIsSet)
203+
{
204+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("metadata")), m_Metadata));
205+
}
185206
}
186207

187208
bool Pet::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
@@ -229,6 +250,12 @@ bool Pet::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const util
229250
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("status"))), refVal_setStatus );
230251
setStatus(toStatusEnum(refVal_setStatus));
231252
}
253+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("metadata"))))
254+
{
255+
std::shared_ptr<Object> refVal_setMetadata;
256+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("metadata"))), refVal_setMetadata );
257+
setMetadata(refVal_setMetadata);
258+
}
232259
return ok;
233260
}
234261

@@ -391,6 +418,27 @@ void Pet::unsetStatus()
391418
{
392419
m_StatusIsSet = false;
393420
}
421+
std::shared_ptr<Object> Pet::getMetadata() const
422+
{
423+
return m_Metadata;
424+
}
425+
426+
427+
void Pet::setMetadata(const std::shared_ptr<Object>& value)
428+
{
429+
m_Metadata = value;
430+
m_MetadataIsSet = true;
431+
}
432+
433+
bool Pet::metadataIsSet() const
434+
{
435+
return m_MetadataIsSet;
436+
}
437+
438+
void Pet::unsetMetadata()
439+
{
440+
m_MetadataIsSet = false;
441+
}
394442

395443
}
396444
}

0 commit comments

Comments
 (0)