Skip to content

Commit

Permalink
[cpp-rest-sdk-client] Serialize boolean parameters as true/false inst…
Browse files Browse the repository at this point in the history
…ead of 1/0 (#10554)

* BUG FIX: A missing semicolon in cpp-pistache-server generated code.

* BUG FIX: Provide default values of schema in cpp-pistache-server generated code.

* BUG FIX: Provide default values of schema in cpp-pistache-server generated code.

* Fix a bug in cpprest-sdk generator (Issue #8450)

* Fix a bug in cpprest-sdk generator (Issue #8450)

* Fix a bug in cpprest-sdk generator (Issue #8450)

* Revert "Fix a bug in cpprest-sdk generator (Issue #8450)"

This reverts commit 7d8f842.

* Fix a bug in cpprest-sdk generator (Issue #8450)

* A new overloaded version of parameterToString method is added to the ApiClient class (mustache file) of cpp-rest-sdk-client generator. This new overload accepts bool value and is added to serialize bool values as boolapha instead of integer representation.

* A new overloaded version of parameterToString method is added to the ApiClient class (mustache file) of cpp-rest-sdk-client generator. This new overload accepts bool value and is added to serialize bool values as boolapha instead of integer representation.
  • Loading branch information
shayan-eftekhari committed Oct 13, 2021
1 parent 5defb9a commit 843e572
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public:
static utility::string_t parameterToString(float value);
static utility::string_t parameterToString(double value);
static utility::string_t parameterToString(const utility::datetime &value);
static utility::string_t parameterToString(bool value);
template<class T>
static utility::string_t parameterToString(const std::vector<T>& value);
template<class T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ utility::string_t ApiClient::parameterToString(const utility::datetime &value)
return utility::conversions::to_string_t(value.to_string(utility::datetime::ISO_8601));
}

utility::string_t ApiClient::parameterToString(bool value)
{
std::stringstream valueAsStringStream;
valueAsStringStream << std::boolalpha << value;
return utility::conversions::to_string_t(valueAsStringStream.str());
}

pplx::task<web::http::http_response> ApiClient::callApi(
const utility::string_t& path,
const utility::string_t& method,
Expand Down
7 changes: 7 additions & 0 deletions samples/client/petstore/cpp-restsdk/client/ApiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ utility::string_t ApiClient::parameterToString(const utility::datetime &value)
return utility::conversions::to_string_t(value.to_string(utility::datetime::ISO_8601));
}

utility::string_t ApiClient::parameterToString(bool value)
{
std::stringstream valueAsStringStream;
valueAsStringStream << std::boolalpha << value;
return utility::conversions::to_string_t(valueAsStringStream.str());
}

pplx::task<web::http::http_response> ApiClient::callApi(
const utility::string_t& path,
const utility::string_t& method,
Expand Down
1 change: 1 addition & 0 deletions samples/client/petstore/cpp-restsdk/client/ApiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class ApiClient
static utility::string_t parameterToString(float value);
static utility::string_t parameterToString(double value);
static utility::string_t parameterToString(const utility::datetime &value);
static utility::string_t parameterToString(bool value);
template<class T>
static utility::string_t parameterToString(const std::vector<T>& value);
template<class T>
Expand Down

0 comments on commit 843e572

Please sign in to comment.