Skip to content

Commit ed647f8

Browse files
committed
[cpp-rest-sdk-client] handling datetime type
A specialization for the shared_ptr<datetime> data type was added to ModelBase member functions fromString, fromJson, toJson and toHttpContent. This should fix compilation errors on generated source code. See https://github.com/coinapi/coinapi-sdk/pull/130
1 parent 6b49d19 commit ed647f8

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public:
6464
static web::json::value toJson( const std::shared_ptr<HttpContent>& val );
6565
template<typename T>
6666
static web::json::value toJson( const std::shared_ptr<T>& val );
67+
static web::json::value toJson( const std::shared_ptr<utility::datetime>& val );
6768
template<typename T>
6869
static web::json::value toJson( const std::vector<T>& val );
6970
template<typename T>
@@ -80,6 +81,7 @@ public:
8081
static bool fromString( const utility::string_t& val, std::shared_ptr<HttpContent> & );
8182
template<typename T>
8283
static bool fromString( const utility::string_t& val, std::shared_ptr<T>& );
84+
static bool fromString( const utility::string_t& val, std::shared_ptr<utility::datetime>& outVal );
8385
template<typename T>
8486
static bool fromString( const utility::string_t& val, std::vector<T> & );
8587
template<typename T>
@@ -96,6 +98,7 @@ public:
9698
static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
9799
template<typename T>
98100
static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
101+
static bool fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal );
99102
template<typename T>
100103
static bool fromJson( const web::json::value& val, std::vector<T> & );
101104
template<typename T>
@@ -113,6 +116,7 @@ public:
113116
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& );
114117
template <typename T>
115118
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<T>& , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
119+
static std::shared_ptr<HttpContent> toHttpContent(const utility::string_t& name, const std::shared_ptr<utility::datetime>& value , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
116120
template <typename T>
117121
static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
118122
template <typename T>

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ web::json::value ModelBase::toJson( const std::shared_ptr<HttpContent>& content
112112
}
113113
return value;
114114
}
115+
web::json::value ModelBase::toJson( const std::shared_ptr<utility::datetime>& val )
116+
{
117+
web::json::value retVal;
118+
if(val != nullptr)
119+
{
120+
retVal = toJson(*val);
121+
}
122+
return retVal;
123+
}
115124
bool ModelBase::fromString( const utility::string_t& val, bool &outVal )
116125
{
117126
utility::stringstream_t ss(val);
@@ -242,6 +251,19 @@ bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<HttpCo
242251
}
243252
return ok;
244253
}
254+
bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<utility::datetime>& outVal )
255+
{
256+
bool ok = false;
257+
if(outVal == nullptr)
258+
{
259+
outVal = std::shared_ptr<utility::datetime>(new utility::datetime());
260+
}
261+
if( outVal != nullptr )
262+
{
263+
ok = fromJson(web::json::value::parse(val), *outVal);
264+
}
265+
return ok;
266+
}
245267
bool ModelBase::fromJson( const web::json::value& val, bool & outVal )
246268
{
247269
outVal = !val.is_boolean() ? false : val.as_bool();
@@ -319,6 +341,19 @@ bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpConte
319341
}
320342
return result;
321343
}
344+
bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal )
345+
{
346+
bool ok = false;
347+
if(outVal == nullptr)
348+
{
349+
outVal = std::shared_ptr<utility::datetime>(new utility::datetime());
350+
}
351+
if( outVal != nullptr )
352+
{
353+
ok = fromJson(val, *outVal);
354+
}
355+
return ok;
356+
}
322357
std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType )
323358
{
324359
std::shared_ptr<HttpContent> content( new HttpContent );
@@ -414,6 +449,18 @@ std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t&
414449
}
415450
return content;
416451
}
452+
std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<utility::datetime>& value , const utility::string_t& contentType )
453+
{
454+
std::shared_ptr<HttpContent> content( new HttpContent );
455+
if (value != nullptr )
456+
{
457+
content->setName( name );
458+
content->setContentDisposition( utility::conversions::to_string_t("form-data") );
459+
content->setContentType( contentType );
460+
content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( toJson(*value).serialize() ) ) ) );
461+
}
462+
return content;
463+
}
417464
bool ModelBase::fromHttpContent(std::shared_ptr<HttpContent> val, bool & outVal )
418465
{
419466
utility::string_t str;

0 commit comments

Comments
 (0)