From 1f733fa11612ab61de05255b53ac60a002a36bc1 Mon Sep 17 00:00:00 2001 From: Gene Chang Date: Thu, 12 Jan 2017 16:58:28 -0500 Subject: [PATCH 1/2] Added support for datetime query parameters in cpprest Signed-off-by: Gene Chang --- .../src/main/resources/cpprest/apiclient-header.mustache | 1 + .../src/main/resources/cpprest/apiclient-source.mustache | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache index 466f914d4a9..91400f163aa 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-header.mustache @@ -38,6 +38,7 @@ public: static utility::string_t parameterToString(utility::string_t value); static utility::string_t parameterToString(int32_t value); static utility::string_t parameterToString(int64_t value); + static utility::string_t parameterToString(const utility::datetime &value); template static utility::string_t parameterToArrayString(std::vector value) diff --git a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache index e9a3810c7bd..4f86ad40540 100644 --- a/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache +++ b/modules/swagger-codegen/src/main/resources/cpprest/apiclient-source.mustache @@ -40,6 +40,11 @@ utility::string_t ApiClient::parameterToString(int32_t 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 ApiClient::callApi( const utility::string_t& path, const utility::string_t& method, From 18faf5493c5ee37cf4b729d0fe67097c92d8f629 Mon Sep 17 00:00:00 2001 From: Gene Chang Date: Fri, 13 Jan 2017 10:46:59 -0500 Subject: [PATCH 2/2] Update petstore sample app for cpprest using bin/cpprest-petstore.sh Signed-off-by: Gene Chang --- samples/client/petstore/cpprest/ApiClient.cpp | 5 +++++ samples/client/petstore/cpprest/ApiClient.h | 1 + samples/client/petstore/cpprest/api/PetApi.cpp | 2 +- samples/client/petstore/cpprest/api/PetApi.h | 4 ++-- samples/client/petstore/cpprest/api/StoreApi.h | 4 ++-- samples/client/petstore/cpprest/model/Category.cpp | 2 +- samples/client/petstore/cpprest/model/Order.cpp | 4 ++-- samples/client/petstore/cpprest/model/Pet.cpp | 2 +- samples/client/petstore/cpprest/model/Pet.h | 4 ++-- samples/client/petstore/cpprest/model/Tag.cpp | 2 +- samples/client/petstore/cpprest/model/User.cpp | 2 +- 11 files changed, 19 insertions(+), 13 deletions(-) diff --git a/samples/client/petstore/cpprest/ApiClient.cpp b/samples/client/petstore/cpprest/ApiClient.cpp index c7687e2851b..00798258261 100644 --- a/samples/client/petstore/cpprest/ApiClient.cpp +++ b/samples/client/petstore/cpprest/ApiClient.cpp @@ -52,6 +52,11 @@ utility::string_t ApiClient::parameterToString(int32_t 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 ApiClient::callApi( const utility::string_t& path, const utility::string_t& method, diff --git a/samples/client/petstore/cpprest/ApiClient.h b/samples/client/petstore/cpprest/ApiClient.h index 81b38cb09c5..1678e9e8c51 100644 --- a/samples/client/petstore/cpprest/ApiClient.h +++ b/samples/client/petstore/cpprest/ApiClient.h @@ -50,6 +50,7 @@ class ApiClient static utility::string_t parameterToString(utility::string_t value); static utility::string_t parameterToString(int32_t value); static utility::string_t parameterToString(int64_t value); + static utility::string_t parameterToString(const utility::datetime &value); template static utility::string_t parameterToArrayString(std::vector value) diff --git a/samples/client/petstore/cpprest/api/PetApi.cpp b/samples/client/petstore/cpprest/api/PetApi.cpp index aa9aab9d89c..c423c43e173 100644 --- a/samples/client/petstore/cpprest/api/PetApi.cpp +++ b/samples/client/petstore/cpprest/api/PetApi.cpp @@ -438,7 +438,7 @@ pplx::task>> PetApi::findPetsByTags(std::vector { - queryParams[U("tags")] = ApiClient::parameterToArrayString(tags); + queryParams[U("tags")] = ApiClient::parameterToArrayString<>(tags); } std::shared_ptr httpBody; diff --git a/samples/client/petstore/cpprest/api/PetApi.h b/samples/client/petstore/cpprest/api/PetApi.h index d60c3c80fca..0a783c66a29 100644 --- a/samples/client/petstore/cpprest/api/PetApi.h +++ b/samples/client/petstore/cpprest/api/PetApi.h @@ -22,10 +22,10 @@ #include "ApiClient.h" -#include "ApiResponse.h" -#include "HttpContent.h" #include "Pet.h" #include +#include "ApiResponse.h" +#include "HttpContent.h" namespace io { namespace swagger { diff --git a/samples/client/petstore/cpprest/api/StoreApi.h b/samples/client/petstore/cpprest/api/StoreApi.h index 60ec088b326..99cbedea460 100644 --- a/samples/client/petstore/cpprest/api/StoreApi.h +++ b/samples/client/petstore/cpprest/api/StoreApi.h @@ -22,9 +22,9 @@ #include "ApiClient.h" -#include "Order.h" -#include #include +#include +#include "Order.h" namespace io { namespace swagger { diff --git a/samples/client/petstore/cpprest/model/Category.cpp b/samples/client/petstore/cpprest/model/Category.cpp index bdb6d8e894a..9c0f21b3b22 100644 --- a/samples/client/petstore/cpprest/model/Category.cpp +++ b/samples/client/petstore/cpprest/model/Category.cpp @@ -21,7 +21,7 @@ namespace model { Category::Category() { - m_Id = 0; + m_Id = 0L; m_IdIsSet = false; m_Name = U(""); m_NameIsSet = false; diff --git a/samples/client/petstore/cpprest/model/Order.cpp b/samples/client/petstore/cpprest/model/Order.cpp index e21d867cd7e..07e815fa90c 100644 --- a/samples/client/petstore/cpprest/model/Order.cpp +++ b/samples/client/petstore/cpprest/model/Order.cpp @@ -21,9 +21,9 @@ namespace model { Order::Order() { - m_Id = 0; + m_Id = 0L; m_IdIsSet = false; - m_PetId = 0; + m_PetId = 0L; m_PetIdIsSet = false; m_Quantity = 0; m_QuantityIsSet = false; diff --git a/samples/client/petstore/cpprest/model/Pet.cpp b/samples/client/petstore/cpprest/model/Pet.cpp index 51dd6d883e9..74b707a4c26 100644 --- a/samples/client/petstore/cpprest/model/Pet.cpp +++ b/samples/client/petstore/cpprest/model/Pet.cpp @@ -21,7 +21,7 @@ namespace model { Pet::Pet() { - m_Id = 0; + m_Id = 0L; m_IdIsSet = false; m_CategoryIsSet = false; m_Name = U(""); diff --git a/samples/client/petstore/cpprest/model/Pet.h b/samples/client/petstore/cpprest/model/Pet.h index 91704dc9ed7..065c46bdb93 100644 --- a/samples/client/petstore/cpprest/model/Pet.h +++ b/samples/client/petstore/cpprest/model/Pet.h @@ -22,10 +22,10 @@ #include "ModelBase.h" -#include "Category.h" +#include "Tag.h" #include +#include "Category.h" #include -#include "Tag.h" namespace io { namespace swagger { diff --git a/samples/client/petstore/cpprest/model/Tag.cpp b/samples/client/petstore/cpprest/model/Tag.cpp index 3cb0798c99e..466ca0d29da 100644 --- a/samples/client/petstore/cpprest/model/Tag.cpp +++ b/samples/client/petstore/cpprest/model/Tag.cpp @@ -21,7 +21,7 @@ namespace model { Tag::Tag() { - m_Id = 0; + m_Id = 0L; m_IdIsSet = false; m_Name = U(""); m_NameIsSet = false; diff --git a/samples/client/petstore/cpprest/model/User.cpp b/samples/client/petstore/cpprest/model/User.cpp index 1ea09f35b50..e9c5e969673 100644 --- a/samples/client/petstore/cpprest/model/User.cpp +++ b/samples/client/petstore/cpprest/model/User.cpp @@ -21,7 +21,7 @@ namespace model { User::User() { - m_Id = 0; + m_Id = 0L; m_IdIsSet = false; m_Username = U(""); m_UsernameIsSet = false;