Fix for issue #4370 - Cpprest does not set Content-Type header on POST requests. (#4374)

* Fixed cpprest generator to include Content-Type header in requests.

* Fixing indent to use spaces.
This commit is contained in:
Scott Richter
2016-12-13 02:01:48 -05:00
committed by wing328
parent 15a84259aa
commit da9d64d053
32 changed files with 349 additions and 222 deletions

View File

@@ -1,9 +1,9 @@
/**
* Swagger Petstore
* This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \"special-key\" to test the authorization filters
*
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
* Contact: apiteam@wordnik.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
@@ -39,12 +39,6 @@ UserApi::~UserApi()
pplx::task<void> UserApi::createUser(std::shared_ptr<User> body)
{
// verify the required parameter 'body' is set
if (body == nullptr)
{
throw ApiException(400, U("Missing required parameter 'body' when calling UserApi->createUser"));
}
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = U("/user");
@@ -55,13 +49,18 @@ pplx::task<void> UserApi::createUser(std::shared_ptr<User> body)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -116,7 +115,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->createUser does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -166,13 +168,18 @@ pplx::task<void> UserApi::createUsersWithArrayInput(std::vector<std::shared_ptr<
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -241,7 +248,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->createUsersWithArrayInput does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -291,13 +301,18 @@ pplx::task<void> UserApi::createUsersWithListInput(std::vector<std::shared_ptr<U
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -366,7 +381,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->createUsersWithListInput does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -417,13 +435,18 @@ pplx::task<void> UserApi::deleteUser(utility::string_t username)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -465,7 +488,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->deleteUser does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -516,13 +542,18 @@ pplx::task<std::shared_ptr<User>> UserApi::getUserByName(utility::string_t usern
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -564,7 +595,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->getUserByName does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -632,13 +666,18 @@ pplx::task<utility::string_t> UserApi::loginUser(utility::string_t username, uti
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("text/plain");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -647,6 +686,11 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
// plain text
else if( responseHttpContentTypes.find(U("text/plain")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("text/plain");
}
else
{
throw ApiException(400, U("UserApi->loginUser does not produce any supported media type"));
@@ -686,7 +730,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->loginUser does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -729,6 +776,10 @@ responseHttpContentTypes.insert( U("application/json") );
result = ModelBase::stringFromJson(json);
}
else if(responseHttpContentType == U("text/plain"))
{
result = response;
}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
// TODO multipart response parsing
@@ -755,13 +806,18 @@ pplx::task<void> UserApi::logoutUser()
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -799,7 +855,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->logoutUser does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
@@ -839,12 +898,6 @@ responseHttpContentTypes.insert( U("application/json") );
pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr<User> body)
{
// verify the required parameter 'body' is set
if (body == nullptr)
{
throw ApiException(400, U("Missing required parameter 'body' when calling UserApi->updateUser"));
}
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = U("/user/{username}");
@@ -856,13 +909,18 @@ pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
// use JSON if possible
if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
if ( responseHttpContentTypes.size() == 0 )
{
responseHttpContentType = U("application/json");
}
// JSON
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
{
responseHttpContentType = U("application/json");
}
@@ -921,7 +979,10 @@ responseHttpContentTypes.insert( U("application/json") );
else
{
throw ApiException(415, U("UserApi->updateUser does not consume any supported media type"));
}
}
//Set the request content type in the header.
headerParams[U("Content-Type")] = requestHttpContentType;
return m_ApiClient->callApi(path, U("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)