[cpp][tiny] rename generator, update samples (#9560)

* rename generator, update samples

* add doc

* update readme
This commit is contained in:
William Cheng
2021-05-25 23:55:16 +08:00
committed by GitHub
parent 6c40192706
commit ae430a8c14
61 changed files with 5070 additions and 38 deletions

View File

@@ -0,0 +1,139 @@
#include "ApiResponse.h"
using namespace Tiny;
ApiResponse::ApiResponse()
{
code = int(0);
type = std::string();
message = std::string();
}
ApiResponse::ApiResponse(std::string jsonString)
{
this->fromJson(jsonString);
}
ApiResponse::~ApiResponse()
{
}
void
ApiResponse::fromJson(std::string jsonObj)
{
bourne::json object = bourne::json::parse(jsonObj);
const char *codeKey = "code";
if(object.has_key(codeKey))
{
bourne::json value = object[codeKey];
jsonToValue(&code, value, "int");
}
const char *typeKey = "type";
if(object.has_key(typeKey))
{
bourne::json value = object[typeKey];
jsonToValue(&type, value, "std::string");
}
const char *messageKey = "message";
if(object.has_key(messageKey))
{
bourne::json value = object[messageKey];
jsonToValue(&message, value, "std::string");
}
}
bourne::json
ApiResponse::toJson()
{
bourne::json object = bourne::json::object();
object["code"] = getCode();
object["type"] = getType();
object["message"] = getMessage();
return object;
}
int
ApiResponse::getCode()
{
return code;
}
void
ApiResponse::setCode(int code)
{
this->code = code;
}
std::string
ApiResponse::getType()
{
return type;
}
void
ApiResponse::setType(std::string type)
{
this->type = type;
}
std::string
ApiResponse::getMessage()
{
return message;
}
void
ApiResponse::setMessage(std::string message)
{
this->message = message;
}

View File

@@ -0,0 +1,78 @@
/*
* ApiResponse.h
*
* Describes the result of uploading an image resource
*/
#ifndef TINY_CPP_CLIENT_ApiResponse_H_
#define TINY_CPP_CLIENT_ApiResponse_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief Describes the result of uploading an image resource
*
* \ingroup Models
*
*/
class ApiResponse{
public:
/*! \brief Constructor.
*/
ApiResponse();
ApiResponse(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~ApiResponse();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
int getCode();
/*! \brief Set
*/
void setCode(int code);
/*! \brief Get
*/
std::string getType();
/*! \brief Set
*/
void setType(std::string type);
/*! \brief Get
*/
std::string getMessage();
/*! \brief Set
*/
void setMessage(std::string message);
private:
int code{};
std::string type{};
std::string message{};
};
}
#endif /* TINY_CPP_CLIENT_ApiResponse_H_ */

View File

@@ -0,0 +1,106 @@
#include "Category.h"
using namespace Tiny;
Category::Category()
{
id = long(0);
name = std::string();
}
Category::Category(std::string jsonString)
{
this->fromJson(jsonString);
}
Category::~Category()
{
}
void
Category::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 *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
}
bourne::json
Category::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["name"] = getName();
return object;
}
long
Category::getId()
{
return id;
}
void
Category::setId(long id)
{
this->id = id;
}
std::string
Category::getName()
{
return name;
}
void
Category::setName(std::string name)
{
this->name = name;
}

View File

@@ -0,0 +1,70 @@
/*
* Category.h
*
* A category for a pet
*/
#ifndef TINY_CPP_CLIENT_Category_H_
#define TINY_CPP_CLIENT_Category_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A category for a pet
*
* \ingroup Models
*
*/
class Category{
public:
/*! \brief Constructor.
*/
Category();
Category(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Category();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
private:
long id{};
std::string name{};
};
}
#endif /* TINY_CPP_CLIENT_Category_H_ */

View File

