[C++][Pistache] Add compatibility for nlohmann-json 3.5.0 (#3306)

* [C++][Pistache] Replace contains with find on json object

This makes generator compatible with nlohmann-json 3.5.0

* [C++][Pistache] Update Petstore sample
This commit is contained in:
Mateusz Szychowski (Muttley) 2019-07-13 13:31:14 +02:00 committed by Stefan Krismann
parent 4843dfc244
commit c1df082d65
9 changed files with 30 additions and 30 deletions

View File

@ -37,7 +37,7 @@ void to_json(nlohmann::json& j, const {{classname}}& o)
void from_json(const nlohmann::json& j, {{classname}}& o) void from_json(const nlohmann::json& j, {{classname}}& o)
{ {
{{#vars}} {{#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}}); j.at("{{baseName}}").get_to(o.m_{{name}});
o.m_{{name}}IsSet = true; o.m_{{name}}IsSet = true;

View File

@ -51,17 +51,17 @@ void to_json(nlohmann::json& j, const ApiResponse& o)
void from_json(const nlohmann::json& j, 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); j.at("code").get_to(o.m_Code);
o.m_CodeIsSet = true; o.m_CodeIsSet = true;
} }
if(j.contains("type")) if(j.find("type") != j.end())
{ {
j.at("type").get_to(o.m_Type); j.at("type").get_to(o.m_Type);
o.m_TypeIsSet = true; o.m_TypeIsSet = true;
} }
if(j.contains("message")) if(j.find("message") != j.end())
{ {
j.at("message").get_to(o.m_Message); j.at("message").get_to(o.m_Message);
o.m_MessageIsSet = true; o.m_MessageIsSet = true;

View File

@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Category& o)
void from_json(const nlohmann::json& j, 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); j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true; o.m_IdIsSet = true;
} }
if(j.contains("name")) if(j.find("name") != j.end())
{ {
j.at("name").get_to(o.m_Name); j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true; o.m_NameIsSet = true;

View File

@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Inline_object& o)
void from_json(const nlohmann::json& j, 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); j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true; o.m_NameIsSet = true;
} }
if(j.contains("status")) if(j.find("status") != j.end())
{ {
j.at("status").get_to(o.m_Status); j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true; o.m_StatusIsSet = true;

View File

@ -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) 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); j.at("additionalMetadata").get_to(o.m_AdditionalMetadata);
o.m_AdditionalMetadataIsSet = true; o.m_AdditionalMetadataIsSet = true;
} }
if(j.contains("file")) if(j.find("file") != j.end())
{ {
j.at("file").get_to(o.m_file); j.at("file").get_to(o.m_file);
o.m_fileIsSet = true; o.m_fileIsSet = true;

View File

@ -63,32 +63,32 @@ void to_json(nlohmann::json& j, const Order& o)
void from_json(const nlohmann::json& j, 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); j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true; o.m_IdIsSet = true;
} }
if(j.contains("petId")) if(j.find("petId") != j.end())
{ {
j.at("petId").get_to(o.m_PetId); j.at("petId").get_to(o.m_PetId);
o.m_PetIdIsSet = true; o.m_PetIdIsSet = true;
} }
if(j.contains("quantity")) if(j.find("quantity") != j.end())
{ {
j.at("quantity").get_to(o.m_Quantity); j.at("quantity").get_to(o.m_Quantity);
o.m_QuantityIsSet = true; o.m_QuantityIsSet = true;
} }
if(j.contains("shipDate")) if(j.find("shipDate") != j.end())
{ {
j.at("shipDate").get_to(o.m_ShipDate); j.at("shipDate").get_to(o.m_ShipDate);
o.m_ShipDateIsSet = true; o.m_ShipDateIsSet = true;
} }
if(j.contains("status")) if(j.find("status") != j.end())
{ {
j.at("status").get_to(o.m_Status); j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true; o.m_StatusIsSet = true;
} }
if(j.contains("complete")) if(j.find("complete") != j.end())
{ {
j.at("complete").get_to(o.m_Complete); j.at("complete").get_to(o.m_Complete);
o.m_CompleteIsSet = true; o.m_CompleteIsSet = true;

View File

@ -56,24 +56,24 @@ void to_json(nlohmann::json& j, const Pet& o)
void from_json(const nlohmann::json& j, 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); j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true; o.m_IdIsSet = true;
} }
if(j.contains("category")) if(j.find("category") != j.end())
{ {
j.at("category").get_to(o.m_Category); j.at("category").get_to(o.m_Category);
o.m_CategoryIsSet = true; o.m_CategoryIsSet = true;
} }
j.at("name").get_to(o.m_Name); j.at("name").get_to(o.m_Name);
j.at("photoUrls").get_to(o.m_PhotoUrls); 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); j.at("tags").get_to(o.m_Tags);
o.m_TagsIsSet = true; o.m_TagsIsSet = true;
} }
if(j.contains("status")) if(j.find("status") != j.end())
{ {
j.at("status").get_to(o.m_Status); j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true; o.m_StatusIsSet = true;

View File

@ -47,12 +47,12 @@ void to_json(nlohmann::json& j, const Tag& o)
void from_json(const nlohmann::json& j, 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); j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true; o.m_IdIsSet = true;
} }
if(j.contains("name")) if(j.find("name") != j.end())
{ {
j.at("name").get_to(o.m_Name); j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true; o.m_NameIsSet = true;

View File

@ -71,42 +71,42 @@ void to_json(nlohmann::json& j, const User& o)
void from_json(const nlohmann::json& j, 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); j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true; o.m_IdIsSet = true;
} }
if(j.contains("username")) if(j.find("username") != j.end())
{ {
j.at("username").get_to(o.m_Username); j.at("username").get_to(o.m_Username);
o.m_UsernameIsSet = true; o.m_UsernameIsSet = true;
} }
if(j.contains("firstName")) if(j.find("firstName") != j.end())
{ {
j.at("firstName").get_to(o.m_FirstName); j.at("firstName").get_to(o.m_FirstName);
o.m_FirstNameIsSet = true; o.m_FirstNameIsSet = true;
} }
if(j.contains("lastName")) if(j.find("lastName") != j.end())
{ {
j.at("lastName").get_to(o.m_LastName); j.at("lastName").get_to(o.m_LastName);
o.m_LastNameIsSet = true; o.m_LastNameIsSet = true;
} }
if(j.contains("email")) if(j.find("email") != j.end())
{ {
j.at("email").get_to(o.m_Email); j.at("email").get_to(o.m_Email);
o.m_EmailIsSet = true; o.m_EmailIsSet = true;
} }
if(j.contains("password")) if(j.find("password") != j.end())
{ {
j.at("password").get_to(o.m_Password); j.at("password").get_to(o.m_Password);
o.m_PasswordIsSet = true; o.m_PasswordIsSet = true;
} }
if(j.contains("phone")) if(j.find("phone") != j.end())
{ {
j.at("phone").get_to(o.m_Phone); j.at("phone").get_to(o.m_Phone);
o.m_PhoneIsSet = true; o.m_PhoneIsSet = true;
} }
if(j.contains("userStatus")) if(j.find("userStatus") != j.end())
{ {
j.at("userStatus").get_to(o.m_UserStatus); j.at("userStatus").get_to(o.m_UserStatus);
o.m_UserStatusIsSet = true; o.m_UserStatusIsSet = true;