forked from loafle/openapi-generator-original
[CppRest] Remove U macro (#6903)
* [CppRest] Replace U macro with conversion function for default string values. * [CppRest] Replace U macro with conversion function in templates. * [CppRest] Update cpprest petstore client sample.
This commit is contained in:
@@ -41,8 +41,8 @@ pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/order/{orderId}");
|
||||
boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId));
|
||||
utility::string_t path = utility::conversions::to_string_t("/store/order/{orderId}");
|
||||
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("orderId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(orderId));
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
@@ -50,32 +50,32 @@ pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
|
||||
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( utility::conversions::to_string_t("application/xml") );
|
||||
responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
||||
|
||||
utility::string_t responseHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( responseHttpContentTypes.size() == 0 )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// JSON
|
||||
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
|
||||
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("multipart/form-data");
|
||||
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(400, U("StoreApi->deleteOrder does not produce any supported media type"));
|
||||
throw ApiException(400, utility::conversions::to_string_t("StoreApi->deleteOrder does not produce any supported media type"));
|
||||
}
|
||||
|
||||
headerParams[U("Accept")] = responseHttpContentType;
|
||||
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
||||
|
||||
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
@@ -84,22 +84,22 @@ pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
|
||||
utility::string_t requestHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() )
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("application/json");
|
||||
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(415, U("StoreApi->deleteOrder does not consume any supported media type"));
|
||||
throw ApiException(415, utility::conversions::to_string_t("StoreApi->deleteOrder does not consume any supported media type"));
|
||||
}
|
||||
|
||||
|
||||
return m_ApiClient->callApi(path, U("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
return m_ApiClient->callApi(path, utility::conversions::to_string_t("DELETE"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
.then([=](web::http::http_response response)
|
||||
{
|
||||
// 1xx - informational : OK
|
||||
@@ -110,18 +110,18 @@ pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
|
||||
if (response.status_code() >= 400)
|
||||
{
|
||||
throw ApiException(response.status_code()
|
||||
, U("error calling deleteOrder: ") + response.reason_phrase()
|
||||
, utility::conversions::to_string_t("error calling deleteOrder: ") + response.reason_phrase()
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
|
||||
// check response content type
|
||||
if(response.headers().has(U("Content-Type")))
|
||||
if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
|
||||
{
|
||||
utility::string_t contentType = response.headers()[U("Content-Type")];
|
||||
utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
|
||||
if( contentType.find(responseHttpContentType) == std::string::npos )
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling deleteOrder: unexpected response type: ") + contentType
|
||||
, utility::conversions::to_string_t("error calling deleteOrder: unexpected response type: ") + contentType
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
@@ -138,7 +138,7 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/inventory");
|
||||
utility::string_t path = utility::conversions::to_string_t("/store/inventory");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
@@ -146,31 +146,31 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
|
||||
|
||||
std::unordered_set<utility::string_t> responseHttpContentTypes;
|
||||
responseHttpContentTypes.insert( U("application/json") );
|
||||
responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
||||
|
||||
utility::string_t responseHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( responseHttpContentTypes.size() == 0 )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// JSON
|
||||
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
|
||||
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("multipart/form-data");
|
||||
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(400, U("StoreApi->getInventory does not produce any supported media type"));
|
||||
throw ApiException(400, utility::conversions::to_string_t("StoreApi->getInventory does not produce any supported media type"));
|
||||
}
|
||||
|
||||
headerParams[U("Accept")] = responseHttpContentType;
|
||||
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
||||
|
||||
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
@@ -179,30 +179,30 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
utility::string_t requestHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() )
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("application/json");
|
||||
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(415, U("StoreApi->getInventory does not consume any supported media type"));
|
||||
throw ApiException(415, utility::conversions::to_string_t("StoreApi->getInventory does not consume any supported media type"));
|
||||
}
|
||||
|
||||
// authentication (api_key) required
|
||||
{
|
||||
utility::string_t apiKey = apiConfiguration->getApiKey(U("api_key"));
|
||||
utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api_key"));
|
||||
if ( apiKey.size() > 0 )
|
||||
{
|
||||
headerParams[U("api_key")] = apiKey;
|
||||
headerParams[utility::conversions::to_string_t("api_key")] = apiKey;
|
||||
}
|
||||
}
|
||||
|
||||
return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
return m_ApiClient->callApi(path, utility::conversions::to_string_t("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
.then([=](web::http::http_response response)
|
||||
{
|
||||
// 1xx - informational : OK
|
||||
@@ -213,18 +213,18 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
if (response.status_code() >= 400)
|
||||
{
|
||||
throw ApiException(response.status_code()
|
||||
, U("error calling getInventory: ") + response.reason_phrase()
|
||||
, utility::conversions::to_string_t("error calling getInventory: ") + response.reason_phrase()
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
|
||||
// check response content type
|
||||
if(response.headers().has(U("Content-Type")))
|
||||
if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
|
||||
{
|
||||
utility::string_t contentType = response.headers()[U("Content-Type")];
|
||||
utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
|
||||
if( contentType.find(responseHttpContentType) == std::string::npos )
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling getInventory: unexpected response type: ") + contentType
|
||||
, utility::conversions::to_string_t("error calling getInventory: unexpected response type: ") + contentType
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
@@ -235,7 +235,7 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
{
|
||||
std::map<utility::string_t, int32_t> result;
|
||||
|
||||
if(responseHttpContentType == U("application/json"))
|
||||
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
||||
{
|
||||
web::json::value json = web::json::value::parse(response);
|
||||
|
||||
@@ -246,14 +246,14 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory()
|
||||
}
|
||||
|
||||
}
|
||||
// else if(responseHttpContentType == U("multipart/form-data"))
|
||||
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
||||
// {
|
||||
// TODO multipart response parsing
|
||||
// }
|
||||
else
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling getInventory: unsupported response type"));
|
||||
, utility::conversions::to_string_t("error calling getInventory: unsupported response type"));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -264,8 +264,8 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/order/{orderId}");
|
||||
boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId));
|
||||
utility::string_t path = utility::conversions::to_string_t("/store/order/{orderId}");
|
||||
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("orderId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(orderId));
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
@@ -273,32 +273,32 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
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( utility::conversions::to_string_t("application/xml") );
|
||||
responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
||||
|
||||
utility::string_t responseHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( responseHttpContentTypes.size() == 0 )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// JSON
|
||||
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
|
||||
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("multipart/form-data");
|
||||
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(400, U("StoreApi->getOrderById does not produce any supported media type"));
|
||||
throw ApiException(400, utility::conversions::to_string_t("StoreApi->getOrderById does not produce any supported media type"));
|
||||
}
|
||||
|
||||
headerParams[U("Accept")] = responseHttpContentType;
|
||||
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
||||
|
||||
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
@@ -307,22 +307,22 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
utility::string_t requestHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() )
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("application/json");
|
||||
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(415, U("StoreApi->getOrderById does not consume any supported media type"));
|
||||
throw ApiException(415, utility::conversions::to_string_t("StoreApi->getOrderById does not consume any supported media type"));
|
||||
}
|
||||
|
||||
|
||||
return m_ApiClient->callApi(path, U("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
return m_ApiClient->callApi(path, utility::conversions::to_string_t("GET"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
.then([=](web::http::http_response response)
|
||||
{
|
||||
// 1xx - informational : OK
|
||||
@@ -333,18 +333,18 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
if (response.status_code() >= 400)
|
||||
{
|
||||
throw ApiException(response.status_code()
|
||||
, U("error calling getOrderById: ") + response.reason_phrase()
|
||||
, utility::conversions::to_string_t("error calling getOrderById: ") + response.reason_phrase()
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
|
||||
// check response content type
|
||||
if(response.headers().has(U("Content-Type")))
|
||||
if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
|
||||
{
|
||||
utility::string_t contentType = response.headers()[U("Content-Type")];
|
||||
utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
|
||||
if( contentType.find(responseHttpContentType) == std::string::npos )
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling getOrderById: unexpected response type: ") + contentType
|
||||
, utility::conversions::to_string_t("error calling getOrderById: unexpected response type: ") + contentType
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
@@ -355,20 +355,20 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
|
||||
{
|
||||
std::shared_ptr<Order> result(new Order());
|
||||
|
||||
if(responseHttpContentType == U("application/json"))
|
||||
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
||||
{
|
||||
web::json::value json = web::json::value::parse(response);
|
||||
|
||||
result->fromJson(json);
|
||||
}
|
||||
// else if(responseHttpContentType == U("multipart/form-data"))
|
||||
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
||||
// {
|
||||
// TODO multipart response parsing
|
||||
// }
|
||||
else
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling getOrderById: unsupported response type"));
|
||||
, utility::conversions::to_string_t("error calling getOrderById: unsupported response type"));
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -380,12 +380,12 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
// verify the required parameter 'body' is set
|
||||
if (body == nullptr)
|
||||
{
|
||||
throw ApiException(400, U("Missing required parameter 'body' when calling StoreApi->placeOrder"));
|
||||
throw ApiException(400, utility::conversions::to_string_t("Missing required parameter 'body' when calling StoreApi->placeOrder"));
|
||||
}
|
||||
|
||||
|
||||
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
||||
utility::string_t path = U("/store/order");
|
||||
utility::string_t path = utility::conversions::to_string_t("/store/order");
|
||||
|
||||
std::map<utility::string_t, utility::string_t> queryParams;
|
||||
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
|
||||
@@ -393,32 +393,32 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
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( utility::conversions::to_string_t("application/xml") );
|
||||
responseHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
||||
|
||||
utility::string_t responseHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( responseHttpContentTypes.size() == 0 )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// JSON
|
||||
else if ( responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() )
|
||||
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("application/json");
|
||||
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
}
|
||||
// multipart formdata
|
||||
else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
||||
{
|
||||
responseHttpContentType = U("multipart/form-data");
|
||||
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(400, U("StoreApi->placeOrder does not produce any supported media type"));
|
||||
throw ApiException(400, utility::conversions::to_string_t("StoreApi->placeOrder does not produce any supported media type"));
|
||||
}
|
||||
|
||||
headerParams[U("Accept")] = responseHttpContentType;
|
||||
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
||||
|
||||
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
||||
|
||||
@@ -427,9 +427,9 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
utility::string_t requestHttpContentType;
|
||||
|
||||
// use JSON if possible
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() )
|
||||
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("application/json");
|
||||
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
||||
web::json::value json;
|
||||
|
||||
json = ModelBase::toJson(body);
|
||||
@@ -437,25 +437,25 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
httpBody = std::shared_ptr<IHttpBody>( new JsonBody( json ) );
|
||||
}
|
||||
// multipart formdata
|
||||
else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
||||
{
|
||||
requestHttpContentType = U("multipart/form-data");
|
||||
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
||||
std::shared_ptr<MultipartFormData> multipart(new MultipartFormData);
|
||||
if(body.get())
|
||||
{
|
||||
body->toMultipart(multipart, U("body"));
|
||||
body->toMultipart(multipart, utility::conversions::to_string_t("body"));
|
||||
}
|
||||
|
||||
httpBody = multipart;
|
||||
requestHttpContentType += U("; boundary=") + multipart->getBoundary();
|
||||
requestHttpContentType += utility::conversions::to_string_t("; boundary=") + multipart->getBoundary();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw ApiException(415, U("StoreApi->placeOrder does not consume any supported media type"));
|
||||
throw ApiException(415, utility::conversions::to_string_t("StoreApi->placeOrder does not consume any supported media type"));
|
||||
}
|
||||
|
||||
|
||||
return m_ApiClient->callApi(path, U("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
return m_ApiClient->callApi(path, utility::conversions::to_string_t("POST"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
||||
.then([=](web::http::http_response response)
|
||||
{
|
||||
// 1xx - informational : OK
|
||||
@@ -466,18 +466,18 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
if (response.status_code() >= 400)
|
||||
{
|
||||
throw ApiException(response.status_code()
|
||||
, U("error calling placeOrder: ") + response.reason_phrase()
|
||||
, utility::conversions::to_string_t("error calling placeOrder: ") + response.reason_phrase()
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
|
||||
// check response content type
|
||||
if(response.headers().has(U("Content-Type")))
|
||||
if(response.headers().has(utility::conversions::to_string_t("Content-Type")))
|
||||
{
|
||||
utility::string_t contentType = response.headers()[U("Content-Type")];
|
||||
utility::string_t contentType = response.headers()[utility::conversions::to_string_t("Content-Type")];
|
||||
if( contentType.find(responseHttpContentType) == std::string::npos )
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling placeOrder: unexpected response type: ") + contentType
|
||||
, utility::conversions::to_string_t("error calling placeOrder: unexpected response type: ") + contentType
|
||||
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
||||
}
|
||||
}
|
||||
@@ -488,20 +488,20 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
|
||||
{
|
||||
std::shared_ptr<Order> result(new Order());
|
||||
|
||||
if(responseHttpContentType == U("application/json"))
|
||||
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
||||
{
|
||||
web::json::value json = web::json::value::parse(response);
|
||||
|
||||
result->fromJson(json);
|
||||
}
|
||||
// else if(responseHttpContentType == U("multipart/form-data"))
|
||||
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
||||
// {
|
||||
// TODO multipart response parsing
|
||||
// }
|
||||
else
|
||||
{
|
||||
throw ApiException(500
|
||||
, U("error calling placeOrder: unsupported response type"));
|
||||
, utility::conversions::to_string_t("error calling placeOrder: unsupported response type"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user