Marc Le Bihan 1fa2d474b4
[[BUG][C][cpp-restsdk] Missing Set.h when trying to generate from Twitter OpenAPI JSON #9969](https://github.com/OpenAPITools/openapi-generator/issues/9969) (#18631)
- Handling `std::set` in cpp-restdsk
    - Member variables using `std:set` added to `Pet` in cpp-restsdk 3.0 Petstore sample

[cpp-pistache-server] taking into account a remark on this issue about cpp-pistache-server and its set management

    - Switching `std::vector` to `std::set` for openapi set type in cpp-pistache-server
2024-05-15 14:51:59 +08:00

420 lines
10 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_CertificatesIsSet = false;
m_VaccinationBookIsSet = 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++;
}
}
}
if (certificatesIsSet())
{
const std::set<std::string>& value = m_Certificates;
const std::string currentValuePath = _pathPrefix + ".certificates";
if (!org::openapitools::server::helpers::hasOnlyUniqueItems(value))
{
success = false;
msg << currentValuePath << ": may not contain the same item more than once;";
}
{ // 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++;
}
}
}
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())) &&
((!certificatesIsSet() && !rhs.certificatesIsSet()) || (certificatesIsSet() && rhs.certificatesIsSet() && getCertificates() == rhs.getCertificates())) &&
((!vaccinationBookIsSet() && !rhs.vaccinationBookIsSet()) || (vaccinationBookIsSet() && rhs.vaccinationBookIsSet() && getVaccinationBook() == rhs.getVaccinationBook()))
;
}
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.certificatesIsSet() || !o.m_Certificates.empty())
j["certificates"] = o.m_Certificates;
if(o.vaccinationBookIsSet())
j["vaccinationBook"] = o.m_VaccinationBook;
}
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("certificates") != j.end())
{
j.at("certificates").get_to(o.m_Certificates);
o.m_CertificatesIsSet = true;
}
if(j.find("vaccinationBook") != j.end())
{
j.at("vaccinationBook").get_to(o.m_VaccinationBook);
o.m_VaccinationBookIsSet = 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;
}
std::set<std::string> Pet::getCertificates() const
{
return m_Certificates;
}
void Pet::setCertificates(std::set<std::string> const& value)
{
m_Certificates = value;
m_CertificatesIsSet = true;
}
bool Pet::certificatesIsSet() const
{
return m_CertificatesIsSet;
}
void Pet::unsetCertificates()
{
m_CertificatesIsSet = false;
}
org::openapitools::server::model::Pet_vaccinationBook Pet::getVaccinationBook() const
{
return m_VaccinationBook;
}
void Pet::setVaccinationBook(org::openapitools::server::model::Pet_vaccinationBook const& value)
{
m_VaccinationBook = value;
m_VaccinationBookIsSet = true;
}
bool Pet::vaccinationBookIsSet() const
{
return m_VaccinationBookIsSet;
}
void Pet::unsetVaccinationBook()
{
m_VaccinationBookIsSet = false;
}
} // namespace org::openapitools::server::model