Marc Le Bihan fde8c772fb
[BUG] [C++][Pistache] cpp-pistache-server generating API include unde… (#18553)
* [BUG] [C++][Pistache] cpp-pistache-server generating API include undefined "Object.h" (#2769)

Should handle Object.h, AnyType.h correctly. Set.h also tested.

   - #include Object.h removed and replaced by a typeMapping.put(object, nlohmann::json) like suggested in other issues
   - object had an invalid syntax: ':' instead of '::' in types with namespace
   - extra include of #include nlohmann/json.h removed when there's already #include <nlohmann/json.hpp>
   - nlohmann::json is excluded from model namespace

Tested with custom petstore played, with suggested openapi specs coming from issues #2769, #10266, #14234

   ```bash
   rm -rf samples/server/petstore/cpp-pistache-everything/ && ./bin/generate-samples.sh ./bin/configs/cpp-pistache-server-cpp-pistache-everything.yaml  && cd samples/server/petstore/cpp-pistache-everything/ && mkdir build && cd build && cmake .. && cmake --build . --parallel
   ```

* - Adding to samples/server/petstore cpp-pistache-everything

* - .md and FILES missing
2024-05-04 21:59:49 +08:00

366 lines
8.5 KiB
C++

/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "Pet.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
Pet::Pet()
{
m_Id = 0L;
m_IdIsSet = false;
m_CategoryIsSet = false;
m_Name = "";
m_TagsIsSet = false;
m_Status = "";
m_StatusIsSet = false;
m_VeterinarianVisitIsSet = false;
m_GoodiesIsSet = false;
m_BestFriendsIsSet = false;
}
void Pet::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool Pet::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool Pet::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "Pet" : pathPrefix;
/* PhotoUrls */ {
const std::vector<std::string>& value = m_PhotoUrls;
const std::string currentValuePath = _pathPrefix + ".photoUrls";
{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const std::string& value : value)
{
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
i++;
}
}
}
if (tagsIsSet())
{
const std::vector<org::openapitools::server::model::Tag>& value = m_Tags;
const std::string currentValuePath = _pathPrefix + ".tags";
{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const org::openapitools::server::model::Tag& value : value)
{
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
success = value.validate(msg, currentValuePath + ".tags") && success;
i++;
}
}
}
if (goodiesIsSet())
{
const std::vector<nlohmann::json>& value = m_Goodies;
const std::string currentValuePath = _pathPrefix + ".goodies";
{ // Recursive validation of array elements
const std::string oldValuePath = currentValuePath;
int i = 0;
for (const nlohmann::json& value : value)
{
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
i++;
}
}
}
return success;
}
bool Pet::operator==(const Pet& rhs) const
{
return
((!idIsSet() && !rhs.idIsSet()) || (idIsSet() && rhs.idIsSet() && getId() == rhs.getId())) &&
((!categoryIsSet() && !rhs.categoryIsSet()) || (categoryIsSet() && rhs.categoryIsSet() && getCategory() == rhs.getCategory())) &&
(getName() == rhs.getName())
&&
(getPhotoUrls() == rhs.getPhotoUrls())
&&
((!tagsIsSet() && !rhs.tagsIsSet()) || (tagsIsSet() && rhs.tagsIsSet() && getTags() == rhs.getTags())) &&
((!statusIsSet() && !rhs.statusIsSet()) || (statusIsSet() && rhs.statusIsSet() && getStatus() == rhs.getStatus())) &&
((!veterinarianVisitIsSet() && !rhs.veterinarianVisitIsSet()) || (veterinarianVisitIsSet() && rhs.veterinarianVisitIsSet() && getVeterinarianVisit() == rhs.getVeterinarianVisit())) &&
((!goodiesIsSet() && !rhs.goodiesIsSet()) || (goodiesIsSet() && rhs.goodiesIsSet() && getGoodies() == rhs.getGoodies())) &&
((!bestFriendsIsSet() && !rhs.bestFriendsIsSet()) || (bestFriendsIsSet() && rhs.bestFriendsIsSet() && getBestFriends() == rhs.getBestFriends()))
;
}
bool Pet::operator!=(const Pet& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const Pet& o)
{
j = nlohmann::json::object();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.categoryIsSet())
j["category"] = o.m_Category;
j["name"] = o.m_Name;
j["photoUrls"] = o.m_PhotoUrls;
if(o.tagsIsSet() || !o.m_Tags.empty())
j["tags"] = o.m_Tags;
if(o.statusIsSet())
j["status"] = o.m_Status;
if(o.veterinarianVisitIsSet())
j["veterinarianVisit"] = o.m_VeterinarianVisit;
if(o.goodiesIsSet() || !o.m_Goodies.empty())
j["goodies"] = o.m_Goodies;
if(o.bestFriendsIsSet())
j["bestFriends"] = o.m_BestFriends;
}
void from_json(const nlohmann::json& j, Pet& o)
{
if(j.find("id") != j.end())
{
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
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.find("tags") != j.end())
{
j.at("tags").get_to(o.m_Tags);
o.m_TagsIsSet = true;
}
if(j.find("status") != j.end())
{
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
}
if(j.find("veterinarianVisit") != j.end())
{
j.at("veterinarianVisit").get_to(o.m_VeterinarianVisit);
o.m_VeterinarianVisitIsSet = true;
}
if(j.find("goodies") != j.end())
{
j.at("goodies").get_to(o.m_Goodies);
o.m_GoodiesIsSet = true;
}
if(j.find("bestFriends") != j.end())
{
j.at("bestFriends").get_to(o.m_BestFriends);
o.m_BestFriendsIsSet = true;
}
}
int64_t Pet::getId() const
{
return m_Id;
}
void Pet::setId(int64_t const value)
{
m_Id = value;
m_IdIsSet = true;
}
bool Pet::idIsSet() const
{
return m_IdIsSet;
}
void Pet::unsetId()
{
m_IdIsSet = false;
}
org::openapitools::server::model::Category Pet::getCategory() const
{
return m_Category;
}
void Pet::setCategory(org::openapitools::server::model::Category const& value)
{
m_Category = value;
m_CategoryIsSet = true;
}
bool Pet::categoryIsSet() const
{
return m_CategoryIsSet;
}
void Pet::unsetCategory()
{
m_CategoryIsSet = false;
}
std::string Pet::getName() const
{
return m_Name;
}
void Pet::setName(std::string const& value)
{
m_Name = value;
}
std::vector<std::string> Pet::getPhotoUrls() const
{
return m_PhotoUrls;
}
void Pet::setPhotoUrls(std::vector<std::string> const& value)
{
m_PhotoUrls = value;
}
std::vector<org::openapitools::server::model::Tag> Pet::getTags() const
{
return m_Tags;
}
void Pet::setTags(std::vector<org::openapitools::server::model::Tag> const& value)
{
m_Tags = value;
m_TagsIsSet = true;
}
bool Pet::tagsIsSet() const
{
return m_TagsIsSet;
}
void Pet::unsetTags()
{
m_TagsIsSet = false;
}
std::string Pet::getStatus() const
{
return m_Status;
}
void Pet::setStatus(std::string const& value)
{
m_Status = value;
m_StatusIsSet = true;
}
bool Pet::statusIsSet() const
{
return m_StatusIsSet;
}
void Pet::unsetStatus()
{
m_StatusIsSet = false;
}
nlohmann::json Pet::getVeterinarianVisit() const
{
return m_VeterinarianVisit;
}
void Pet::setVeterinarianVisit(nlohmann::json const& value)
{
m_VeterinarianVisit = value;
m_VeterinarianVisitIsSet = true;
}
bool Pet::veterinarianVisitIsSet() const
{
return m_VeterinarianVisitIsSet;
}
void Pet::unsetVeterinarianVisit()
{
m_VeterinarianVisitIsSet = false;
}
std::vector<nlohmann::json> Pet::getGoodies() const
{
return m_Goodies;
}
void Pet::setGoodies(std::vector<nlohmann::json> const& value)
{
m_Goodies = value;
m_GoodiesIsSet = true;
}
bool Pet::goodiesIsSet() const
{
return m_GoodiesIsSet;
}
void Pet::unsetGoodies()
{
m_GoodiesIsSet = false;
}
org::openapitools::server::model::Pet_bestFriends Pet::getBestFriends() const
{
return m_BestFriends;
}
void Pet::setBestFriends(org::openapitools::server::model::Pet_bestFriends const& value)
{
m_BestFriends = value;
m_BestFriendsIsSet = true;
}
bool Pet::bestFriendsIsSet() const
{
return m_BestFriendsIsSet;
}
void Pet::unsetBestFriends()
{
m_BestFriendsIsSet = false;
}
} // namespace org::openapitools::server::model