@@ -0,0 +1,102 @@
#include "Helpers.h"
#include <string>
#include <sstream>
bool isprimitive(std::string type){
if(type == "std::string" ||
type == "int" ||
type == "float" ||
type == "long" ||
type == "double" ||
type == "bool" ||
type == "std::map" ||
type == "std::list")
{
return true;
}
return false;
}
void
jsonToValue(void* target, bourne::json value, std::string type)
{
if (target == NULL || value.is_null()) {
return;
}
else if (type.compare("bool") == 0)
{
bool* val = static_cast<bool*> (target);
*val = value.to_bool();
}
else if (type.compare("int") == 0)
{
int* val = static_cast<int*> (target);
*val = value.to_int();
}
else if (type.compare("float") == 0)
{
float* val = static_cast<float*> (target);
*val = (float)(value.to_float());
}
else if (type.compare("long") == 0)
{
long* val = static_cast<long*> (target);
*val = (long)(value.to_int());
}
else if (type.compare("double") == 0)
{
double* val = static_cast<double*> (target);
*val = value.to_float();
}
else if (type.compare("std::string") == 0)
{
std::string* val = static_cast<std::string*> (target);
*val = value.to_string();
}
else {
return;
}
}
std::string
stringify(long input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(int input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(double input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(float input){
std::stringstream stream;
stream << input;
return stream.str();
};
std::string
stringify(std::string input){
std::stringstream stream;
stream << input;
return stream.str();
};

View File

@@ -0,0 +1,22 @@
#ifndef TINY_CPP_CLIENT_HELPERS_H_
#define TINY_CPP_CLIENT_HELPERS_H_
#include <string>
#include "bourne/json.hpp"
bool isprimitive(std::string type);
void jsonToValue(void* target, bourne::json value, std::string type);
std::string stringify(long input);
std::string stringify(int input);
std::string stringify(double input);
std::string stringify(float input);
std::string stringify(std::string input);
#endif /* TINY_CPP_CLIENT_HELPERS_H_ */

View File

@@ -0,0 +1,238 @@
#include "Order.h"
using namespace Tiny;
Order::Order()
{
id = long(0);
petId = long(0);
quantity = int(0);
shipDate = std::string();
status = std::string();
complete = bool(false);
}
Order::Order(std::string jsonString)
{
this->fromJson(jsonString);
}
Order::~Order()
{
}
void
Order::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 *petIdKey = "petId";
if(object.has_key(petIdKey))
{
bourne::json value = object[petIdKey];
jsonToValue(&petId, value, "long");
}
const char *quantityKey = "quantity";
if(object.has_key(quantityKey))
{
bourne::json value = object[quantityKey];
jsonToValue(&quantity, value, "int");
}
const char *shipDateKey = "shipDate";
if(object.has_key(shipDateKey))
{
bourne::json value = object[shipDateKey];
jsonToValue(&shipDate, value, "std::string");
}
const char *statusKey = "status";
if(object.has_key(statusKey))
{
bourne::json value = object[statusKey];
jsonToValue(&status, value, "std::string");
}
const char *completeKey = "complete";
if(object.has_key(completeKey))
{
bourne::json value = object[completeKey];
jsonToValue(&complete, value, "bool");
}
}
bourne::json
Order::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["petId"] = getPetId();
object["quantity"] = getQuantity();
object["shipDate"] = getShipDate();
object["status"] = getStatus();
object["complete"] = isComplete();
return object;
}
long
Order::getId()
{
return id;
}
void
Order::setId(long id)
{
this->id = id;
}
long
Order::getPetId()
{
return petId;
}
void
Order::setPetId(long petId)
{
this->petId = petId;
}
int
Order::getQuantity()
{
return quantity;
}
void
Order::setQuantity(int quantity)
{
this->quantity = quantity;
}
std::string
Order::getShipDate()
{
return shipDate;
}
void
Order::setShipDate(std::string shipDate)
{
this->shipDate = shipDate;
}
std::string
Order::getStatus()
{
return status;
}
void
Order::setStatus(std::string status)
{
this->status = status;
}
bool
Order::isComplete()
{
return complete;
}
void
Order::setComplete(bool complete)
{
this->complete = complete;
}

View File

@@ -0,0 +1,102 @@
/*
* Order.h
*
* An order for a pets from the pet store
*/
#ifndef TINY_CPP_CLIENT_Order_H_
#define TINY_CPP_CLIENT_Order_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief An order for a pets from the pet store
*
* \ingroup Models
*
*/
class Order{
public:
/*! \brief Constructor.
*/
Order();
Order(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Order();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
long getPetId();
/*! \brief Set
*/
void setPetId(long petId);
/*! \brief Get
*/
int getQuantity();
/*! \brief Set
*/
void setQuantity(int quantity);
/*! \brief Get
*/
std::string getShipDate();
/*! \brief Set
*/
void setShipDate(std::string shipDate);
/*! \brief Get Order Status
*/
std::string getStatus();
/*! \brief Set Order Status
*/
void setStatus(std::string status);
/*! \brief Get
*/
bool isComplete();
/*! \brief Set
*/
void setComplete(bool complete);
private:
long id{};
long petId{};
int quantity{};
std::string shipDate{};
std::string status{};
bool complete{};
};
}
#endif /* TINY_CPP_CLIENT_Order_H_ */

View File

@@ -0,0 +1,274 @@
#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;
}

