From df1055fe38ee79f82c77850451f29b024bf877c7 Mon Sep 17 00:00:00 2001 From: Jean-Maxime Fillau Date: Thu, 13 Apr 2017 11:30:20 +0200 Subject: [PATCH] Add float conversion for cpprest api client template. (#5387) Signed-off-by: FILLAU Jean-Maxime --- .../resources/cpprest/apiclient-header.mustache | 1 + .../resources/cpprest/apiclient-source.mustache | 5 +++++ .../resources/cpprest/modelbase-header.mustache | 2 ++ .../resources/cpprest/modelbase-source.mustache | 13 +++++++++++++ 4 files changed, 21 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache index 91400f163aa..f5194b2185f 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache @@ -38,6 +38,7 @@ public: static utility::string_t parameterToString(utility::string_t value); static utility::string_t parameterToString(int32_t value); static utility::string_t parameterToString(int64_t value); + static utility::string_t parameterToString(float value); static utility::string_t parameterToString(const utility::datetime &value); template diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache index 4f86ad40540..99532a11dcb 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache @@ -40,6 +40,11 @@ utility::string_t ApiClient::parameterToString(int32_t value) return utility::conversions::to_string_t(std::to_string(value)); } +utility::string_t ApiClient::parameterToString(float value) +{ + return utility::conversions::to_string_t(std::to_string(value)); +} + utility::string_t ApiClient::parameterToString(const utility::datetime &value) { return utility::conversions::to_string_t(value.to_string(utility::datetime::ISO_8601)); diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache index 3daf1d0dc9d..9597c47f8ec 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-header.mustache @@ -43,6 +43,7 @@ public: static int64_t int64_tFromJson(web::json::value& val); static int32_t int32_tFromJson(web::json::value& val); + static float floatFromJson(web::json::value& val); static utility::string_t stringFromJson(web::json::value& val); static utility::datetime dateFromJson(web::json::value& val); static double doubleFromJson(web::json::value& val); @@ -59,6 +60,7 @@ public: static int64_t int64_tFromHttpContent(std::shared_ptr val); static int32_t int32_tFromHttpContent(std::shared_ptr val); + static float floatFromHttpContent(std::shared_ptr val); static utility::string_t stringFromHttpContent(std::shared_ptr val); static utility::datetime dateFromHttpContent(std::shared_ptr val); static bool boolFromHttpContent(std::shared_ptr val); diff --git a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache index 9c34ab37f7d..1ad866893af 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/modelbase-source.mustache @@ -262,6 +262,10 @@ int32_t ModelBase::int32_tFromJson(web::json::value& val) { return val.as_integer(); } +float ModelBase::floatFromJson(web::json::value& val) +{ + return val.as_double(); +} utility::string_t ModelBase::stringFromJson(web::json::value& val) { return val.is_string() ? val.as_string() : U(""); @@ -298,6 +302,15 @@ int32_t ModelBase::int32_tFromHttpContent(std::shared_ptr val) ss >> result; return result; } +float ModelBase::floatFromHttpContent(std::shared_ptr val) +{ + utility::string_t str = ModelBase::stringFromHttpContent(val); + + utility::stringstream_t ss(str); + float result = 0; + ss >> result; + return result; +} utility::string_t ModelBase::stringFromHttpContent(std::shared_ptr val) { std::shared_ptr data = val->getData();