[Cpprest] Fixing issue #3773 (#3876)

* Fixed errors with cpprest client generation when generating a client that uses arrays of primitive types (vector) and file responses (HttpContent).

* Updated the petstore sample using script.

* Removed debug code.

* Removed extra newline to match master.

* Fixed binary file handling in cpprest. Updated petstore samples.

* Update readme to add Cummins to list

* Cleaning up for pull. Removing unnecessary changes.

* Fixing petstore

* Fixing error in build.

* Fixed error in stream copy for binary data

* Replaced tab with 4 spaces in all modified files.

Replaced tab with 4 spaces in all modified files.
This commit is contained in:
Scott Richter
2016-09-29 22:31:24 -04:00
committed by wing328
parent 3d231e4e4b
commit b2e2643fd2
36 changed files with 290 additions and 308 deletions

View File

@@ -1,9 +1,9 @@
/**
* 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.
* This is a sample server Petstore server. You can find out more about Swagger at <a href=\"http://swagger.io\">http://swagger.io</a> or on irc.freenode.net, #swagger. 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
* Contact: apiteam@wordnik.com
*
* NOTE: This class is auto generated by the swagger code generator program.
* https://github.com/swagger-api/swagger-codegen.git
@@ -51,12 +51,6 @@ PetApi::~PetApi()
pplx::task<void> PetApi::addPet(std::shared_ptr<Pet> body)
{
// verify the required parameter 'body' is set
if (body == nullptr)
{
throw ApiException(400, U("Missing required parameter 'body' when calling PetApi->addPet"));
}
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = U("/pet");
@@ -67,8 +61,8 @@ pplx::task<void> PetApi::addPet(std::shared_ptr<Pet> body)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -82,7 +76,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->addPet does not produce any supported media type"));
}
@@ -150,7 +144,7 @@ consumeHttpContentTypes.insert( U("application/xml") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -161,8 +155,8 @@ consumeHttpContentTypes.insert( U("application/xml") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
@@ -183,8 +177,8 @@ pplx::task<void> PetApi::deletePet(int64_t petId, utility::string_t apiKey)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -198,7 +192,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->deletePet does not produce any supported media type"));
}
@@ -256,7 +250,7 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -267,8 +261,8 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
@@ -288,8 +282,8 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByStatus(std::vect
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -303,7 +297,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->findPetsByStatus does not produce any supported media type"));
}
@@ -357,7 +351,7 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -368,8 +362,8 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
@@ -415,8 +409,8 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByTags(std::vector
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -430,7 +424,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->findPetsByTags does not produce any supported media type"));
}
@@ -484,7 +478,7 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -495,8 +489,8 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
@@ -543,8 +537,8 @@ pplx::task<std::shared_ptr<Pet>> PetApi::getPetById(int64_t petId)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -558,7 +552,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->getPetById does not produce any supported media type"));
}
@@ -593,6 +587,8 @@ responseHttpContentTypes.insert( U("application/json") );
throw ApiException(415, U("PetApi->getPetById does not consume any supported media type"));
}
// authentication (petstore_auth) required
// oauth2 authentication is added automatically as part of the http_client_config
// authentication (api_key) required
{
utility::string_t apiKey = apiConfiguration->getApiKey(U("api_key"));
@@ -617,7 +613,7 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -628,8 +624,8 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
@@ -657,12 +653,6 @@ responseHttpContentTypes.insert( U("application/json") );
pplx::task<void> PetApi::updatePet(std::shared_ptr<Pet> body)
{
// verify the required parameter 'body' is set
if (body == nullptr)
{
throw ApiException(400, U("Missing required parameter 'body' when calling PetApi->updatePet"));
}
std::shared_ptr<ApiConfiguration> apiConfiguration( m_ApiClient->getConfiguration() );
utility::string_t path = U("/pet");
@@ -673,8 +663,8 @@ pplx::task<void> PetApi::updatePet(std::shared_ptr<Pet> body)
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -688,7 +678,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->updatePet does not produce any supported media type"));
}
@@ -756,7 +746,7 @@ consumeHttpContentTypes.insert( U("application/xml") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -767,15 +757,15 @@ consumeHttpContentTypes.insert( U("application/xml") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
return void();
});
}
pplx::task<void> PetApi::updatePetWithForm(int64_t petId, utility::string_t name, utility::string_t status)
pplx::task<void> PetApi::updatePetWithForm(utility::string_t petId, utility::string_t name, utility::string_t status)
{
@@ -789,8 +779,8 @@ pplx::task<void> PetApi::updatePetWithForm(int64_t petId, utility::string_t name
std::map<utility::string_t, std::shared_ptr<HttpContent>> fileParams;
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/xml") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -804,7 +794,7 @@ responseHttpContentTypes.insert( U("application/json") );
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->updatePetWithForm does not produce any supported media type"));
}
@@ -868,7 +858,7 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -879,15 +869,15 @@ responseHttpContentTypes.insert( U("application/json") );
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
return void();
});
}
pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, utility::string_t additionalMetadata, std::shared_ptr<HttpContent> file)
pplx::task<void> PetApi::uploadFile(int64_t petId, utility::string_t additionalMetadata, std::shared_ptr<HttpContent> file)
{
@@ -902,6 +892,7 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, utili
std::unordered_set<utility::string_t> responseHttpContentTypes;
responseHttpContentTypes.insert( U("application/json") );
responseHttpContentTypes.insert( U("application/xml") );
utility::string_t responseHttpContentType;
@@ -915,7 +906,7 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, utili
{
responseHttpContentType = U("multipart/form-data");
}
else
else
{
throw ApiException(400, U("PetApi->uploadFile does not produce any supported media type"));
}
@@ -979,7 +970,7 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, utili
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
// check response content type
// check response content type
if(response.headers().has(U("Content-Type")))
{
utility::string_t contentType = response.headers()[U("Content-Type")];
@@ -990,31 +981,13 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, utili
, std::make_shared<std::stringstream>(response.extract_utf8string(true).get()));
}
}
return response.extract_string();
return response.extract_string();
})
.then([=](utility::string_t response)
{
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;
});
return void();
});
}
}