View File

@@ -0,0 +1,105 @@
/*
* Pet.h
*
* A pet for sale in the pet store
*/
#ifndef TINY_CPP_CLIENT_Pet_H_
#define TINY_CPP_CLIENT_Pet_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
#include "Category.h"
#include "Tag.h"
#include <list>
namespace Tiny {
/*! \brief A pet for sale in the pet store
*
* \ingroup Models
*
*/
class Pet{
public:
/*! \brief Constructor.
*/
Pet();
Pet(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Pet();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
Category getCategory();
/*! \brief Set
*/
void setCategory(Category category);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
/*! \brief Get
*/
std::list<std::string> getPhotoUrls();
/*! \brief Set
*/
void setPhotoUrls(std::list <std::string> photoUrls);
/*! \brief Get
*/
std::list<Tag> getTags();
/*! \brief Set
*/
void setTags(std::list <Tag> tags);
/*! \brief Get pet status in the store
*/
std::string getStatus();
/*! \brief Set pet status in the store
*/
void setStatus(std::string status);
private:
long id{};
Category category;
std::string name{};
std::list<std::string> photoUrls;
std::list<Tag> tags;
std::string status{};
};
}
#endif /* TINY_CPP_CLIENT_Pet_H_ */

View File

@@ -0,0 +1,106 @@
#include "Tag.h"
using namespace Tiny;
Tag::Tag()
{
id = long(0);
name = std::string();
}
Tag::Tag(std::string jsonString)
{
this->fromJson(jsonString);
}
Tag::~Tag()
{
}
void
Tag::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 *nameKey = "name";
if(object.has_key(nameKey))
{
bourne::json value = object[nameKey];
jsonToValue(&name, value, "std::string");
}
}
bourne::json
Tag::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["name"] = getName();
return object;
}
long
Tag::getId()
{
return id;
}
void
Tag::setId(long id)
{
this->id = id;
}
std::string
Tag::getName()
{
return name;
}
void
Tag::setName(std::string name)
{
this->name = name;
}

View File

@@ -0,0 +1,70 @@
/*
* Tag.h
*
* A tag for a pet
*/
#ifndef TINY_CPP_CLIENT_Tag_H_
#define TINY_CPP_CLIENT_Tag_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A tag for a pet
*
* \ingroup Models
*
*/
class Tag{
public:
/*! \brief Constructor.
*/
Tag();
Tag(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~Tag();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getName();
/*! \brief Set
*/
void setName(std::string name);
private:
long id{};
std::string name{};
};
}
#endif /* TINY_CPP_CLIENT_Tag_H_ */

View File

@@ -0,0 +1,304 @@
#include "User.h"
using namespace Tiny;
User::User()
{
id = long(0);
username = std::string();
firstName = std::string();
lastName = std::string();
email = std::string();
password = std::string();
phone = std::string();
userStatus = int(0);
}
User::User(std::string jsonString)
{
this->fromJson(jsonString);
}
User::~User()
{
}
void
User::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 *usernameKey = "username";
if(object.has_key(usernameKey))
{
bourne::json value = object[usernameKey];
jsonToValue(&username, value, "std::string");
}
const char *firstNameKey = "firstName";
if(object.has_key(firstNameKey))
{
bourne::json value = object[firstNameKey];
jsonToValue(&firstName, value, "std::string");
}
const char *lastNameKey = "lastName";
if(object.has_key(lastNameKey))
{
bourne::json value = object[lastNameKey];
jsonToValue(&lastName, value, "std::string");
}
const char *emailKey = "email";
if(object.has_key(emailKey))
{
bourne::json value = object[emailKey];
jsonToValue(&email, value, "std::string");
}
const char *passwordKey = "password";
if(object.has_key(passwordKey))
{
bourne::json value = object[passwordKey];
jsonToValue(&password, value, "std::string");
}
const char *phoneKey = "phone";
if(object.has_key(phoneKey))
{
bourne::json value = object[phoneKey];
jsonToValue(&phone, value, "std::string");
}
const char *userStatusKey = "userStatus";
if(object.has_key(userStatusKey))
{
bourne::json value = object[userStatusKey];
jsonToValue(&userStatus, value, "int");
}
}
bourne::json
User::toJson()
{
bourne::json object = bourne::json::object();
object["id"] = getId();
object["username"] = getUsername();
object["firstName"] = getFirstName();
object["lastName"] = getLastName();
object["email"] = getEmail();
object["password"] = getPassword();
object["phone"] = getPhone();
object["userStatus"] = getUserStatus();
return object;
}
long
User::getId()
{
return id;
}
void
User::setId(long id)
{
this->id = id;
}
std::string
User::getUsername()
{
return username;
}
void
User::setUsername(std::string username)
{
this->username = username;
}
std::string
User::getFirstName()
{
return firstName;
}
void
User::setFirstName(std::string firstName)
{
this->firstName = firstName;
}
std::string
User::getLastName()
{
return lastName;
}
void
User::setLastName(std::string lastName)
{
this->lastName = lastName;
}
std::string
User::getEmail()
{
return email;
}
void
User::setEmail(std::string email)
{
this->email = email;
}
std::string
User::getPassword()
{
return password;
}
void
User::setPassword(std::string password)
{
this->password = password;
}
std::string
User::getPhone()
{
return phone;
}
void
User::setPhone(std::string phone)
{
this->phone = phone;
}
int
User::getUserStatus()
{
return userStatus;
}
void
User::setUserStatus(int userStatus)
{
this->userStatus = userStatus;
}

