Skip to content

Commit 3089fd3

Browse files
authored
Merge pull request #9905 from cipold/master
Fix multiple bugs in generated cpprest client code
2 parents 9396a9f + 9670684 commit 3089fd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+90
-46
lines changed

modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache

Lines changed: 1 addition & 0 deletions
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);

modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ utility::string_t ApiClient::parameterToString(utility::string_t value)
3131
{
3232
return value;
3333
}
34+
35+
utility::string_t ApiClient::parameterToString(bool value)
36+
{
37+
std::stringstream valueAsStringStream;
38+
valueAsStringStream << (value ? "true" : "false");
39+
return utility::conversions::to_string_t(valueAsStringStream.str());
40+
}
41+
3442
utility::string_t ApiClient::parameterToString(int64_t value)
3543
{
3644
std::stringstream valueAsStringStream;
@@ -132,7 +140,20 @@ pplx::task<web::http::http_response> ApiClient::callApi(
132140
if (!formParams.empty())
133141
{
134142
request.set_body(body_data);
135-
}
143+
}
144+
}
145+
else if (contentType == utility::conversions::to_string_t("multipart/form-data"))
146+
{
147+
MultipartFormData uploadData;
148+
for (auto& kvp : formParams)
149+
{
150+
uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second));
151+
}
152+
std::stringstream data;
153+
uploadData.writeTo(data);
154+
auto bodyString = data.str();
155+
auto length = bodyString.size();
156+
request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, utility::conversions::to_string_t("multipart/form-data; boundary=") + uploadData.getBoundary());
136157
}
137158
else
138159
{

modules/swagger-codegen/src/main/resources/cpprest/multipart-source.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void MultipartFormData::writeTo( std::ostream& target )
5959
std::shared_ptr<HttpContent> content = m_Contents[i];
6060
6161
// boundary
62-
target << "\r\n" << "--" << utility::conversions::to_utf8string( m_Boundary ) << "\r\n";
62+
target << (i > 0 ? "\r\n" : "") << "--" << utility::conversions::to_utf8string( m_Boundary ) << "\r\n";
6363
6464
// headers
6565
target << "Content-Disposition: " << utility::conversions::to_utf8string( content->getContentDisposition() );
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.3-SNAPSHOT
1+
2.4.11-SNAPSHOT

samples/client/petstore/cpprest/ApiClient.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/
@@ -43,6 +43,14 @@ utility::string_t ApiClient::parameterToString(utility::string_t value)
4343
{
4444
return value;
4545
}
46+
47+
utility::string_t ApiClient::parameterToString(bool value)
48+
{
49+
std::stringstream valueAsStringStream;
50+
valueAsStringStream << (value ? "true" : "false");
51+
return utility::conversions::to_string_t(valueAsStringStream.str());
52+
}
53+
4654
utility::string_t ApiClient::parameterToString(int64_t value)
4755
{
4856
std::stringstream valueAsStringStream;
@@ -144,7 +152,20 @@ pplx::task<web::http::http_response> ApiClient::callApi(
144152
if (!formParams.empty())
145153
{
146154
request.set_body(body_data);
147-
}
155+
}
156+
}
157+
else if (contentType == utility::conversions::to_string_t("multipart/form-data"))
158+
{
159+
MultipartFormData uploadData;
160+
for (auto& kvp : formParams)
161+
{
162+
uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second));
163+
}
164+
std::stringstream data;
165+
uploadData.writeTo(data);
166+
auto bodyString = data.str();
167+
auto length = bodyString.size();
168+
request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, utility::conversions::to_string_t("multipart/form-data; boundary=") + uploadData.getBoundary());
148169
}
149170
else
150171
{

samples/client/petstore/cpprest/ApiClient.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/
@@ -48,6 +48,7 @@ class ApiClient
4848
void setConfiguration(std::shared_ptr<ApiConfiguration> configuration);
4949

5050
static utility::string_t parameterToString(utility::string_t value);
51+
static utility::string_t parameterToString(bool value);
5152
static utility::string_t parameterToString(int32_t value);
5253
static utility::string_t parameterToString(int64_t value);
5354
static utility::string_t parameterToString(float value);

samples/client/petstore/cpprest/ApiConfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/

samples/client/petstore/cpprest/ApiConfiguration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/

samples/client/petstore/cpprest/ApiException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/

samples/client/petstore/cpprest/ApiException.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* OpenAPI spec version: 1.0.0
66
* Contact: [email protected]
77
*
8-
* NOTE: This class is auto generated by the swagger code generator 2.4.3-SNAPSHOT.
8+
* NOTE: This class is auto generated by the swagger code generator 2.4.11-SNAPSHOT.
99
* https://github.com/swagger-api/swagger-codegen.git
1010
* Do not edit the class manually.
1111
*/

0 commit comments

Comments
 (0)