William Cheng 0204bf4ae2 Squashed commit of the following:
commit c5a0d0f7394aa742fa336fff7e7c1d3049761868
Merge: 8c4991ba3ed f8ff8c87609
Author: William Cheng <wing328hk@gmail.com>
Date:   Tue Aug 17 18:28:12 2021 +0800

    Merge branch 'mustache-linting' of https://github.com/NathanBaulch/openapi-generator into NathanBaulch-mustache-linting

commit f8ff8c87609b1ca36fa26fb8474806999638195e
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Thu Aug 5 14:12:47 2021 +1000

    Reorder tags that handle missing values

commit f5d8a33709d6a3f846a9fe4520b78c3d637051d9
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Thu Aug 5 14:08:59 2021 +1000

    Use dot notation where possible

commit 493d14921e2333f3ae19ef6fc89318b7e263a80c
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Thu Aug 5 14:10:49 2021 +1000

    Remove empty tags

commit 32480dc53f48227d55531b94e307d72671373737
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Thu Aug 5 10:41:58 2021 +1000

    Remove redundant sections

commit a8edabd722c34aa094b4aeb11c22664529c3a219
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Wed Aug 4 22:02:22 2021 +1000

    Trim extra EOF new lines

commit e89bd7458e3594bf0d30e580bc9408e45b018a57
Author: Nathan Baulch <nathan.baulch@gmail.com>
Date:   Wed Aug 4 21:59:26 2021 +1000

    Trim trailing whitespace
2021-08-17 18:37:51 +08:00

275 lines
3.3 KiB
C++

#include "Pet.h"
using namespace Tiny;
Pet::Pet()
{
id = long(0);
category = Category();
name = std::string();
photoUrls = std::list<std::string>();
tags = std::list<Tag>();
status = std::string();
}
Pet::Pet(std::string jsonString)
{
this->fromJson(jsonString);
}
Pet::~Pet()
{
}
void
Pet::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *idKey = "id";
if(object.has_key(idKey))
{
bourne::json value = object[idKey];
jsonToValue(&id, value, "long");
}
const char *categoryKey = "category";
if(object.has_key(categoryKey))
{
bourne::json value = object[categoryKey];
Category* obj = &category;
obj->fromJson(value.dump());
}
const char *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
const char *photoUrlsKey = "photoUrls";
if(object.has_key(photoUrlsKey))
{
bourne::json value = object[photoUrlsKey];
std::list<std::string> photoUrls_list;
std::string element;
for(auto& var : value.array_range())
{
jsonToValue(&element, var, "std::string");
photoUrls_list.push_back(element);
}
photoUrls = photoUrls_list;
}
const char *tagsKey = "tags";
if(object.has_key(tagsKey))
{
bourne::json value = object[tagsKey];
std::list<Tag> tags_list;
Tag element;
for(auto& var : value.array_range())
{
element.fromJson(var.dump());
tags_list.push_back(element);
}
tags = tags_list;
}
const char *statusKey = "status";
if(object.has_key(statusKey))
{
bourne::json value = object[statusKey];
jsonToValue(&status, value, "std::string");
}
}
bourne::json
Pet::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["category"] = getCategory().toJson();
object["name"] = getName();
std::list<std::string> photoUrls_list = getPhotoUrls();
bourne::json photoUrls_arr = bourne::json::array();
for(auto& var : photoUrls_list)
{
photoUrls_arr.append(var);
}
object["photoUrls"] = photoUrls_arr;
std::list<Tag> tags_list = getTags();
bourne::json tags_arr = bourne::json::array();
for(auto& var : tags_list)
{
Tag obj = var;
tags_arr.append(obj.toJson());
}
object["tags"] = tags_arr;
object["status"] = getStatus();
return object;
}
long
Pet::getId()
{
return id;
}
void
Pet::setId(long id)
{
this->id = id;
}
Category
Pet::getCategory()
{
return category;
}
void
Pet::setCategory(Category category)
{
this->category = category;
}
std::string
Pet::getName()
{
return name;
}
void
Pet::setName(std::string name)
{
this->name = name;
}
std::list<std::string>
Pet::getPhotoUrls()
{
return photoUrls;
}
void
Pet::setPhotoUrls(std::list <std::string> photoUrls)
{
this->photoUrls = photoUrls;
}
std::list<Tag>
Pet::getTags()
{
return tags;
}
void
Pet::setTags(std::list <Tag> tags)
{
this->tags = tags;
}
std::string
Pet::getStatus()
{
return status;
}
void
Pet::setStatus(std::string status)
{
this->status = status;
}