forked from loafle/openapi-generator-original
* Continuing from #1317 and its PRs for pistache server string enum code generation; * A class that has an `anyOf` specification, in cpp side will have no members: in stead it should have a member having the type `classname_anyOf` * Thus, Its `==` operator is not present or wrongly filled * An string enum, should have a better usage, hence the `setEnumValue` * this PR, is a brigde between `stringenumclassname_anyOf` and `stringenumclassname` * `anyOf` specification is not just about `Enums`, so a better handling is needed from mustache templates, hence new template model parameter `isStringEnumContainer` * PR fix: muttleyxd: `double semicolon` * PR fix: wing328: `I think std::string is C++ only. What about adding x-is-string-enum-container instead in the postProcessModel operation in the C++ pistache server generator?` * PR fix: wing328: `I think std::string is C++ only...` after fix get latest codes and then generate samples Co-authored-by: Mehmet Fatih <mfyuce@netas.com.tr>
261 lines
5.4 KiB
C++
261 lines
5.4 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;
|
|
|
|
}
|
|
|
|
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<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 Tag& value : value)
|
|
{
|
|
const std::string currentValuePath = oldValuePath + "[" + std::to_string(i) + "]";
|
|
|
|
success = value.validate(msg, currentValuePath + ".tags") && success;
|
|
|
|
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()))
|
|
|
|
;
|
|
}
|
|
|
|
bool Pet::operator!=(const Pet& rhs) const
|
|
{
|
|
return !(*this == rhs);
|
|
}
|
|
|
|
void to_json(nlohmann::json& j, const Pet& o)
|
|
{
|
|
j = nlohmann::json();
|
|
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;
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
}
|
|
|
|
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;
|
|
}
|
|
Category Pet::getCategory() const
|
|
{
|
|
return m_Category;
|
|
}
|
|
void Pet::setCategory(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<Tag> Pet::getTags() const
|
|
{
|
|
return m_Tags;
|
|
}
|
|
void Pet::setTags(std::vector<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;
|
|
}
|
|
|
|
|
|
} // namespace org::openapitools::server::model
|
|
|