View File

@@ -0,0 +1,118 @@
/*
* User.h
*
* A User who is purchasing from the pet store
*/
#ifndef TINY_CPP_CLIENT_User_H_
#define TINY_CPP_CLIENT_User_H_
#include <string>
#include "bourne/json.hpp"
#include "Helpers.h"
namespace Tiny {
/*! \brief A User who is purchasing from the pet store
*
* \ingroup Models
*
*/
class User{
public:
/*! \brief Constructor.
*/
User();
User(std::string jsonString);
/*! \brief Destructor.
*/
virtual ~User();
/*! \brief Retrieve a bourne JSON representation of this class.
*/
bourne::json toJson();
/*! \brief Fills in members of this class from bourne JSON object representing it.
*/
void fromJson(std::string jsonObj);
/*! \brief Get
*/
long getId();
/*! \brief Set
*/
void setId(long id);
/*! \brief Get
*/
std::string getUsername();
/*! \brief Set
*/
void setUsername(std::string username);
/*! \brief Get
*/
std::string getFirstName();
/*! \brief Set
*/
void setFirstName(std::string firstName);
/*! \brief Get
*/
std::string getLastName();
/*! \brief Set
*/
void setLastName(std::string lastName);
/*! \brief Get
*/
std::string getEmail();
/*! \brief Set
*/
void setEmail(std::string email);
/*! \brief Get
*/
std::string getPassword();
/*! \brief Set
*/
void setPassword(std::string password);
/*! \brief Get
*/
std::string getPhone();
/*! \brief Set
*/
void setPhone(std::string phone);
/*! \brief Get User Status
*/
int getUserStatus();
/*! \brief Set User Status
*/
void setUserStatus(int userStatus);
private:
long id{};
std::string username{};
std::string firstName{};
std::string lastName{};
std::string email{};
std::string password{};
std::string phone{};
int userStatus{};
};
}
#endif /* TINY_CPP_CLIENT_User_H_ */

View File

@@ -0,0 +1,139 @@
#include "ApiResponse.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_ApiResponse_code_is_assigned_from_json()
{
bourne::json input =
{
"code", 1
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getCode());
}
void test_ApiResponse_type_is_assigned_from_json()
{
bourne::json input =
{
"type", "hello"
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getType().c_str());
}
void test_ApiResponse_message_is_assigned_from_json()
{
bourne::json input =
{
"message", "hello"
};
ApiResponse obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getMessage().c_str());
}
void test_ApiResponse_code_is_converted_to_json()
{
bourne::json input =
{
"code", 1
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["code"] == output["code"]);
}
void test_ApiResponse_type_is_converted_to_json()
{
bourne::json input =
{
"type", "hello"
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["type"] == output["type"]);
}
void test_ApiResponse_message_is_converted_to_json()
{
bourne::json input =
{
"message", "hello"
};
ApiResponse obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["message"] == output["message"]);
}

View File

@@ -0,0 +1,97 @@
#include "Category.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Category_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Category obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Category_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Category obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Category_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Category obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Category_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Category obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}

View File

