forked from loafle/openapi-generator-original
990 lines
41 KiB
C++
990 lines
41 KiB
C++
/**
|
|
* 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.
|
|
*
|
|
* OpenAPI spec version: 1.0.0
|
|
* Contact: apiteam@swagger.io
|
|
*
|
|
* NOTE: This class is auto generated by the swagger code generator 3.0.0-SNAPSHOT.
|
|
* https://github.com/swagger-api/swagger-codegen.git
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
|
|
#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(Pet pet)
|
|
{
|
|
|
|
// verify the required parameter 'pet' is set
|
|
if (pet == nullptr)
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("Missing required parameter 'pet' when calling PetApi->addPet"));
|
|
}
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet");
|
|
|
|
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;
|
|
|
|
utility::string_t responseHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( responseHttpContentTypes.size() == 0 )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->addPet does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
|
|
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
web::json::value json;
|
|
|
|
json = ModelBase::toJson(pet);
|
|
|
|
|
|
httpBody = std::shared_ptr<IHttpBody>( new JsonBody( json ) );
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
std::shared_ptr<MultipartFormData> multipart(new MultipartFormData);
|
|
|
|
if(pet.get())
|
|
{
|
|
pet->toMultipart(multipart, utility::conversions::to_string_t("pet"));
|
|
}
|
|
|
|
httpBody = multipart;
|
|
requestHttpContentType += utility::conversions::to_string_t("; boundary=") + multipart->getBoundary();
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->addPet does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling addPet: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling addPet: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
return void();
|
|
});
|
|
}
|
|
pplx::task<void> PetApi::deletePet(int64_t petId, boost::optional<utility::string_t> apiKey)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/{petId}");
|
|
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("petId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(petId));
|
|
|
|
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;
|
|
|
|
utility::string_t responseHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( responseHttpContentTypes.size() == 0 )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->deletePet does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
|
|
if (apiKey)
|
|
{
|
|
headerParams[utility::conversions::to_string_t("api_key")] = ApiClient::parameterToString(*apiKey);
|
|
}
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->deletePet does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling deletePet: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling deletePet: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
return void();
|
|
});
|
|
}
|
|
pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByStatus(std::vector<utility::string_t> status)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/findByStatus");
|
|
|
|
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( 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 = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->findPetsByStatus does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
|
|
{
|
|
queryParams[utility::conversions::to_string_t("status")] = ApiClient::parameterToString(status);
|
|
}
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->findPetsByStatus does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling findPetsByStatus: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling findPetsByStatus: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
std::vector<std::shared_ptr<Pet>> result;
|
|
|
|
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
|
{
|
|
web::json::value json = web::json::value::parse(response);
|
|
|
|
for( auto& item : json.as_array() )
|
|
{
|
|
std::shared_ptr<Pet> itemObj(new Pet());
|
|
itemObj->fromJson(item);
|
|
result.push_back(itemObj);
|
|
|
|
}
|
|
|
|
}
|
|
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
|
// {
|
|
// TODO multipart response parsing
|
|
// }
|
|
else
|
|
{
|
|
throw ApiException(500
|
|
, utility::conversions::to_string_t("error calling findPetsByStatus: unsupported response type"));
|
|
}
|
|
|
|
return result;
|
|
});
|
|
}
|
|
pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByTags(std::vector<utility::string_t> tags)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/findByTags");
|
|
|
|
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( 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 = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->findPetsByTags does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
|
|
{
|
|
queryParams[utility::conversions::to_string_t("tags")] = ApiClient::parameterToString(tags);
|
|
}
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->findPetsByTags does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling findPetsByTags: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling findPetsByTags: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
std::vector<std::shared_ptr<Pet>> result;
|
|
|
|
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
|
{
|
|
web::json::value json = web::json::value::parse(response);
|
|
|
|
for( auto& item : json.as_array() )
|
|
{
|
|
std::shared_ptr<Pet> itemObj(new Pet());
|
|
itemObj->fromJson(item);
|
|
result.push_back(itemObj);
|
|
|
|
}
|
|
|
|
}
|
|
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
|
// {
|
|
// TODO multipart response parsing
|
|
// }
|
|
else
|
|
{
|
|
throw ApiException(500
|
|
, utility::conversions::to_string_t("error calling findPetsByTags: unsupported response type"));
|
|
}
|
|
|
|
return result;
|
|
});
|
|
}
|
|
pplx::task<std::shared_ptr<Pet>> PetApi::getPetById(int64_t petId)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/{petId}");
|
|
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("petId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(petId));
|
|
|
|
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( 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 = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->getPetById does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->getPetById does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (api_key) required
|
|
{
|
|
utility::string_t apiKey = apiConfiguration->getApiKey(utility::conversions::to_string_t("api_key"));
|
|
if ( apiKey.size() > 0 )
|
|
{
|
|
headerParams[utility::conversions::to_string_t("api_key")] = apiKey;
|
|
}
|
|
}
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling getPetById: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling getPetById: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
std::shared_ptr<Pet> result(new Pet());
|
|
|
|
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
|
{
|
|
web::json::value json = web::json::value::parse(response);
|
|
|
|
result->fromJson(json);
|
|
}
|
|
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
|
// {
|
|
// TODO multipart response parsing
|
|
// }
|
|
else
|
|
{
|
|
throw ApiException(500
|
|
, utility::conversions::to_string_t("error calling getPetById: unsupported response type"));
|
|
}
|
|
|
|
return result;
|
|
});
|
|
}
|
|
pplx::task<void> PetApi::updatePet(Pet pet)
|
|
{
|
|
|
|
// verify the required parameter 'pet' is set
|
|
if (pet == nullptr)
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("Missing required parameter 'pet' when calling PetApi->updatePet"));
|
|
}
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet");
|
|
|
|
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;
|
|
|
|
utility::string_t responseHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( responseHttpContentTypes.size() == 0 )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->updatePet does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/json") );
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/xml") );
|
|
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
web::json::value json;
|
|
|
|
json = ModelBase::toJson(pet);
|
|
|
|
|
|
httpBody = std::shared_ptr<IHttpBody>( new JsonBody( json ) );
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
std::shared_ptr<MultipartFormData> multipart(new MultipartFormData);
|
|
|
|
if(pet.get())
|
|
{
|
|
pet->toMultipart(multipart, utility::conversions::to_string_t("pet"));
|
|
}
|
|
|
|
httpBody = multipart;
|
|
requestHttpContentType += utility::conversions::to_string_t("; boundary=") + multipart->getBoundary();
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->updatePet does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
return m_ApiClient->callApi(path, utility::conversions::to_string_t("PUT"), queryParams, httpBody, headerParams, formParams, fileParams, requestHttpContentType)
|
|
.then([=](web::http::http_response response)
|
|
{
|
|
// 1xx - informational : OK
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling updatePet: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling updatePet: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
return void();
|
|
});
|
|
}
|
|
pplx::task<void> PetApi::updatePetWithForm(int64_t petId, boost::optional<utility::string_t> name, boost::optional<utility::string_t> status)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/{petId}");
|
|
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("petId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(petId));
|
|
|
|
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;
|
|
|
|
utility::string_t responseHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( responseHttpContentTypes.size() == 0 )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->updatePetWithForm does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("application/x-www-form-urlencoded") );
|
|
|
|
if (name)
|
|
{
|
|
formParams[ utility::conversions::to_string_t("name") ] = ApiClient::parameterToString(*name);
|
|
}
|
|
if (status)
|
|
{
|
|
formParams[ utility::conversions::to_string_t("status") ] = ApiClient::parameterToString(*status);
|
|
}
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->updatePetWithForm does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling updatePetWithForm: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling updatePetWithForm: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
return void();
|
|
});
|
|
}
|
|
pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost::optional<utility::string_t> additionalMetadata, boost::optional<HttpContent> file)
|
|
{
|
|
|
|
|
|
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
|
|
utility::string_t path = utility::conversions::to_string_t("/pet/{petId}/uploadImage");
|
|
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("petId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(petId));
|
|
|
|
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( utility::conversions::to_string_t("application/json") );
|
|
|
|
utility::string_t responseHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( responseHttpContentTypes.size() == 0 )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// JSON
|
|
else if ( responseHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( responseHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != responseHttpContentTypes.end() )
|
|
{
|
|
responseHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(400, utility::conversions::to_string_t("PetApi->uploadFile does not produce any supported media type"));
|
|
}
|
|
|
|
headerParams[utility::conversions::to_string_t("Accept")] = responseHttpContentType;
|
|
|
|
std::unordered_set<utility::string_t> consumeHttpContentTypes;
|
|
consumeHttpContentTypes.insert( utility::conversions::to_string_t("multipart/form-data") );
|
|
|
|
if (additionalMetadata)
|
|
{
|
|
formParams[ utility::conversions::to_string_t("additionalMetadata") ] = ApiClient::parameterToString(*additionalMetadata);
|
|
}
|
|
if (file)
|
|
{
|
|
fileParams[ utility::conversions::to_string_t("file") ] = *file;
|
|
}
|
|
|
|
std::shared_ptr<IHttpBody> httpBody;
|
|
utility::string_t requestHttpContentType;
|
|
|
|
// use JSON if possible
|
|
if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(utility::conversions::to_string_t("application/json")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("application/json");
|
|
}
|
|
// multipart formdata
|
|
else if( consumeHttpContentTypes.find(utility::conversions::to_string_t("multipart/form-data")) != consumeHttpContentTypes.end() )
|
|
{
|
|
requestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
|
|
}
|
|
else
|
|
{
|
|
throw ApiException(415, utility::conversions::to_string_t("PetApi->uploadFile does not consume any supported media type"));
|
|
}
|
|
|
|
// authentication (petstore_auth) required
|
|
// oauth2 authentication is added automatically as part of the http_client_config
|
|
|
|
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
|
|
// 2xx - successful : OK
|
|
// 3xx - redirection : OK
|
|
// 4xx - client error : not OK
|
|
// 5xx - client error : not OK
|
|
if (response.status_code() >= 400)
|
|
{
|
|
throw ApiException(response.status_code()
|
|
, utility::conversions::to_string_t("error calling uploadFile: ") + response.reason_phrase()
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
|
|
// check response content type
|
|
if(response.headers().has(utility::conversions::to_string_t("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
|
|
, utility::conversions::to_string_t("error calling uploadFile: unexpected response type: ") + contentType
|
|
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
|
|
}
|
|
}
|
|
|
|
return response.extract_string();
|
|
})
|
|
.then([=](utility::string_t response)
|
|
{
|
|
std::shared_ptr<ApiResponse> result(new ApiResponse());
|
|
|
|
if(responseHttpContentType == utility::conversions::to_string_t("application/json"))
|
|
{
|
|
web::json::value json = web::json::value::parse(response);
|
|
|
|
result->fromJson(json);
|
|
}
|
|
// else if(responseHttpContentType == utility::conversions::to_string_t("multipart/form-data"))
|
|
// {
|
|
// TODO multipart response parsing
|
|
// }
|
|
else
|
|
{
|
|
throw ApiException(500
|
|
, utility::conversions::to_string_t("error calling uploadFile: unsupported response type"));
|
|
}
|
|
|
|
return result;
|
|
});
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|