Skip to content

Commit 9163e00

Browse files
authored
Implemented missing definitions of declared methods inside modelbase-header.mustache, added two missing body of methods definitions (#19569)
* Fix #19566 implemented the missing definition of declared methods inside openapi-generator/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache, have also be added two missing body of methods definitions * Regenerated cpp-restsdk client samples * Fixed shared_ptr creation
1 parent 2f3f25d commit 9163e00

File tree

2 files changed

+250
-28
lines changed

2 files changed

+250
-28
lines changed

modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache

Lines changed: 125 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<T>& ou
255255
bool ok = false;
256256
if(outVal == nullptr)
257257
{
258-
outVal = std::shared_ptr<T>(new T());
258+
outVal = std::make_shared<T>();
259259
}
260260
if( outVal != nullptr )
261261
{
@@ -264,12 +264,78 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<T>& ou
264264
return ok;
265265
}
266266
template<typename T>
267+
bool ModelBase::fromString(const utility::string_t& val, std::vector<T>& outVal )
268+
{
269+
bool ok = true;
270+
web::json::value jsonValue = web::json::value::parse(val);
271+
if (jsonValue.is_array())
272+
{
273+
for (const web::json::value& jitem : jsonValue.as_array())
274+
{
275+
T item;
276+
ok &= fromJson(jitem, item);
277+
outVal.push_back(item);
278+
}
279+
}
280+
else
281+
{
282+
T item;
283+
ok = fromJson(jsonValue, item);
284+
outVal.push_back(item);
285+
}
286+
return ok;
287+
}
288+
template<typename T>
289+
bool ModelBase::fromString(const utility::string_t& val, std::set<T>& outVal )
290+
{
291+
bool ok = true;
292+
web::json::value jsonValue = web::json::value::parse(val);
293+
if (jsonValue.is_array())
294+
{
295+
for (const web::json::value& jitem : jsonValue.as_array())
296+
{
297+
T item;
298+
ok &= fromJson(jitem, item);
299+
outVal.insert(item);
300+
}
301+
}
302+
else
303+
{
304+
T item;
305+
ok = fromJson(jsonValue, item);
306+
outVal.insert(item);
307+
}
308+
return ok;
309+
}
310+
template<typename T>
311+
bool ModelBase::fromString(const utility::string_t& val, std::map<utility::string_t, T>& outVal )
312+
{
313+
bool ok = false;
314+
web::json::value jsonValue = web::json::value::parse(val);
315+
if (jsonValue.is_array())
316+
{
317+
for (const web::json::value& jitem : jsonValue.as_array())
318+
{
319+
T item;
320+
ok &= fromJson(jitem, item);
321+
outVal.insert({ val, item });
322+
}
323+
}
324+
else
325+
{
326+
T item;
327+
ok = fromJson(jsonValue, item);
328+
outVal.insert({ val, item });
329+
}
330+
return ok;
331+
}
332+
template<typename T>
267333
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<T> &outVal )
268334
{
269335
bool ok = false;
270336
if(outVal == nullptr)
271337
{
272-
outVal = std::shared_ptr<T>(new T());
338+
outVal = std::make_shared<T>();
273339
}
274340
if( outVal != nullptr )
275341
{
@@ -297,6 +363,27 @@ bool ModelBase::fromJson( const web::json::value& val, std::vector<T> &outVal )
297363
return ok;
298364
}
299365
template<typename T>
366+
bool ModelBase::fromJson(const web::json::value& val, std::set<T>& outVal )
367+
{
368+
bool ok = true;
369+
if (val.is_array())
370+
{
371+
for (const web::json::value& jitem : val.as_array())
372+
{
373+
T item;
374+
ok &= fromJson(jitem, item);
375+
outVal.insert(item);
376+
}
377+
}
378+
else
379+
{
380+
T item;
381+
ok = fromJson(val, item);
382+
outVal.insert(item);
383+
}
384+
return ok;
385+
}
386+
template<typename T>
300387
bool ModelBase::fromJson( const web::json::value& jval, std::map<utility::string_t, T> &outVal )
301388
{
302389
bool ok = true;
@@ -319,13 +406,13 @@ bool ModelBase::fromJson( const web::json::value& jval, std::map<utility::string
319406
template <typename T>
320407
std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<T>& value , const utility::string_t& contentType )
321408
{
322-
std::shared_ptr<HttpContent> content( new HttpContent );
409+
std::shared_ptr<HttpContent> content = std::make_shared<HttpContent>();
323410
if (value != nullptr )
324411
{
325412
content->setName( name );
326413
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
327414
content->setContentType( contentType );
328-
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) );
415+
content->setData( std::make_shared<std::stringstream>( utility::conversions::to_utf8string(value->toJson().serialize()) ) );
329416
}
330417
return content;
331418
}
@@ -334,23 +421,33 @@ template <typename T>
334421
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
335422
{
336423
web::json::value json_array = ModelBase::toJson(value);
337-
std::shared_ptr<HttpContent> content( new HttpContent );
424+
std::shared_ptr<HttpContent> content = std::make_shared<HttpContent>();
338425
content->setName( name );
339426
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
340427
content->setContentType( contentType );
341-
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
428+
content->setData( std::make_shared<std::stringstream>( utility::conversions::to_utf8string(json_array.serialize()) ) );
429+
return content;
430+
}
431+
template <typename T>
432+
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::set<T>& value, const utility::string_t& contentType )
433+
{
434+
web::json::value json_array = ModelBase::toJson(value);
435+
std::shared_ptr<HttpContent> content = std::make_shared<HttpContent>();
436+
content->setName(name);
437+
content->setContentDisposition(utility::conversions::to_string_t("form-data"));
438+
content->setContentType(contentType);
439+
content->setData( std::make_shared<std::stringstream>( utility::conversions::to_utf8string(json_array.serialize()) ) );
342440
return content;
343441
}
344-
345442
template <typename T>
346443
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
347444
{
348445
web::json::value jobj = ModelBase::toJson(value);
349-
std::shared_ptr<HttpContent> content( new HttpContent );
446+
std::shared_ptr<HttpContent> content = std::make_shared<HttpContent>();
350447
content->setName( name );
351448
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
352449
content->setContentType( contentType );
353-
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) );
450+
content->setData( std::make_shared<std::stringstream>( utility::conversions::to_utf8string(jobj.serialize()) ) );
354451
return content;
355452
}
356453
template <typename T>
@@ -360,20 +457,34 @@ bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_
360457
if(val == nullptr) return false;
361458
if( outVal == nullptr )
362459
{
363-
outVal = std::shared_ptr<T>(new T());
460+
outVal = std::make_shared<T>();
364461
}
365462
ModelBase::fromHttpContent(val, str);
366463
return fromString(str, outVal);
367464
}
368465
template <typename T>
369-
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & )
466+
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & outVal )
370467
{
371-
return true;
468+
utility::string_t str;
469+
if (val == nullptr) return false;
470+
ModelBase::fromHttpContent(val, str);
471+
return fromString(str, outVal);
372472
}
373473
template <typename T>
374-
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & )
474+
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, std::set<T>& outVal )
375475
{
376-
return true;
476+
utility::string_t str;
477+
if (val == nullptr) return false;
478+
ModelBase::fromHttpContent(val, str);
479+
return fromString(str, outVal);
480+
}
481+
template <typename T>
482+
bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & outVal )
483+
{
484+
utility::string_t str;
485+
if (val == nullptr) return false;
486+
ModelBase::fromHttpContent(val, str);
487+
return fromString(str, outVal);
377488
}
378489
{{#modelNamespaceDeclarations}}
379490
}

0 commit comments

Comments
 (0)