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

117 lines
2.8 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_vaccinationBook.h"
#include "Helpers.h"
#include <sstream>
namespace org::openapitools::server::model
{
Pet_vaccinationBook::Pet_vaccinationBook()
{
}
void Pet_vaccinationBook::validate() const
{
std::stringstream msg;
if (!validate(msg))
{
throw org::openapitools::server::helpers::ValidationException(msg.str());
}
}
bool Pet_vaccinationBook::validate(std::stringstream& msg) const
{
return validate(msg, "");
}
bool Pet_vaccinationBook::validate(std::stringstream& msg, const std::string& pathPrefix) const
{
bool success = true;
const std::string _pathPrefix = pathPrefix.empty() ? "Pet_vaccinationBook" : pathPrefix;
/* Vaccines */ {
const std::set<org::openapitools::server::model::Vaccine>& value = m_Vaccines;
const std::string currentValuePath = _pathPrefix + ".vaccines";
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 org::openapitools::server::model::Vaccine& value : value)
{
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
success = value.validate(msg, currentValuePath + ".vaccines") && success;
i++;
}
}
}
return success;
}
bool Pet_vaccinationBook::operator==(const Pet_vaccinationBook& rhs) const
{
return
(getVaccines() == rhs.getVaccines())
;
}
bool Pet_vaccinationBook::operator!=(const Pet_vaccinationBook& rhs) const
{
return !(*this == rhs);
}
void to_json(nlohmann::json& j, const Pet_vaccinationBook& o)
{
j = nlohmann::json::object();
j["vaccines"] = o.m_Vaccines;
}
void from_json(const nlohmann::json& j, Pet_vaccinationBook& o)
{
j.at("vaccines").get_to(o.m_Vaccines);
}
std::set<org::openapitools::server::model::Vaccine> Pet_vaccinationBook::getVaccines() const
{
return m_Vaccines;
}
void Pet_vaccinationBook::setVaccines(std::set<org::openapitools::server::model::Vaccine> const& value)
{
m_Vaccines = value;
}
} // namespace org::openapitools::server::model