Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpprest] Deserialize Float without decimal point #8043

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,10 @@ pplx::task<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/r
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
{{/bodyParam}}
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("{{classname}}->{{operationId}} does not consume any supported media type"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public:
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::datetime & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, web::json::value & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& );
template <typename T>
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ bool ModelBase::fromString( const utility::string_t& val, float &outVal )
}
catch (...)
{
success = false;
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<float>(intVal);
}
}
return success;
}
Expand All @@ -150,7 +155,12 @@ bool ModelBase::fromString( const utility::string_t& val, double &outVal )
}
catch (...)
{
success = false;
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<double>(intVal);
}
}
return success;
}
Expand Down Expand Up @@ -281,7 +291,7 @@ bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpConte
if(content == nullptr)
{
content = std::shared_ptr<HttpContent>(new HttpContent());
}
}
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
{
utility::string_t value;
Expand Down
16 changes: 13 additions & 3 deletions samples/client/petstore/cpp-restsdk/client/ModelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ bool ModelBase::fromString( const utility::string_t& val, float &outVal )
}
catch (...)
{
success = false;
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<float>(intVal);
}
}
return success;
}
Expand All @@ -161,7 +166,12 @@ bool ModelBase::fromString( const utility::string_t& val, double &outVal )
}
catch (...)
{
success = false;
int64_t intVal = 0;
success = ModelBase::fromString(val, intVal);
if(success)
{
outVal = static_cast<double>(intVal);
}
}
return success;
}
Expand Down Expand Up @@ -292,7 +302,7 @@ bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<HttpConte
if(content == nullptr)
{
content = std::shared_ptr<HttpContent>(new HttpContent());
}
}
if(val.has_field(utility::conversions::to_string_t("ContentDisposition")))
{
utility::string_t value;
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/cpp-restsdk/client/ModelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class ModelBase
static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::datetime & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, web::json::value & );
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& );
template <typename T>
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& );
template <typename T>
static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
Expand Down
32 changes: 32 additions & 0 deletions samples/client/petstore/cpp-restsdk/client/api/PetApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ pplx::task<void> PetApi::addPet(std::shared_ptr<Pet> body) const
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->addPet does not consume any supported media type"));
Expand Down Expand Up @@ -219,6 +223,10 @@ pplx::task<void> PetApi::deletePet(int64_t petId, boost::optional<utility::strin
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->deletePet does not consume any supported media type"));
Expand Down Expand Up @@ -325,6 +333,10 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByStatus(std::vect
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->findPetsByStatus does not consume any supported media type"));
Expand Down Expand Up @@ -453,6 +465,10 @@ pplx::task<std::vector<std::shared_ptr<Pet>>> PetApi::findPetsByTags(std::vector
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->findPetsByTags does not consume any supported media type"));
Expand Down Expand Up @@ -579,6 +595,10 @@ pplx::task<std::shared_ptr<Pet>> PetApi::getPetById(int64_t petId) const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->getPetById does not consume any supported media type"));
Expand Down Expand Up @@ -728,6 +748,10 @@ pplx::task<void> PetApi::updatePet(std::shared_ptr<Pet> body) const
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->updatePet does not consume any supported media type"));
Expand Down Expand Up @@ -839,6 +863,10 @@ pplx::task<void> PetApi::updatePetWithForm(int64_t petId, boost::optional<utilit
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->updatePetWithForm does not consume any supported media type"));
Expand Down Expand Up @@ -951,6 +979,10 @@ pplx::task<std::shared_ptr<ApiResponse>> PetApi::uploadFile(int64_t petId, boost
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("PetApi->uploadFile does not consume any supported media type"));
Expand Down
16 changes: 16 additions & 0 deletions samples/client/petstore/cpp-restsdk/client/api/StoreApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ pplx::task<void> StoreApi::deleteOrder(utility::string_t orderId) const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("StoreApi->deleteOrder does not consume any supported media type"));
Expand Down Expand Up @@ -190,6 +194,10 @@ pplx::task<std::map<utility::string_t, int32_t>> StoreApi::getInventory() const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("StoreApi->getInventory does not consume any supported media type"));
Expand Down Expand Up @@ -323,6 +331,10 @@ pplx::task<std::shared_ptr<Order>> StoreApi::getOrderById(int64_t orderId) const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("StoreApi->getOrderById does not consume any supported media type"));
Expand Down Expand Up @@ -464,6 +476,10 @@ pplx::task<std::shared_ptr<Order>> StoreApi::placeOrder(std::shared_ptr<Order> b
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("StoreApi->placeOrder does not consume any supported media type"));
Expand Down
32 changes: 32 additions & 0 deletions samples/client/petstore/cpp-restsdk/client/api/UserApi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ pplx::task<void> UserApi::createUser(std::shared_ptr<User> body) const
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->createUser does not consume any supported media type"));
Expand Down Expand Up @@ -237,6 +241,10 @@ pplx::task<void> UserApi::createUsersWithArrayInput(std::vector<std::shared_ptr<
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->createUsersWithArrayInput does not consume any supported media type"));
Expand Down Expand Up @@ -363,6 +371,10 @@ pplx::task<void> UserApi::createUsersWithListInput(std::vector<std::shared_ptr<U
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->createUsersWithListInput does not consume any supported media type"));
Expand Down Expand Up @@ -463,6 +475,10 @@ pplx::task<void> UserApi::deleteUser(utility::string_t username) const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->deleteUser does not consume any supported media type"));
Expand Down Expand Up @@ -565,6 +581,10 @@ pplx::task<std::shared_ptr<User>> UserApi::getUserByName(utility::string_t usern
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->getUserByName does not consume any supported media type"));
Expand Down Expand Up @@ -695,6 +715,10 @@ pplx::task<utility::string_t> UserApi::loginUser(utility::string_t username, uti
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->loginUser does not consume any supported media type"));
Expand Down Expand Up @@ -816,6 +840,10 @@ pplx::task<void> UserApi::logoutUser() const
{
localVarRequestHttpContentType = utility::conversions::to_string_t("multipart/form-data");
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->logoutUser does not consume any supported media type"));
Expand Down Expand Up @@ -938,6 +966,10 @@ pplx::task<void> UserApi::updateUser(utility::string_t username, std::shared_ptr
localVarHttpBody = localVarMultipart;
localVarRequestHttpContentType += utility::conversions::to_string_t("; boundary=") + localVarMultipart->getBoundary();
}
else if (localVarConsumeHttpContentTypes.find(utility::conversions::to_string_t("application/x-www-form-urlencoded")) != localVarConsumeHttpContentTypes.end())
{
localVarRequestHttpContentType = utility::conversions::to_string_t("application/x-www-form-urlencoded");
}
else
{
throw ApiException(415, utility::conversions::to_string_t("UserApi->updateUser does not consume any supported media type"));
Expand Down