forked from loafle/openapi-generator-original
When a spec defines a Model at the top level that is a non-aggretate type (such as string, number or boolean), it essentially represents an alias for the simple type. For example, the following spec snippet creates an alias of the boolean type that for all intents and purposes acts just like a regular boolean. definitions: JustABoolean: type: boolean This can be modeled in some languages through built-in mechanisms, such as typedefs in C++. Java, however, just not have a clean way of representing this. This change introduces an internal mechanism for representing aliases. It maintains a map in DefaultCodegen that tracks these types of definitions, and wherever it sees the "JustABoolean" type in the spec, it generates code that uses the built-in "Boolean" instead. This functionality currenlty only applies to Java, but could be extended to other languages later. The change adds a few examples of this to the fake endpoint spec for testing, which means all of the samples change as well.
156 lines
4.6 KiB
C++
156 lines
4.6 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 program.
|
|
* https://github.com/swagger-api/swagger-codegen.git
|
|
* Do not edit the class manually.
|
|
*/
|
|
|
|
#include "ApiClient.h"
|
|
#include "MultipartFormData.h"
|
|
#include "ModelBase.h"
|
|
|
|
namespace io {
|
|
namespace swagger {
|
|
namespace client {
|
|
namespace api {
|
|
|
|
using namespace io::swagger::client::model;
|
|
|
|
ApiClient::ApiClient(std::shared_ptr<ApiConfiguration> configuration )
|
|
: m_Configuration(configuration)
|
|
{
|
|
}
|
|
ApiClient::~ApiClient()
|
|
{
|
|
}
|
|
|
|
std::shared_ptr<ApiConfiguration> ApiClient::getConfiguration() const
|
|
{
|
|
return m_Configuration;
|
|
}
|
|
void ApiClient::setConfiguration(std::shared_ptr<ApiConfiguration> configuration)
|
|
{
|
|
m_Configuration = configuration;
|
|
}
|
|
|
|
|
|
utility::string_t ApiClient::parameterToString(utility::string_t value)
|
|
{
|
|
return value;
|
|
}
|
|
utility::string_t ApiClient::parameterToString(int64_t value)
|
|
{
|
|
return utility::conversions::to_string_t(std::to_string(value));
|
|
}
|
|
utility::string_t ApiClient::parameterToString(int32_t value)
|
|
{
|
|
return utility::conversions::to_string_t(std::to_string(value));
|
|
}
|
|
|
|
utility::string_t ApiClient::parameterToString(float value)
|
|
{
|
|
return utility::conversions::to_string_t(std::to_string(value));
|
|
}
|
|
|
|
utility::string_t ApiClient::parameterToString(const utility::datetime &value)
|
|
{
|
|
return utility::conversions::to_string_t(value.to_string(utility::datetime::ISO_8601));
|
|
}
|
|
|
|
pplx::task<web::http::http_response> ApiClient::callApi(
|
|
const utility::string_t& path,
|
|
const utility::string_t& method,
|
|
const std::map<utility::string_t, utility::string_t>& queryParams,
|
|
const std::shared_ptr<IHttpBody> postBody,
|
|
const std::map<utility::string_t, utility::string_t>& headerParams,
|
|
const std::map<utility::string_t, utility::string_t>& formParams,
|
|
const std::map<utility::string_t, std::shared_ptr<HttpContent>>& fileParams,
|
|
const utility::string_t& contentType
|
|
) const
|
|
{
|
|
if (postBody != nullptr && formParams.size() != 0)
|
|
{
|
|
throw ApiException(400, U("Cannot have body and form params"));
|
|
}
|
|
|
|
if (postBody != nullptr && fileParams.size() != 0)
|
|
{
|
|
throw ApiException(400, U("Cannot have body and file params"));
|
|
}
|
|
|
|
if (fileParams.size() > 0 && contentType != U("multipart/form-data"))
|
|
{
|
|
throw ApiException(400, U("Operations with file parameters must be called with multipart/form-data"));
|
|
}
|
|
|
|
web::http::client::http_client client(m_Configuration->getBaseUrl(), m_Configuration->getHttpConfig());
|
|
|
|
web::http::http_request request;
|
|
for ( auto& kvp : headerParams )
|
|
{
|
|
request.headers().add(kvp.first, kvp.second);
|
|
}
|
|
|
|
if (fileParams.size() > 0)
|
|
{
|
|
MultipartFormData uploadData;
|
|
for (auto& kvp : formParams)
|
|
{
|
|
uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second));
|
|
}
|
|
for (auto& kvp : fileParams)
|
|
{
|
|
uploadData.add(ModelBase::toHttpContent(kvp.first, kvp.second));
|
|
}
|
|
std::stringstream data;
|
|
postBody->writeTo(data);
|
|
auto bodyString = data.str();
|
|
auto length = bodyString.size();
|
|
request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType);
|
|
}
|
|
else
|
|
{
|
|
if (postBody != nullptr)
|
|
{
|
|
std::stringstream data;
|
|
postBody->writeTo(data);
|
|
auto bodyString = data.str();
|
|
auto length = bodyString.size();
|
|
request.set_body(concurrency::streams::bytestream::open_istream(std::move(bodyString)), length, contentType);
|
|
}
|
|
else
|
|
{
|
|
web::http::uri_builder formData;
|
|
for (auto& kvp : formParams)
|
|
{
|
|
formData.append_query(kvp.first, kvp.second);
|
|
}
|
|
request.set_body(formData.query(), U("application/x-www-form-urlencoded"));
|
|
}
|
|
}
|
|
|
|
web::http::uri_builder builder(path);
|
|
for (auto& kvp : queryParams)
|
|
{
|
|
builder.append_query(kvp.first, kvp.second);
|
|
}
|
|
request.set_request_uri(builder.to_uri());
|
|
request.set_method(method);
|
|
if ( !request.headers().has( web::http::header_names::user_agent ) )
|
|
{
|
|
request.headers().add( web::http::header_names::user_agent, m_Configuration->getUserAgent() );
|
|
}
|
|
|
|
return client.request(request);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|