Skip to content

Commit 4060a4f

Browse files
pieterlexisMikeRalphson
authored andcommitted
cpprest: Add conversion for bool in query param (#71)
Due to c++ conversion rules, bools in query parameters were passed as 1 an 0 (using a bool -> int implicit conversion) instead of true and false. The OpenAPI 3 spec has this to say about the value of a boolean: > Boolean > type: boolean represents two values: true and false. Note that truthy and > falsy values such as "true", "", 0 or null are not considered boolean values. This commit adds a util function to convert a bool query param into a true or false as a query param. Before: GET /foo?bar=0 HTTP/1.1 After: GET /foo?bar=false HTTP/1.1
1 parent f5e7fe1 commit 4060a4f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

templates/cpprest/apiclient-header.mustache

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public:
3636
void setConfiguration(std::shared_ptr<ApiConfiguration> configuration);
3737
3838
static utility::string_t parameterToString(utility::string_t value);
39+
static utility::string_t parameterToString(bool value);
3940
static utility::string_t parameterToString(int32_t value);
4041
static utility::string_t parameterToString(int64_t value);
4142
static utility::string_t parameterToString(float value);

templates/cpprest/apiclient-source.mustache

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ utility::string_t ApiClient::parameterToString(utility::string_t value)
3131
{
3232
return value;
3333
}
34+
utility::string_t ApiClient::parameterToString(bool value)
35+
{
36+
if (value) {
37+
return utility::conversions::to_string_t("true");
38+
}
39+
return utility::conversions::to_string_t("false");
40+
}
3441
utility::string_t ApiClient::parameterToString(int64_t value)
3542
{
3643
std::stringstream valueAsStringStream;

0 commit comments

Comments
 (0)