Akihito Nakano cf657f1c7b [C++] Adjust the names (script, sample folder, generator) to lang option (#220)
* Rename script: qt5-petstore.sh -> cpp-qt5-petstore.sh

* Rename sample folder: qt5cpp -> cpp-qt5

* Rename script: cpprest-petstore.sh -> cpp-restsdk-petstore.sh

* Rename sample folder: cpprest -> cpp-restsdk

* Rename generator: CppRestClientCodegen -> CppRestSdkClientCodegen

* Rename script: tizen-petstore.sh -> cpp-tizen-petstore.sh

* Rename sample folder: tizen -> cpp-tizen

* Rename script(security): qt5cpp-petstore.sh -> cpp-qt5-petstore.sh

* Rename sample folder(security): qt5cpp -> cpp-qt5

* Rename script(windows): qt5cpp-petstore.bat -> cpp-qt5-petstore.bat

* Change sample folder

* Rename script(windows): cpprest-petstore.bat -> cpp-restsdk-petstore.bat

* Change sample folder

* Rename script(windows): tizen-petstore.bat -> cpp-tizen-petstore.bat

* Change sample folder

* Change output folder: tizen -> cpp-tizen

* Rename the scripts under bin/openapi3

cpp-restsdk is not exist under bin/openapi3

* Change sample folder
2018-06-07 16:55:43 +08:00

515 lines
20 KiB
C++

/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
* NOTE: This class is auto generated by OpenAPI-Generator 3.0.0-SNAPSHOT.
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "StoreApi.h"
#include "IHttpBody.h"
#include "JsonBody.h"
#include "MultipartFormData.h"
#include <unordered_set>
#include <boost/algorithm/string/replace.hpp>
namespace org {
namespace openapitools {
namespace client {
namespace api {
using namespace org::openapitools::client::model;
StoreApi::StoreApi( std::shared_ptr<ApiClient> apiClient )
: m_ApiClient(apiClient)
{
}
StoreApi::~StoreApi()
{
}
pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId)
{
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = utility::conversions::to_string_t("/store/order/{orderId}");
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("orderId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(orderId));
std::map<utility::string_t, utility::string_t> queryParams;
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
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("StoreApi->deleteOrder 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("StoreApi->deleteOrder does not consume any supported media type"));
}
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 deleteOrder: ") + 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 deleteOrder: 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::map<utility::string_t, int32_t>> StoreApi::getInventory()
{
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = utility::conversions::to_string_t("/store/inventory");
std::map<utility::string_t, utility::string_t> queryParams;
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
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("StoreApi->getInventory 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("StoreApi->getInventory 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 getInventory: ") + 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 getInventory: unexpected response type: ") + contentType
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
})
.then([=](utility::string_t response)
{
std::map<utility::string_t, int32_t> result;
if(responseHttpContentType == utility::conversions::to_string_t("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 == utility::conversions::to_string_t("multipart/form-data"))
// {
// TODO multipart response parsing
// }
else
{
throw ApiException(500
, utility::conversions::to_string_t("error calling getInventory: unsupported response type"));
}
return result;
});
}
pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId)
{
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = utility::conversions::to_string_t("/store/order/{orderId}");
boost::replace_all(path, utility::conversions::to_string_t("{") + utility::conversions::to_string_t("orderId") + utility::conversions::to_string_t("}"), ApiClient::parameterToString(orderId));
std::map<utility::string_t, utility::string_t> queryParams;
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
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("StoreApi->getOrderById 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("StoreApi->getOrderById does not consume any supported media type"));
}
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 getOrderById: ") + 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 getOrderById: 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<Order> result(new Order());
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 getOrderById: unsupported response type"));
}
return result;
});
}
pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> order)
{
// verify the required parameter 'order' is set
if (order == nullptr)
{
throw ApiException(400, utility::conversions::to_string_t("Missing required parameter 'order' when calling StoreApi->placeOrder"));
}
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = utility::conversions::to_string_t("/store/order");
std::map<utility::string_t, utility::string_t> queryParams;
std::map<utility::string_t, utility::string_t> headerParams( apiConfiguration->getDefaultHeaders() );
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("StoreApi->placeOrder 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");
web::json::value json;
json = ModelBase::toJson(order);
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(order.get())
{
order->toMultipart(multipart, utility::conversions::to_string_t("order"));
}
httpBody = multipart;
requestHttpContentType += utility::conversions::to_string_t("; boundary=") + multipart->getBoundary();
}
else
{
throw ApiException(415, utility::conversions::to_string_t("StoreApi->placeOrder does not consume any supported media type"));
}
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 placeOrder: ") + 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 placeOrder: 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<Order> result(new Order());
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 placeOrder: unsupported response type"));
}
return result;
});
}
}
}
}
}