@@ -0,0 +1,245 @@
#include "Order.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Order_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Order_petId_is_assigned_from_json()
{
bourne::json input =
{
"petId", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getPetId());
}
void test_Order_quantity_is_assigned_from_json()
{
bourne::json input =
{
"quantity", 1
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getQuantity());
}
void test_Order_shipDate_is_assigned_from_json()
{
}
void test_Order_status_is_assigned_from_json()
{
bourne::json input =
{
"status", "hello"
};
Order obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getStatus().c_str());
}
void test_Order_complete_is_assigned_from_json()
{
bourne::json input =
{
"complete", true
};
Order obj(input.dump());
TEST_ASSERT(true == obj.isComplete());
}
void test_Order_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Order_petId_is_converted_to_json()
{
bourne::json input =
{
"petId", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["petId"] == output["petId"]);
}
void test_Order_quantity_is_converted_to_json()
{
bourne::json input =
{
"quantity", 1
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["quantity"] == output["quantity"]);
}
void test_Order_shipDate_is_converted_to_json()
{
}
void test_Order_status_is_converted_to_json()
{
bourne::json input =
{
"status", "hello"
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["status"] == output["status"]);
}
void test_Order_complete_is_converted_to_json()
{
bourne::json input =
{
"complete", true
};
Order obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["complete"] == output["complete"]);
}

View File

@@ -0,0 +1,145 @@
#include "Pet.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Pet_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Pet_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Pet_status_is_assigned_from_json()
{
bourne::json input =
{
"status", "hello"
};
Pet obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getStatus().c_str());
}
void test_Pet_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Pet_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}
void test_Pet_status_is_converted_to_json()
{
bourne::json input =
{
"status", "hello"
};
Pet obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["status"] == output["status"]);
}

View File

@@ -0,0 +1,97 @@
#include "Tag.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_Tag_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
Tag obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_Tag_name_is_assigned_from_json()
{
bourne::json input =
{
"name", "hello"
};
Tag obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getName().c_str());
}
void test_Tag_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
Tag obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_Tag_name_is_converted_to_json()
{
bourne::json input =
{
"name", "hello"
};
Tag obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["name"] == output["name"]);
}

View File

@@ -0,0 +1,349 @@
#include "User.h"
using namespace Tiny;
#include <string>
#include <list>
#include <unity.h>
#include "bourne/json.hpp"
void test_User_id_is_assigned_from_json()
{
bourne::json input =
{
"id", 1
};
User obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getId());
}
void test_User_username_is_assigned_from_json()
{
bourne::json input =
{
"username", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getUsername().c_str());
}
void test_User_firstName_is_assigned_from_json()
{
bourne::json input =
{
"firstName", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getFirstName().c_str());
}
void test_User_lastName_is_assigned_from_json()
{
bourne::json input =
{
"lastName", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getLastName().c_str());
}
void test_User_email_is_assigned_from_json()
{
bourne::json input =
{
"email", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getEmail().c_str());
}
void test_User_password_is_assigned_from_json()
{
bourne::json input =
{
"password", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getPassword().c_str());
}
void test_User_phone_is_assigned_from_json()
{
bourne::json input =
{
"phone", "hello"
};
User obj(input.dump());
TEST_ASSERT_EQUAL_STRING("hello", obj.getPhone().c_str());
}
void test_User_userStatus_is_assigned_from_json()
{
bourne::json input =
{
"userStatus", 1
};
User obj(input.dump());
TEST_ASSERT_EQUAL_INT(1, obj.getUserStatus());
}
void test_User_id_is_converted_to_json()
{
bourne::json input =
{
"id", 1
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["id"] == output["id"]);
}
void test_User_username_is_converted_to_json()
{
bourne::json input =
{
"username", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["username"] == output["username"]);
}
void test_User_firstName_is_converted_to_json()
{
bourne::json input =
{
"firstName", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["firstName"] == output["firstName"]);
}
void test_User_lastName_is_converted_to_json()
{
bourne::json input =
{
"lastName", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["lastName"] == output["lastName"]);
}
void test_User_email_is_converted_to_json()
{
bourne::json input =
{
"email", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["email"] == output["email"]);
}
void test_User_password_is_converted_to_json()
{
bourne::json input =
{
"password", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["password"] == output["password"]);
}
void test_User_phone_is_converted_to_json()
{
bourne::json input =
{
"phone", "hello"
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["phone"] == output["phone"]);
}
void test_User_userStatus_is_converted_to_json()
{
bourne::json input =
{
"userStatus", 1
};
User obj(input.dump());
bourne::json output = bourne::json::object();
output = obj.toJson();
TEST_ASSERT(input["userStatus"] == output["userStatus"]);
}

View File

