diff --git a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache index 665c9e7e8a3..04c57851798 100644 --- a/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/modelbase-header.mustache @@ -255,7 +255,7 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr& ou bool ok = false; if(outVal == nullptr) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } if( outVal != nullptr ) { @@ -264,12 +264,78 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr& ou return ok; } template +bool ModelBase::fromString(const utility::string_t& val, std::vector& outVal ) +{ + bool ok = true; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.push_back(item); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.push_back(item); + } + return ok; +} +template +bool ModelBase::fromString(const utility::string_t& val, std::set& outVal ) +{ + bool ok = true; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert(item); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.insert(item); + } + return ok; +} +template +bool ModelBase::fromString(const utility::string_t& val, std::map& outVal ) +{ + bool ok = false; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert({ val, item }); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.insert({ val, item }); + } + return ok; +} +template bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr &outVal ) { bool ok = false; if(outVal == nullptr) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } if( outVal != nullptr ) { @@ -297,6 +363,27 @@ bool ModelBase::fromJson( const web::json::value& val, std::vector &outVal ) return ok; } template +bool ModelBase::fromJson(const web::json::value& val, std::set& outVal ) +{ + bool ok = true; + if (val.is_array()) + { + for (const web::json::value& jitem : val.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert(item); + } + } + else + { + T item; + ok = fromJson(val, item); + outVal.insert(item); + } + return ok; +} +template bool ModelBase::fromJson( const web::json::value& jval, std::map &outVal ) { bool ok = true; @@ -319,13 +406,13 @@ bool ModelBase::fromJson( const web::json::value& jval, std::map std::shared_ptr ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr& value , const utility::string_t& contentType ) { - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); if (value != nullptr ) { content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(value->toJson().serialize()) ) ); } return content; } @@ -334,23 +421,33 @@ template std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::vector& value, const utility::string_t& contentType ) { web::json::value json_array = ModelBase::toJson(value); - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(json_array.serialize()) ) ); + return content; +} +template +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::set& value, const utility::string_t& contentType ) +{ + web::json::value json_array = ModelBase::toJson(value); + std::shared_ptr content = std::make_shared(); + content->setName(name); + content->setContentDisposition(utility::conversions::to_string_t("form-data")); + content->setContentType(contentType); + content->setData( std::make_shared( utility::conversions::to_utf8string(json_array.serialize()) ) ); return content; } - template std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::map& value, const utility::string_t& contentType ) { web::json::value jobj = ModelBase::toJson(value); - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(jobj.serialize()) ) ); return content; } template @@ -360,20 +457,34 @@ bool ModelBase::fromHttpContent( std::shared_ptr val, std::shared_ if(val == nullptr) return false; if( outVal == nullptr ) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } template -bool ModelBase::fromHttpContent( std::shared_ptr val, std::vector & ) +bool ModelBase::fromHttpContent( std::shared_ptr val, std::vector & outVal ) { - return true; + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); } template -bool ModelBase::fromHttpContent( std::shared_ptr val, std::map & ) +bool ModelBase::fromHttpContent(std::shared_ptr val, std::set& outVal ) { - return true; + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); +} +template +bool ModelBase::fromHttpContent( std::shared_ptr val, std::map & outVal ) +{ + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); } {{#modelNamespaceDeclarations}} } diff --git a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h index d0206b1fdb5..10b6ec9f10c 100644 --- a/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h +++ b/samples/client/petstore/cpp-restsdk/client/include/CppRestPetstoreClient/ModelBase.h @@ -266,7 +266,7 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr& ou bool ok = false; if(outVal == nullptr) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } if( outVal != nullptr ) { @@ -275,12 +275,78 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr& ou return ok; } template +bool ModelBase::fromString(const utility::string_t& val, std::vector& outVal ) +{ + bool ok = true; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.push_back(item); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.push_back(item); + } + return ok; +} +template +bool ModelBase::fromString(const utility::string_t& val, std::set& outVal ) +{ + bool ok = true; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert(item); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.insert(item); + } + return ok; +} +template +bool ModelBase::fromString(const utility::string_t& val, std::map& outVal ) +{ + bool ok = false; + web::json::value jsonValue = web::json::value::parse(val); + if (jsonValue.is_array()) + { + for (const web::json::value& jitem : jsonValue.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert({ val, item }); + } + } + else + { + T item; + ok = fromJson(jsonValue, item); + outVal.insert({ val, item }); + } + return ok; +} +template bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr &outVal ) { bool ok = false; if(outVal == nullptr) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } if( outVal != nullptr ) { @@ -308,6 +374,27 @@ bool ModelBase::fromJson( const web::json::value& val, std::vector &outVal ) return ok; } template +bool ModelBase::fromJson(const web::json::value& val, std::set& outVal ) +{ + bool ok = true; + if (val.is_array()) + { + for (const web::json::value& jitem : val.as_array()) + { + T item; + ok &= fromJson(jitem, item); + outVal.insert(item); + } + } + else + { + T item; + ok = fromJson(val, item); + outVal.insert(item); + } + return ok; +} +template bool ModelBase::fromJson( const web::json::value& jval, std::map &outVal ) { bool ok = true; @@ -330,13 +417,13 @@ bool ModelBase::fromJson( const web::json::value& jval, std::map std::shared_ptr ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr& value , const utility::string_t& contentType ) { - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); if (value != nullptr ) { content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(value->toJson().serialize()) ) ); } return content; } @@ -345,23 +432,33 @@ template std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::vector& value, const utility::string_t& contentType ) { web::json::value json_array = ModelBase::toJson(value); - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(json_array.serialize()) ) ); + return content; +} +template +std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::set& value, const utility::string_t& contentType ) +{ + web::json::value json_array = ModelBase::toJson(value); + std::shared_ptr content = std::make_shared(); + content->setName(name); + content->setContentDisposition(utility::conversions::to_string_t("form-data")); + content->setContentType(contentType); + content->setData( std::make_shared( utility::conversions::to_utf8string(json_array.serialize()) ) ); return content; } - template std::shared_ptr ModelBase::toHttpContent( const utility::string_t& name, const std::map& value, const utility::string_t& contentType ) { web::json::value jobj = ModelBase::toJson(value); - std::shared_ptr content( new HttpContent ); + std::shared_ptr content = std::make_shared(); content->setName( name ); content->setContentDisposition( utility::conversions::to_string_t("form-data") ); content->setContentType( contentType ); - content->setData( std::shared_ptr( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) ); + content->setData( std::make_shared( utility::conversions::to_utf8string(jobj.serialize()) ) ); return content; } template @@ -371,20 +468,34 @@ bool ModelBase::fromHttpContent( std::shared_ptr val, std::shared_ if(val == nullptr) return false; if( outVal == nullptr ) { - outVal = std::shared_ptr(new T()); + outVal = std::make_shared(); } ModelBase::fromHttpContent(val, str); return fromString(str, outVal); } template -bool ModelBase::fromHttpContent( std::shared_ptr val, std::vector & ) +bool ModelBase::fromHttpContent( std::shared_ptr val, std::vector & outVal ) { - return true; + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); } template -bool ModelBase::fromHttpContent( std::shared_ptr val, std::map & ) +bool ModelBase::fromHttpContent(std::shared_ptr val, std::set& outVal ) { - return true; + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); +} +template +bool ModelBase::fromHttpContent( std::shared_ptr val, std::map & outVal ) +{ + utility::string_t str; + if (val == nullptr) return false; + ModelBase::fromHttpContent(val, str); + return fromString(str, outVal); } } }