From 218a338d44e43cd2a38aa4c20f59f2b7525c0923 Mon Sep 17 00:00:00 2001 From: muttley Date: Mon, 8 Jul 2019 14:20:47 +0200 Subject: [PATCH 1/2] [C++][Pistache] Replace contains with find on json object This makes generator compatible with nlohmann-json 3.5.0 --- .../main/resources/cpp-pistache-server/model-source.mustache | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache index c58a2fc79a0c..e69d65cafc68 100644 --- a/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache +++ b/modules/openapi-generator/src/main/resources/cpp-pistache-server/model-source.mustache @@ -37,7 +37,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o) void from_json(const nlohmann::json& j, {{classname}}& o) { {{#vars}} - {{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.contains("{{baseName}}")) + {{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(j.find("{{baseName}}") != j.end()) { j.at("{{baseName}}").get_to(o.m_{{name}}); o.m_{{name}}IsSet = true; From 184b7cac4a290e59ae241d07cd9154561b0dc5fc Mon Sep 17 00:00:00 2001 From: muttley Date: Mon, 8 Jul 2019 14:21:02 +0200 Subject: [PATCH 2/2] [C++][Pistache] Update Petstore sample --- .../petstore/cpp-pistache/model/ApiResponse.cpp | 6 +++--- .../petstore/cpp-pistache/model/Category.cpp | 4 ++-- .../cpp-pistache/model/Inline_object.cpp | 4 ++-- .../cpp-pistache/model/Inline_object_1.cpp | 4 ++-- .../server/petstore/cpp-pistache/model/Order.cpp | 12 ++++++------ .../server/petstore/cpp-pistache/model/Pet.cpp | 8 ++++---- .../server/petstore/cpp-pistache/model/Tag.cpp | 4 ++-- .../server/petstore/cpp-pistache/model/User.cpp | 16 ++++++++-------- 8 files changed, 29 insertions(+), 29 deletions(-) diff --git a/samples/server/petstore/cpp-pistache/model/ApiResponse.cpp b/samples/server/petstore/cpp-pistache/model/ApiResponse.cpp index a78fb1cc7f97..77cd466e145f 100644 --- a/samples/server/petstore/cpp-pistache/model/ApiResponse.cpp +++ b/samples/server/petstore/cpp-pistache/model/ApiResponse.cpp @@ -51,17 +51,17 @@ void to_json(nlohmann::json& j, const ApiResponse& o) void from_json(const nlohmann::json& j, ApiResponse& o) { - if(j.contains("code")) + if(j.find("code") != j.end()) { j.at("code").get_to(o.m_Code); o.m_CodeIsSet = true; } - if(j.contains("type")) + if(j.find("type") != j.end()) { j.at("type").get_to(o.m_Type); o.m_TypeIsSet = true; } - if(j.contains("message")) + if(j.find("message") != j.end()) { j.at("message").get_to(o.m_Message); o.m_MessageIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Category.cpp b/samples/server/petstore/cpp-pistache/model/Category.cpp index 2abb0c3c5e2a..43ff1d490004 100644 --- a/samples/server/petstore/cpp-pistache/model/Category.cpp +++ b/samples/server/petstore/cpp-pistache/model/Category.cpp @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Category& o) void from_json(const nlohmann::json& j, Category& o) { - if(j.contains("id")) + if(j.find("id") != j.end()) { j.at("id").get_to(o.m_Id); o.m_IdIsSet = true; } - if(j.contains("name")) + if(j.find("name") != j.end()) { j.at("name").get_to(o.m_Name); o.m_NameIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Inline_object.cpp b/samples/server/petstore/cpp-pistache/model/Inline_object.cpp index ebb313039081..89638a845668 100644 --- a/samples/server/petstore/cpp-pistache/model/Inline_object.cpp +++ b/samples/server/petstore/cpp-pistache/model/Inline_object.cpp @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Inline_object& o) void from_json(const nlohmann::json& j, Inline_object& o) { - if(j.contains("name")) + if(j.find("name") != j.end()) { j.at("name").get_to(o.m_Name); o.m_NameIsSet = true; } - if(j.contains("status")) + if(j.find("status") != j.end()) { j.at("status").get_to(o.m_Status); o.m_StatusIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Inline_object_1.cpp b/samples/server/petstore/cpp-pistache/model/Inline_object_1.cpp index d5ffe1fef884..0da3bdba2b8a 100644 --- a/samples/server/petstore/cpp-pistache/model/Inline_object_1.cpp +++ b/samples/server/petstore/cpp-pistache/model/Inline_object_1.cpp @@ -46,12 +46,12 @@ void to_json(nlohmann::json& j, const Inline_object_1& o) void from_json(const nlohmann::json& j, Inline_object_1& o) { - if(j.contains("additionalMetadata")) + if(j.find("additionalMetadata") != j.end()) { j.at("additionalMetadata").get_to(o.m_AdditionalMetadata); o.m_AdditionalMetadataIsSet = true; } - if(j.contains("file")) + if(j.find("file") != j.end()) { j.at("file").get_to(o.m_file); o.m_fileIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Order.cpp b/samples/server/petstore/cpp-pistache/model/Order.cpp index b24cc0fce92e..82efbce6cb22 100644 --- a/samples/server/petstore/cpp-pistache/model/Order.cpp +++ b/samples/server/petstore/cpp-pistache/model/Order.cpp @@ -63,32 +63,32 @@ void to_json(nlohmann::json& j, const Order& o) void from_json(const nlohmann::json& j, Order& o) { - if(j.contains("id")) + if(j.find("id") != j.end()) { j.at("id").get_to(o.m_Id); o.m_IdIsSet = true; } - if(j.contains("petId")) + if(j.find("petId") != j.end()) { j.at("petId").get_to(o.m_PetId); o.m_PetIdIsSet = true; } - if(j.contains("quantity")) + if(j.find("quantity") != j.end()) { j.at("quantity").get_to(o.m_Quantity); o.m_QuantityIsSet = true; } - if(j.contains("shipDate")) + if(j.find("shipDate") != j.end()) { j.at("shipDate").get_to(o.m_ShipDate); o.m_ShipDateIsSet = true; } - if(j.contains("status")) + if(j.find("status") != j.end()) { j.at("status").get_to(o.m_Status); o.m_StatusIsSet = true; } - if(j.contains("complete")) + if(j.find("complete") != j.end()) { j.at("complete").get_to(o.m_Complete); o.m_CompleteIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Pet.cpp b/samples/server/petstore/cpp-pistache/model/Pet.cpp index 7781e283cebc..1bceb861ad48 100644 --- a/samples/server/petstore/cpp-pistache/model/Pet.cpp +++ b/samples/server/petstore/cpp-pistache/model/Pet.cpp @@ -56,24 +56,24 @@ void to_json(nlohmann::json& j, const Pet& o) void from_json(const nlohmann::json& j, Pet& o) { - if(j.contains("id")) + if(j.find("id") != j.end()) { j.at("id").get_to(o.m_Id); o.m_IdIsSet = true; } - if(j.contains("category")) + if(j.find("category") != j.end()) { j.at("category").get_to(o.m_Category); o.m_CategoryIsSet = true; } j.at("name").get_to(o.m_Name); j.at("photoUrls").get_to(o.m_PhotoUrls); - if(j.contains("tags")) + if(j.find("tags") != j.end()) { j.at("tags").get_to(o.m_Tags); o.m_TagsIsSet = true; } - if(j.contains("status")) + if(j.find("status") != j.end()) { j.at("status").get_to(o.m_Status); o.m_StatusIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/Tag.cpp b/samples/server/petstore/cpp-pistache/model/Tag.cpp index b81cb825724b..7f56fb2bcca9 100644 --- a/samples/server/petstore/cpp-pistache/model/Tag.cpp +++ b/samples/server/petstore/cpp-pistache/model/Tag.cpp @@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Tag& o) void from_json(const nlohmann::json& j, Tag& o) { - if(j.contains("id")) + if(j.find("id") != j.end()) { j.at("id").get_to(o.m_Id); o.m_IdIsSet = true; } - if(j.contains("name")) + if(j.find("name") != j.end()) { j.at("name").get_to(o.m_Name); o.m_NameIsSet = true; diff --git a/samples/server/petstore/cpp-pistache/model/User.cpp b/samples/server/petstore/cpp-pistache/model/User.cpp index 66a026e9c78f..20ae06352f25 100644 --- a/samples/server/petstore/cpp-pistache/model/User.cpp +++ b/samples/server/petstore/cpp-pistache/model/User.cpp @@ -71,42 +71,42 @@ void to_json(nlohmann::json& j, const User& o) void from_json(const nlohmann::json& j, User& o) { - if(j.contains("id")) + if(j.find("id") != j.end()) { j.at("id").get_to(o.m_Id); o.m_IdIsSet = true; } - if(j.contains("username")) + if(j.find("username") != j.end()) { j.at("username").get_to(o.m_Username); o.m_UsernameIsSet = true; } - if(j.contains("firstName")) + if(j.find("firstName") != j.end()) { j.at("firstName").get_to(o.m_FirstName); o.m_FirstNameIsSet = true; } - if(j.contains("lastName")) + if(j.find("lastName") != j.end()) { j.at("lastName").get_to(o.m_LastName); o.m_LastNameIsSet = true; } - if(j.contains("email")) + if(j.find("email") != j.end()) { j.at("email").get_to(o.m_Email); o.m_EmailIsSet = true; } - if(j.contains("password")) + if(j.find("password") != j.end()) { j.at("password").get_to(o.m_Password); o.m_PasswordIsSet = true; } - if(j.contains("phone")) + if(j.find("phone") != j.end()) { j.at("phone").get_to(o.m_Phone); o.m_PhoneIsSet = true; } - if(j.contains("userStatus")) + if(j.find("userStatus") != j.end()) { j.at("userStatus").get_to(o.m_UserStatus); o.m_UserStatusIsSet = true;