@@ -0,0 +1,8 @@
#include "AbstractService.h"
#include "Arduino.h"
void Tiny::AbstractService::begin(std::string url){
http.begin(String(url.c_str()), test_root_ca); //HTTPS connection
}

View File

@@ -0,0 +1,28 @@
#ifndef TINY_CPP_CLIENT_ABSTRACTSERVICE_H_
#define TINY_CPP_CLIENT_ABSTRACTSERVICE_H_
#include "HTTPClient.h"
#include "Response.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class AbstractService {
public:
HTTPClient http;
std::string basepath = "https://petstore3.swagger.io/api/v3"; // TODO: change to your url
void begin(std::string url);
// Go and comment out a certificate in root.cert, if you get an error here
// Certificate from file
const char* test_root_ca =
#include "../../root.cert"
;
}; // end class
}// namespace Tinyclient
#endif /* TINY_CPP_CLIENT_ABSTRACTSERVICE_H_ */

View File

@@ -0,0 +1,418 @@
#include "PetApi.h"
using namespace Tiny;
Response<
Pet
>
PetApi::
addPet(
Pet pet
)
{
std::string url = basepath + "/pet"; //
// Query |
// Headers |
// Form |
// Body | pet
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = pet.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
String
>
PetApi::
deletePet(
long petId
,
std::string apiKey
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers | apiKey
// Form |
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
std::list<Pet>
>
PetApi::
findPetsByStatus(
std::list<std::string> status
)
{
std::string url = basepath + "/pet/findByStatus"; //
// Query | status
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
std::list<Pet> obj = std::list<Pet>();
bourne::json jsonPayload(output_string);
for(auto& var : jsonPayload.array_range())
{
Pet tmp(var.dump());
obj.push_back(tmp);
}
Response<std::list<Pet>> response(obj, httpCode);
return response;
}
Response<
std::list<Pet>
>
PetApi::
findPetsByTags(
std::list<std::string> tags
)
{
std::string url = basepath + "/pet/findByTags"; //
// Query | tags
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
std::list<Pet> obj = std::list<Pet>();
bourne::json jsonPayload(output_string);
for(auto& var : jsonPayload.array_range())
{
Pet tmp(var.dump());
obj.push_back(tmp);
}
Response<std::list<Pet>> response(obj, httpCode);
return response;
}
Response<
Pet
>
PetApi::
getPetById(
long petId
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers |
// Form |
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
Pet
>
PetApi::
updatePet(
Pet pet
)
{
std::string url = basepath + "/pet"; //
// Query |
// Headers |
// Form |
// Body | pet
begin(url);
std::string payload = "";
// Send Request
// METHOD | PUT
http.addHeader("Content-Type", "application/json");
payload = pet.toJson().dump();
int httpCode = http.sendRequest("PUT", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Pet obj(output_string);
Response<Pet> response(obj, httpCode);
return response;
}
Response<
String
>
PetApi::
updatePetWithForm(
long petId
,
std::string name
,
std::string status
)
{
std::string url = basepath + "/pet/{petId}"; //petId
// Query |
// Headers |
// Form | name status
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
ApiResponse
>
PetApi::
uploadFile(
long petId
,
std::string additionalMetadata
,
std::string file
)
{
std::string url = basepath + "/pet/{petId}/uploadImage"; //petId
// Query |
// Headers |
// Form | additionalMetadata file
// Body |
std::string s_petId("{");
s_petId.append("petId");
s_petId.append("}");
int pos = url.find(s_petId);
url.erase(pos, s_petId.length());
url.insert(pos, stringify(petId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
ApiResponse obj(output_string);
Response<ApiResponse> response(obj, httpCode);
return response;
}

View File

@@ -0,0 +1,163 @@
#ifndef TINY_CPP_CLIENT_PetApi_H_
#define TINY_CPP_CLIENT_PetApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include "ApiResponse.h"
#include "Pet.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class PetApi : public AbstractService {
public:
PetApi() = default;
virtual ~PetApi() = default;
/**
* Add a new pet to the store.
*
*
* \param pet Pet object that needs to be added to the store *Required*
*/
Response<
Pet
>
addPet(
Pet pet
);
/**
* Deletes a pet.
*
*
* \param petId Pet id to delete *Required*
* \param apiKey
*/
Response<
String
>
deletePet(
long petId
,
std::string apiKey
);
/**
* Finds Pets by status.
*
* Multiple status values can be provided with comma separated strings
* \param status Status values that need to be considered for filter *Required*
*/
Response<
std::list<Pet>
>
findPetsByStatus(
std::list<std::string> status
);
/**
* Finds Pets by tags.
*
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
* \param tags Tags to filter by *Required*
*/
Response<
std::list<Pet>
>
findPetsByTags(
std::list<std::string> tags
);
/**
* Find pet by ID.
*
* Returns a single pet
* \param petId ID of pet to return *Required*
*/
Response<
Pet
>
getPetById(
long petId
);
/**
* Update an existing pet.
*
*
* \param pet Pet object that needs to be added to the store *Required*
*/
Response<
Pet
>
updatePet(
Pet pet
);
/**
* Updates a pet in the store with form data.
*
*
* \param petId ID of pet that needs to be updated *Required*
* \param name Updated name of the pet
* \param status Updated status of the pet
*/
Response<
String
>
updatePetWithForm(
long petId
,
std::string name
,
std::string status
);
/**
* uploads an image.
*
*
* \param petId ID of pet to update *Required*
* \param additionalMetadata Additional data to pass to server
* \param file file to upload
*/
Response<
ApiResponse
>
uploadFile(
long petId
,
std::string additionalMetadata
,
std::string file
);
};
}
#endif /* TINY_CPP_CLIENT_PetApi_H_ */

View File

@@ -0,0 +1,25 @@
#ifndef TINY_CPP_CLIENT_RESPONSE_H_
#define TINY_CPP_CLIENT_RESPONSE_H_
#include <string>
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
template <typename T = std::string>
class Response {
public:
Response(T _obj, int _code){
obj = _obj;
code = _code;
}
int code;
T obj;
};
} // namespace Tinyclient
#endif /* TINY_CPP_CLIENT_RESPONSE_H_ */

View File

@@ -0,0 +1,185 @@
#include "StoreApi.h"
using namespace Tiny;
Response<
String
>
StoreApi::
deleteOrder(
std::string orderId
)
{
std::string url = basepath + "/store/order/{orderId}"; //orderId
// Query |
// Headers |
// Form |
// Body |
std::string s_orderId("{");
s_orderId.append("orderId");
s_orderId.append("}");
int pos = url.find(s_orderId);
url.erase(pos, s_orderId.length());
url.insert(pos, stringify(orderId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
StoreApi::
getInventory(
)
{
std::string url = basepath + "/store/inventory"; //
// Query |
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
//TODO: Implement map logic here
//TODO: No support for maps.
Response<String> response(output, httpCode);
return response;
}
Response<
Order
>
StoreApi::
getOrderById(
long orderId
)
{
std::string url = basepath + "/store/order/{orderId}"; //orderId
// Query |
// Headers |
// Form |
// Body |
std::string s_orderId("{");
s_orderId.append("orderId");
s_orderId.append("}");
int pos = url.find(s_orderId);
url.erase(pos, s_orderId.length());
url.insert(pos, stringify(orderId));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Order obj(output_string);
Response<Order> response(obj, httpCode);
return response;
}
Response<
Order
>
StoreApi::
placeOrder(
Order order
)
{
std::string url = basepath + "/store/order"; //
// Query |
// Headers |
// Form |
// Body | order
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = order.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Order obj(output_string);
Response<Order> response(obj, httpCode);
return response;
}

View File

@@ -0,0 +1,83 @@
#ifndef TINY_CPP_CLIENT_StoreApi_H_
#define TINY_CPP_CLIENT_StoreApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include <map>
#include "Order.h"
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class StoreApi : public AbstractService {
public:
StoreApi() = default;
virtual ~StoreApi() = default;
/**
* Delete purchase order by ID.
*
* For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors
* \param orderId ID of the order that needs to be deleted *Required*
*/
Response<
String
>
deleteOrder(
std::string orderId
);
/**
* Returns pet inventories by status.
*
* Returns a map of status codes to quantities
*/
Response<
String
>
getInventory(
);
/**
* Find purchase order by ID.
*
* For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions
* \param orderId ID of pet that needs to be fetched *Required*
*/
Response<
Order
>
getOrderById(
long orderId
);
/**
* Place an order for a pet.
*
*
* \param order order placed for purchasing the pet *Required*
*/
Response<
Order
>
placeOrder(
Order order
);
};
}
#endif /* TINY_CPP_CLIENT_StoreApi_H_ */

View File

@@ -0,0 +1,366 @@
#include "UserApi.h"
using namespace Tiny;
Response<
String
>
UserApi::
createUser(
User user
)
{
std::string url = basepath + "/user"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
payload = user.toJson().dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
createUsersWithArrayInput(
std::list<User> user
)
{
std::string url = basepath + "/user/createWithArray"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
bourne::json tmp_arr = bourne::json::array();
for(auto& var : user)
{
auto tmp = var.toJson();
tmp_arr.append(tmp);
}
payload = tmp_arr.dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
createUsersWithListInput(
std::list<User> user
)
{
std::string url = basepath + "/user/createWithList"; //
// Query |
// Headers |
// Form |
// Body | user
begin(url);
std::string payload = "";
// Send Request
// METHOD | POST
http.addHeader("Content-Type", "application/json");
bourne::json tmp_arr = bourne::json::array();
for(auto& var : user)
{
auto tmp = var.toJson();
tmp_arr.append(tmp);
}
payload = tmp_arr.dump();
int httpCode = http.sendRequest("POST", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
deleteUser(
std::string username
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body |
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | DELETE
int httpCode = http.sendRequest("DELETE", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
User
>
UserApi::
getUserByName(
std::string username
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body |
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
User obj(output_string);
Response<User> response(obj, httpCode);
return response;
}
Response<
std::string
>
UserApi::
loginUser(
std::string username
,
std::string password
)
{
std::string url = basepath + "/user/login"; //
// Query | username password
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
bourne::json jsonPayload(output_string);
std::string obj;
jsonToValue(&obj, jsonPayload, "std::string");
Response<std::string> response(obj, httpCode);
return response;
}
Response<
String
>
UserApi::
logoutUser(
)
{
std::string url = basepath + "/user/logout"; //
// Query |
// Headers |
// Form |
// Body |
begin(url);
std::string payload = "";
// Send Request
// METHOD | GET
int httpCode = http.sendRequest("GET", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}
Response<
String
>
UserApi::
updateUser(
std::string username
,
User user
)
{
std::string url = basepath + "/user/{username}"; //username
// Query |
// Headers |
// Form |
// Body | user
std::string s_username("{");
s_username.append("username");
s_username.append("}");
int pos = url.find(s_username);
url.erase(pos, s_username.length());
url.insert(pos, stringify(username));
begin(url);
std::string payload = "";
// Send Request
// METHOD | PUT
http.addHeader("Content-Type", "application/json");
payload = user.toJson().dump();
int httpCode = http.sendRequest("PUT", reinterpret_cast<uint8_t*>(&payload[0]), payload.length());
// Handle Request
String output = http.getString();
std::string output_string = output.c_str();
http.end();
Response<String> response(output, httpCode);
return response;
}

View File

@@ -0,0 +1,147 @@
#ifndef TINY_CPP_CLIENT_UserApi_H_
#define TINY_CPP_CLIENT_UserApi_H_
#include "Response.h"
#include "Arduino.h"
#include "AbstractService.h"
#include "Helpers.h"
#include <list>
#include "User.h"
#include <list>
namespace Tiny {
/**
* Class
* Generated with openapi::tiny-cpp-client
*/
class UserApi : public AbstractService {
public:
UserApi() = default;
virtual ~UserApi() = default;
/**
* Create user.
*
* This can only be done by the logged in user.
* \param user Created user object *Required*
*/
Response<
String
>
createUser(
User user
);
/**
* Creates list of users with given input array.
*
*
* \param user List of user object *Required*
*/
Response<
String
>
createUsersWithArrayInput(
std::list<User> user
);
/**
* Creates list of users with given input array.
*
*
* \param user List of user object *Required*
*/
Response<
String
>
createUsersWithListInput(
std::list<User> user
);
/**
* Delete user.
*
* This can only be done by the logged in user.
* \param username The name that needs to be deleted *Required*
*/
Response<
String
>
deleteUser(
std::string username
);
/**
* Get user by user name.
*
*
* \param username The name that needs to be fetched. Use user1 for testing. *Required*
*/
Response<
User
>
getUserByName(
std::string username
);
/**
* Logs user into the system.
*
*
* \param username The user name for login *Required*
* \param password The password for login in clear text *Required*
*/
Response<
std::string
>
loginUser(
std::string username
,
std::string password
);
/**
* Logs out current logged in user session.
*
*
*/
Response<
String
>
logoutUser(
);
/**
* Updated user.
*
* This can only be done by the logged in user.
* \param username name that need to be deleted *Required*
* \param user Updated user object *Required*
*/
Response<
String
>
updateUser(
std::string username
,
User user
);
};
}
#endif /* TINY_CPP_CLIENT_UserApi_H_ */