Skip to content

Commit 12fa2c0

Browse files
authored
[cpp-restsdk] store Object as a shared pointer (OpenAPITools#21349)
* [cpp-restsdk] store Object as a shared pointer * [cpp-restsdk] add test for object property
1 parent fa64c8e commit 12fa2c0

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/CppRestSdkClientCodegen.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,8 @@ public String getTypeDeclaration(Schema p) {
387387
|| ModelUtils.isFileSchema(p) || ModelUtils.isUUIDSchema(p)
388388
|| languageSpecificPrimitives.contains(openAPIType)) {
389389
return toModelName(openAPIType);
390+
} else if (ModelUtils.isObjectSchema(p)) {
391+
return "std::shared_ptr<Object>";
390392
} else if(typeMapping.containsKey(super.getSchemaType(p))) {
391393
return openAPIType;
392394
}

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/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/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)