#include "StoreApi.h" #include "IHttpBody.h" #include "JsonBody.h" #include "MultipartFormData.h" #include #include namespace io { namespace swagger { namespace client { namespace api { using namespace io::swagger::client::model; StoreApi::StoreApi( std::shared_ptr apiClient ) : m_ApiClient(apiClient) { } StoreApi::~StoreApi() { } pplx::task StoreApi::deleteOrder(utility::string_t orderId) { std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); utility::string_t path = U("/store/order/{orderId}"); boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId)); std::map queryParams; std::map headerParams( apiConfiguration->getDefaultHeaders() ); std::map formParams; std::map> fileParams; std::unordered_set responseHttpContentTypes; responseHttpContentTypes.insert( U("application/xml") ); responseHttpContentTypes.insert( U("application/json") ); utility::string_t responseHttpContentType; // use JSON if possible if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("application/json"); } // multipart formdata else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("multipart/form-data"); } else { throw ApiException(400, U("StoreApi->deleteOrder does not produce any supported media type")); } headerParams[U("Accept")] = responseHttpContentType; std::unordered_set consumeHttpContentTypes; { } std::shared_ptr httpBody; utility::string_t requestHttpContentType; // use JSON if possible if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("application/json"); } // multipart formdata else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("multipart/form-data"); } else { throw ApiException(415, U("StoreApi->deleteOrder does not consume any supported media type")); } return m_ApiClient->callApi(path, U("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() , U("error calling deleteOrder: ") + response.reason_phrase() , std::make_shared(response.extract_utf8string(true).get())); } // check response content type 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 deleteOrder: unexpected response type: ") + contentType , std::make_shared(response.extract_utf8string(true).get())); } } return response.extract_string(); }) .then([=](utility::string_t response) { return void(); }); } pplx::task> StoreApi::getInventory() { std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); utility::string_t path = U("/store/inventory"); std::map queryParams; std::map headerParams( apiConfiguration->getDefaultHeaders() ); std::map formParams; std::map> fileParams; std::unordered_set responseHttpContentTypes; responseHttpContentTypes.insert( U("application/json") ); utility::string_t responseHttpContentType; // use JSON if possible if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("application/json"); } // multipart formdata else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("multipart/form-data"); } else { throw ApiException(400, U("StoreApi->getInventory does not produce any supported media type")); } headerParams[U("Accept")] = responseHttpContentType; std::unordered_set consumeHttpContentTypes; std::shared_ptr httpBody; utility::string_t requestHttpContentType; // use JSON if possible if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("application/json"); } // multipart formdata else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("multipart/form-data"); } else { throw ApiException(415, U("StoreApi->getInventory does not consume any supported media type")); } // authentication (api_key) required { utility::string_t apiKey = apiConfiguration->getApiKey(U("api_key")); if ( apiKey.size() > 0 ) { headerParams[U("api_key")] = apiKey; } } return m_ApiClient->callApi(path, U("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() , U("error calling getInventory: ") + response.reason_phrase() , std::make_shared(response.extract_utf8string(true).get())); } // check response content type 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 getInventory: unexpected response type: ") + contentType , std::make_shared(response.extract_utf8string(true).get())); } } return response.extract_string(); }) .then([=](utility::string_t response) { std::map result; if(responseHttpContentType == U("application/json")) { web::json::value json = web::json::value::parse(response); for( auto& item : json.as_object() ) { result[item.first] = ModelBase::int32_tFromJson(item.second); } } // else if(responseHttpContentType == U("multipart/form-data")) // { // TODO multipart response parsing // } else { throw ApiException(500 , U("error calling findPetsByStatus: unsupported response type")); } return result; }); } pplx::task> StoreApi::getOrderById(int64_t orderId) { std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); utility::string_t path = U("/store/order/{orderId}"); boost::replace_all(path, U("{") U("orderId") U("}"), ApiClient::parameterToString(orderId)); std::map queryParams; std::map headerParams( apiConfiguration->getDefaultHeaders() ); std::map formParams; std::map> fileParams; std::unordered_set responseHttpContentTypes; responseHttpContentTypes.insert( U("application/xml") ); responseHttpContentTypes.insert( U("application/json") ); utility::string_t responseHttpContentType; // use JSON if possible if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("application/json"); } // multipart formdata else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("multipart/form-data"); } else { throw ApiException(400, U("StoreApi->getOrderById does not produce any supported media type")); } headerParams[U("Accept")] = responseHttpContentType; std::unordered_set consumeHttpContentTypes; { } std::shared_ptr httpBody; utility::string_t requestHttpContentType; // use JSON if possible if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("application/json"); } // multipart formdata else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("multipart/form-data"); } else { throw ApiException(415, U("StoreApi->getOrderById does not consume any supported media type")); } return m_ApiClient->callApi(path, U("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() , U("error calling getOrderById: ") + response.reason_phrase() , std::make_shared(response.extract_utf8string(true).get())); } // check response content type 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 getOrderById: unexpected response type: ") + contentType , std::make_shared(response.extract_utf8string(true).get())); } } return response.extract_string(); }) .then([=](utility::string_t response) { std::shared_ptr result(new Order()); 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; }); } pplx::task> StoreApi::placeOrder(std::shared_ptr body) { // verify the required parameter 'body' is set if (body == nullptr) { throw ApiException(400, U("Missing required parameter 'body' when calling StoreApi->placeOrder")); } std::shared_ptr apiConfiguration( m_ApiClient->getConfiguration() ); utility::string_t path = U("/store/order"); std::map queryParams; std::map headerParams( apiConfiguration->getDefaultHeaders() ); std::map formParams; std::map> fileParams; std::unordered_set responseHttpContentTypes; responseHttpContentTypes.insert( U("application/xml") ); responseHttpContentTypes.insert( U("application/json") ); utility::string_t responseHttpContentType; // use JSON if possible if ( responseHttpContentTypes.size() == 0 || responseHttpContentTypes.find(U("application/json")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("application/json"); } // multipart formdata else if( responseHttpContentTypes.find(U("multipart/form-data")) != responseHttpContentTypes.end() ) { responseHttpContentType = U("multipart/form-data"); } else { throw ApiException(400, U("StoreApi->placeOrder does not produce any supported media type")); } headerParams[U("Accept")] = responseHttpContentType; std::unordered_set consumeHttpContentTypes; std::shared_ptr httpBody; utility::string_t requestHttpContentType; // use JSON if possible if ( consumeHttpContentTypes.size() == 0 || consumeHttpContentTypes.find(U("application/json")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("application/json"); web::json::value json; json = ModelBase::toJson(body); httpBody = std::shared_ptr( new JsonBody( json ) ); } // multipart formdata else if( consumeHttpContentTypes.find(U("multipart/form-data")) != consumeHttpContentTypes.end() ) { requestHttpContentType = U("multipart/form-data"); std::shared_ptr multipart(new MultipartFormData); if(body.get()) { body->toMultipart(multipart, U("body")); } httpBody = multipart; requestHttpContentType += U("; boundary=") + multipart->getBoundary(); } else { throw ApiException(415, U("StoreApi->placeOrder does not consume any supported media type")); } return m_ApiClient->callApi(path, U("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() , U("error calling placeOrder: ") + response.reason_phrase() , std::make_shared(response.extract_utf8string(true).get())); } // check response content type 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 placeOrder: unexpected response type: ") + contentType , std::make_shared(response.extract_utf8string(true).get())); } } return response.extract_string(); }) .then([=](utility::string_t response) { std::shared_ptr result(new Order()); 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; }); } } } } }