2016-06-18 10:09:19 +00:00
/**
* Swagger Petstore
2016-12-13 08:09:56 +00:00
* 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.
2016-06-18 10:09:19 +00:00
*
* OpenAPI spec version : 1.0 .0
2016-12-13 08:09:56 +00:00
* Contact : apiteam @ swagger . io
2016-06-18 10:09:19 +00:00
*
* NOTE : This class is auto generated by the swagger code generator program .
* https : //github.com/swagger-api/swagger-codegen.git
* Do not edit the class manually .
*/
2016-06-14 08:33:50 +00:00
# include "PetApi.h"
# include "IHttpBody.h"
# include "JsonBody.h"
# include "MultipartFormData.h"
# include <unordered_set>
# include <boost/algorithm/string/replace.hpp>
namespace io {
namespace swagger {
namespace client {
namespace api {
using namespace io : : swagger : : client : : model ;
PetApi : : PetApi ( std : : shared_ptr < ApiClient > apiClient )
: m_ApiClient ( apiClient )
{
}
PetApi : : ~ PetApi ( )
{
}
pplx : : task < void > PetApi : : addPet ( std : : shared_ptr < Pet > body )
{
2016-12-13 08:09:56 +00:00
// verify the required parameter 'body' is set
if ( body = = nullptr )
{
throw ApiException ( 400 , U ( " Missing required parameter 'body' when calling PetApi->addPet " ) ) ;
}
2016-06-14 08:33:50 +00:00
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->addPet does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
consumeHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
consumeHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
web : : json : : value json ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
json = ModelBase : : toJson ( body ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
httpBody = std : : shared_ptr < IHttpBody > ( new JsonBody ( json ) ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
std : : shared_ptr < MultipartFormData > multipart ( new MultipartFormData ) ;
2016-12-13 08:09:56 +00:00
if ( body . get ( ) )
2016-06-14 08:33:50 +00:00
{
body - > toMultipart ( multipart , U ( " body " ) ) ;
}
httpBody = multipart ;
requestHttpContentType + = U ( " ; boundary= " ) + multipart - > getBoundary ( ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->addPet does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " POST " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling addPet: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling addPet: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
return void ( ) ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < void > PetApi : : deletePet ( int64_t petId , utility : : string_t apiKey )
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/{petId} " ) ;
boost : : replace_all ( path , U ( " { " ) U ( " petId " ) U ( " } " ) , ApiClient : : parameterToString ( petId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->deletePet does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
{
headerParams [ U ( " api_key " ) ] = ApiClient : : parameterToString ( apiKey ) ;
}
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->deletePet does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " DELETE " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling deletePet: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling deletePet: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
return void ( ) ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < std : : vector < std : : shared_ptr < Pet > > > PetApi : : findPetsByStatus ( std : : vector < utility : : string_t > status )
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/findByStatus " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->findPetsByStatus does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
{
queryParams [ U ( " status " ) ] = ApiClient : : parameterToArrayString < utility : : string_t > ( status ) ;
}
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->findPetsByStatus does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " GET " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling findPetsByStatus: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling findPetsByStatus: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : vector < std : : shared_ptr < Pet > > result ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
if ( responseHttpContentType = = U ( " application/json " ) )
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
for ( auto & item : json . as_array ( ) )
{
std : : shared_ptr < Pet > itemObj ( new Pet ( ) ) ;
itemObj - > fromJson ( item ) ;
2016-12-13 08:09:56 +00:00
result . push_back ( itemObj ) ;
2016-06-14 08:33:50 +00:00
}
}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
, U ( " error calling findPetsByStatus: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < std : : vector < std : : shared_ptr < Pet > > > PetApi : : findPetsByTags ( std : : vector < utility : : string_t > tags )
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/findByTags " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->findPetsByTags does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
{
2017-01-13 16:07:06 +00:00
queryParams [ U ( " tags " ) ] = ApiClient : : parameterToArrayString < > ( tags ) ;
2016-06-14 08:33:50 +00:00
}
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->findPetsByTags does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " GET " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling findPetsByTags: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling findPetsByTags: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : vector < std : : shared_ptr < Pet > > result ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
if ( responseHttpContentType = = U ( " application/json " ) )
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
for ( auto & item : json . as_array ( ) )
{
std : : shared_ptr < Pet > itemObj ( new Pet ( ) ) ;
itemObj - > fromJson ( item ) ;
2016-12-13 08:09:56 +00:00
result . push_back ( itemObj ) ;
2016-06-14 08:33:50 +00:00
}
}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
, U ( " error calling findPetsByStatus: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < std : : shared_ptr < Pet > > PetApi : : getPetById ( int64_t petId )
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/{petId} " ) ;
boost : : replace_all ( path , U ( " { " ) U ( " petId " ) U ( " } " ) , ApiClient : : parameterToString ( petId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->getPetById does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->getPetById does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (api_key) required
{
utility : : string_t apiKey = apiConfiguration - > getApiKey ( U ( " api_key " ) ) ;
if ( apiKey . size ( ) > 0 )
{
headerParams [ U ( " api_key " ) ] = apiKey ;
}
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " GET " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling getPetById: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling getPetById: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
std : : shared_ptr < Pet > result ( new Pet ( ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
if ( responseHttpContentType = = U ( " application/json " ) )
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
result - > fromJson ( json ) ;
}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
2016-12-13 08:09:56 +00:00
// TODO multipart response parsing
2016-06-14 08:33:50 +00:00
// }
2016-12-13 08:09:56 +00:00
else
2016-06-14 08:33:50 +00:00
{
2016-11-16 13:44:49 +00:00
throw ApiException ( 500
, U ( " error calling findPetsByStatus: unsupported response type " ) ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return result ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
pplx : : task < void > PetApi : : updatePet ( std : : shared_ptr < Pet > body )
{
2016-12-13 08:09:56 +00:00
// verify the required parameter 'body' is set
if ( body = = nullptr )
{
throw ApiException ( 400 , U ( " Missing required parameter 'body' when calling PetApi->updatePet " ) ) ;
}
2016-06-14 08:33:50 +00:00
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet " ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->updatePet does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
consumeHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
consumeHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-06-14 08:33:50 +00:00
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
web : : json : : value json ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
json = ModelBase : : toJson ( body ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
httpBody = std : : shared_ptr < IHttpBody > ( new JsonBody ( json ) ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
std : : shared_ptr < MultipartFormData > multipart ( new MultipartFormData ) ;
2016-12-13 08:09:56 +00:00
if ( body . get ( ) )
2016-06-14 08:33:50 +00:00
{
body - > toMultipart ( multipart , U ( " body " ) ) ;
}
httpBody = multipart ;
requestHttpContentType + = U ( " ; boundary= " ) + multipart - > getBoundary ( ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->updatePet does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " PUT " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling updatePet: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling updatePet: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
return void ( ) ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
pplx : : task < void > PetApi : : updatePetWithForm ( int64_t petId , utility : : string_t name , utility : : string_t status )
2016-06-14 08:33:50 +00:00
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/{petId} " ) ;
boost : : replace_all ( path , U ( " { " ) U ( " petId " ) U ( " } " ) , ApiClient : : parameterToString ( petId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
2016-12-13 08:09:56 +00:00
responseHttpContentTypes . insert ( U ( " application/xml " ) ) ;
2016-12-13 07:01:48 +00:00
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->updatePetWithForm does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
consumeHttpContentTypes . insert ( U ( " application/x-www-form-urlencoded " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
{
formParams [ U ( " name " ) ] = ApiClient : : parameterToString ( name ) ;
}
{
formParams [ U ( " status " ) ] = ApiClient : : parameterToString ( status ) ;
}
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->updatePetWithForm does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " POST " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling updatePetWithForm: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling updatePetWithForm: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
return void ( ) ;
2016-12-13 08:09:56 +00:00
} ) ;
2016-06-14 08:33:50 +00:00
}
2016-12-13 08:09:56 +00:00
pplx : : task < std : : shared_ptr < ApiResponse > > PetApi : : uploadFile ( int64_t petId , utility : : string_t additionalMetadata , std : : shared_ptr < HttpContent > file )
2016-06-14 08:33:50 +00:00
{
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : shared_ptr < ApiConfiguration > apiConfiguration ( m_ApiClient - > getConfiguration ( ) ) ;
utility : : string_t path = U ( " /pet/{petId}/uploadImage " ) ;
boost : : replace_all ( path , U ( " { " ) U ( " petId " ) U ( " } " ) , ApiClient : : parameterToString ( petId ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : map < utility : : string_t , utility : : string_t > queryParams ;
std : : map < utility : : string_t , utility : : string_t > headerParams ( apiConfiguration - > getDefaultHeaders ( ) ) ;
std : : map < utility : : string_t , utility : : string_t > formParams ;
std : : map < utility : : string_t , std : : shared_ptr < HttpContent > > fileParams ;
std : : unordered_set < utility : : string_t > responseHttpContentTypes ;
responseHttpContentTypes . insert ( U ( " application/json " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
utility : : string_t responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
2016-12-13 07:01:48 +00:00
if ( responseHttpContentTypes . size ( ) = = 0 )
{
responseHttpContentType = U ( " application/json " ) ;
}
// JSON
else if ( responseHttpContentTypes . find ( U ( " application/json " ) ) ! = responseHttpContentTypes . end ( ) )
2016-06-14 08:33:50 +00:00
{
responseHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( responseHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = responseHttpContentTypes . end ( ) )
{
responseHttpContentType = U ( " multipart/form-data " ) ;
}
2016-11-16 13:44:49 +00:00
else
2016-06-14 08:33:50 +00:00
{
throw ApiException ( 400 , U ( " PetApi->uploadFile does not produce any supported media type " ) ) ;
2016-12-13 08:09:56 +00:00
}
2016-06-14 08:33:50 +00:00
headerParams [ U ( " Accept " ) ] = responseHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
std : : unordered_set < utility : : string_t > consumeHttpContentTypes ;
consumeHttpContentTypes . insert ( U ( " multipart/form-data " ) ) ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
{
formParams [ U ( " additionalMetadata " ) ] = ApiClient : : parameterToString ( additionalMetadata ) ;
}
if ( file ! = nullptr )
{
fileParams [ U ( " file " ) ] = file ;
}
std : : shared_ptr < IHttpBody > httpBody ;
utility : : string_t requestHttpContentType ;
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
// use JSON if possible
if ( consumeHttpContentTypes . size ( ) = = 0 | | consumeHttpContentTypes . find ( U ( " application/json " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " application/json " ) ;
}
2016-12-13 08:09:56 +00:00
// multipart formdata
2016-06-14 08:33:50 +00:00
else if ( consumeHttpContentTypes . find ( U ( " multipart/form-data " ) ) ! = consumeHttpContentTypes . end ( ) )
{
requestHttpContentType = U ( " multipart/form-data " ) ;
}
else
{
throw ApiException ( 415 , U ( " PetApi->uploadFile does not consume any supported media type " ) ) ;
2016-12-13 07:01:48 +00:00
}
2016-12-13 08:09:56 +00:00
//Set the request content type in the header.
headerParams [ U ( " Content-Type " ) ] = requestHttpContentType ;
2016-06-14 08:33:50 +00:00
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
2016-12-13 08:09:56 +00:00
2016-06-14 08:33:50 +00:00
return m_ApiClient - > callApi ( path , U ( " POST " ) , queryParams , httpBody , headerParams , formParams , fileParams , requestHttpContentType )
. then ( [ = ] ( web : : http : : http_response response )
{
2016-11-16 13:44:49 +00:00
// 1xx - informational : OK
// 2xx - successful : OK
2016-12-13 08:09:56 +00:00
// 3xx - redirection : OK
2016-11-16 13:44:49 +00:00
// 4xx - client error : not OK
// 5xx - client error : not OK
if ( response . status_code ( ) > = 400 )
{
throw ApiException ( response . status_code ( )
, U ( " error calling uploadFile: " ) + response . reason_phrase ( )
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
// check response content type
2016-06-14 08:33:50 +00:00
if ( response . headers ( ) . has ( U ( " Content-Type " ) ) )
{
utility : : string_t contentType = response . headers ( ) [ U ( " Content-Type " ) ] ;
if ( contentType . find ( responseHttpContentType ) = = std : : string : : npos )
{
throw ApiException ( 500
, U ( " error calling uploadFile: unexpected response type: " ) + contentType
, std : : make_shared < std : : stringstream > ( response . extract_utf8string ( true ) . get ( ) ) ) ;
}
}
2016-12-13 08:09:56 +00:00
2016-11-16 13:44:49 +00:00
return response . extract_string ( ) ;
2016-06-14 08:33:50 +00:00
} )
. then ( [ = ] ( utility : : string_t response )
{
2016-12-13 08:09:56 +00:00
std : : shared_ptr < ApiResponse > result ( new ApiResponse ( ) ) ;
if ( responseHttpContentType = = U ( " application/json " ) )
{
web : : json : : value json = web : : json : : value : : parse ( response ) ;
result - > fromJson ( json ) ;
}
// else if(responseHttpContentType == U("multipart/form-data"))
// {
// TODO multipart response parsing
// }
else
{
throw ApiException ( 500
, U ( " error calling findPetsByStatus: unsupported response type " ) ) ;
}
return result ;
} ) ;
2016-06-14 08:33:50 +00:00
}
}
}
}
}