Merge remote-tracking branch 'origin/5.3.x' into 6.0.x

This commit is contained in:
William Cheng
2021-07-12 17:11:35 +08:00
3874 changed files with 120282 additions and 21640 deletions

View File

@@ -0,0 +1,5 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

View File

@@ -0,0 +1,23 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator
# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.
# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs
# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux
# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux
# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md

View File

@@ -0,0 +1,30 @@
README.md
README.md
lib/Models/ApiResponse.cpp
lib/Models/ApiResponse.h
lib/Models/Category.cpp
lib/Models/Category.h
lib/Models/Helpers.cpp
lib/Models/Helpers.h
lib/Models/Order.cpp
lib/Models/Order.h
lib/Models/Pet.cpp
lib/Models/Pet.h
lib/Models/Tag.cpp
lib/Models/Tag.h
lib/Models/User.cpp
lib/Models/User.h
lib/service/AbstractService.cpp
lib/service/AbstractService.h
lib/service/PetApi.cpp
lib/service/PetApi.h
lib/service/Response.h
lib/service/StoreApi.cpp
lib/service/StoreApi.h
lib/service/UserApi.cpp
lib/service/UserApi.h
platformio.ini
pre_compiling_bourne.py
root.cert
src/main.cpp
test/RunTests.cpp

View File

@@ -0,0 +1 @@
6.0.0-SNAPSHOT

View File

@@ -0,0 +1,73 @@
# Documentation for OpenAPI Petstore
This is a client generator for microcontrollers on the Espressif32 platform and the Arduino framework
After the client have been generated, you have to change these following variablies:
- root.cert | Provide your service root certificate.
- src/main.cpp | Change wifi name
- src/main.cpp | Change wifi password
- lib/service/AbstractService.h | Change to your url
# Documentation for OpenAPI Petstore 1.0.0 Tiny client cpp (Arduino)
The project is structured like this:
```
samples/client/petstore/tiny/cpp/
├── lib
│ ├── Models
│ ├── service
│ └── TestFiles
├── platformio.ini
├── pre_compiling_bourne.py
├── README.md
├── root.cert
├── src
│ └── main.cpp
└── test
└── RunTests.cpp
```
All URIs are relative to http://petstore.swagger.iohttp://petstore.swagger.io/v2
### PetApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*addPet* | *POST* /pet | Add a new pet to the store.|
|*deletePet* | *DELETE* /pet/{petId} | Deletes a pet.|
|*findPetsByStatus* | *GET* /pet/findByStatus | Finds Pets by status.|
|*findPetsByTags* | *GET* /pet/findByTags | Finds Pets by tags.|
|*getPetById* | *GET* /pet/{petId} | Find pet by ID.|
|*updatePet* | *PUT* /pet | Update an existing pet.|
|*updatePetWithForm* | *POST* /pet/{petId} | Updates a pet in the store with form data.|
|*uploadFile* | *POST* /pet/{petId}/uploadImage | uploads an image.|
### StoreApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*deleteOrder* | *DELETE* /store/order/{orderId} | Delete purchase order by ID.|
|*getInventory* | *GET* /store/inventory | Returns pet inventories by status.|
|*getOrderById* | *GET* /store/order/{orderId} | Find purchase order by ID.|
|*placeOrder* | *POST* /store/order | Place an order for a pet.|
### UserApi
|Method | HTTP request | Description|
|------------- | ------------- | -------------|
|*createUser* | *POST* /user | Create user.|
|*createUsersWithArrayInput* | *POST* /user/createWithArray | Creates list of users with given input array.|
|*createUsersWithListInput* | *POST* /user/createWithList | Creates list of users with given input array.|
|*deleteUser* | *DELETE* /user/{username} | Delete user.|
|*getUserByName* | *GET* /user/{username} | Get user by user name.|
|*loginUser* | *GET* /user/login | Logs user into the system.|
|*logoutUser* | *GET* /user/logout | Logs out current logged in user session.|
|*updateUser* | *PUT* /user/{username} | Updated user.|
## What are the Model files for the data structures/objects?
|Class | Description|
|------------- | -------------|
|*ApiResponse* | Describes the result of uploading an image resource|
|*Category* | A category for a pet|
|*Order* | An order for a pets from the pet store|
|*Pet* | A pet for sale in the pet store|
|*Tag* | A tag for a pet|
|*User* | A User who is purchasing from the pet store|

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_ */

View File

@@ -0,0 +1,7 @@
[env:esp32]
platform = espressif32
board = nodemcu-32s
framework = arduino
lib_deps = https://github.com/steinwurf/bourne.git
extra_scripts = pre_compiling_bourne.py

View File

@@ -0,0 +1,25 @@
Import("env")
## Compatibility for bourne to work on microcontrollers
# We insert '#define _GLIBCXX_USE_C99' in files that use std::stoll or std::to_string
def insert_c99_into(file):
import fileinput
path = env['PROJECT_LIBDEPS_DIR'] + "/" + env['PIOENV'] + "/bourne/src/bourne/" + file
value = '#define _GLIBCXX_USE_C99 1\n'
for line in fileinput.FileInput(path,inplace=1):
if line.startswith('#define _GLIBCXX_USE_C99'):
continue
elif line.startswith('// D'):
line=line.replace(line,line+value)
print(line, end='')
def fix_parser():
insert_c99_into('detail/parser.cpp')
def fix_json():
insert_c99_into('json.cpp')
fix_parser()
fix_json()

View File

@@ -0,0 +1,53 @@
// TODO: Provide your service root certificate.
// Below is two examples of root certificates.
// Let's encrypt root certificate
/**
"-----BEGIN CERTIFICATE-----\n" \
"MIIDrzCCApegAwIBAgIQCDvgVpBCRrGhdWrJWZHHSjANBgkqhkiG9w0BAQUFADBh\n" \
"MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3\n" \
"d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD\n" \
"QTAeFw0wNjExMTAwMDAwMDBaFw0zMTExMTAwMDAwMDBaMGExCzAJBgNVBAYTAlVT\n" \
"MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxGTAXBgNVBAsTEHd3dy5kaWdpY2VydC5j\n" \
"b20xIDAeBgNVBAMTF0RpZ2lDZXJ0IEdsb2JhbCBSb290IENBMIIBIjANBgkqhkiG\n" \
"9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4jvhEXLeqKTTo1eqUKKPC3eQyaKl7hLOllsB\n" \
"CSDMAZOnTjC3U/dDxGkAV53ijSLdhwZAAIEJzs4bg7/fzTtxRuLWZscFs3YnFo97\n" \
"nh6Vfe63SKMI2tavegw5BmV/Sl0fvBf4q77uKNd0f3p4mVmFaG5cIzJLv07A6Fpt\n" \
"43C/dxC//AH2hdmoRBBYMql1GNXRor5H4idq9Joz+EkIYIvUX7Q6hL+hqkpMfT7P\n" \
"T19sdl6gSzeRntwi5m3OFBqOasv+zbMUZBfHWymeMr/y7vrTC0LUq7dBMtoM1O/4\n" \
"gdW7jVg/tRvoSSiicNoxBN33shbyTApOB6jtSj1etX+jkMOvJwIDAQABo2MwYTAO\n" \
"BgNVHQ8BAf8EBAMCAYYwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUA95QNVbR\n" \
"TLtm8KPiGxvDl7I90VUwHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUw\n" \
"DQYJKoZIhvcNAQEFBQADggEBAMucN6pIExIK+t1EnE9SsPTfrgT1eXkIoyQY/Esr\n" \
"hMAtudXH/vTBH1jLuG2cenTnmCmrEbXjcKChzUyImZOMkXDiqw8cvpOp/2PV5Adg\n" \
"06O/nVsJ8dWO41P0jmP6P6fbtGbfYmbW0W5BjfIttep3Sp+dWOIrWcBAI+0tKIJF\n" \
"PnlUkiaY4IBIqDfv8NZ5YBberOgOzW6sRBc4L0na4UU+Krk2U886UAb3LujEV0ls\n" \
"YSEY1QSteDwsOoBrp+uvFRTp2InBuThs4pFsiv9kuXclVzDAGySj4dzp30d8tbQk\n" \
"CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=\n" \
"-----END CERTIFICATE-----\n"
*/
// Amazon_Root_CA_1.pem
/**
"-----BEGIN CERTIFICATE-----\n" \
"MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF\n" \
"ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6\n" \
"b24gUm9vdCBDQSAxMB4XDTE1MDUyNjAwMDAwMFoXDTM4MDExNzAwMDAwMFowOTEL\n" \
"MAkGA1UEBhMCVVMxDzANBgNVBAoTBkFtYXpvbjEZMBcGA1UEAxMQQW1hem9uIFJv\n" \
"b3QgQ0EgMTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALJ4gHHKeNXj\n" \
"ca9HgFB0fW7Y14h29Jlo91ghYPl0hAEvrAIthtOgQ3pOsqTQNroBvo3bSMgHFzZM\n" \
"9O6II8c+6zf1tRn4SWiw3te5djgdYZ6k/oI2peVKVuRF4fn9tBb6dNqcmzU5L/qw\n" \
"IFAGbHrQgLKm+a/sRxmPUDgH3KKHOVj4utWp+UhnMJbulHheb4mjUcAwhmahRWa6\n" \
"VOujw5H5SNz/0egwLX0tdHA114gk957EWW67c4cX8jJGKLhD+rcdqsq08p8kDi1L\n" \
"93FcXmn/6pUCyziKrlA4b9v7LWIbxcceVOF34GfID5yHI9Y/QCB/IIDEgEw+OyQm\n" \
"jgSubJrIqg0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMC\n" \
"AYYwHQYDVR0OBBYEFIQYzIU07LwMlJQuCFmcx7IQTgoIMA0GCSqGSIb3DQEBCwUA\n" \
"A4IBAQCY8jdaQZChGsV2USggNiMOruYou6r4lK5IpDB/G/wkjUu0yKGX9rbxenDI\n" \
"U5PMCCjjmCXPI6T53iHTfIUJrU6adTrCC2qJeHZERxhlbI1Bjjt/msv0tadQ1wUs\n" \
"N+gDS63pYaACbvXy8MWy7Vu33PqUXHeeE6V/Uq2V8viTO96LXFvKWlJbYK8U90vv\n" \
"o/ufQJVtMVT8QtPHRh8jrdkPSHCa2XV4cdFyQzR1bldZwgJcJmApzyMZFo6IQ6XU\n" \
"5MsI+yMRQ+hDKXJioaldXgjUkK642M4UwtBV8ob2xJNDd2ZhwLnoQdeXeGADbkpy\n" \
"rqXRfboQnoZsG4q5WTP468SQvvG5\n" \
"-----END CERTIFICATE-----\n" \
*/

View File

@@ -0,0 +1,37 @@
#include "PetApi.h"
const char* ssid = "your wifi name"; // TODO Change wifi name
const char* password = "Your wifi password"; //TODO Change wifi password
void setup(){
//Initialize serial and wait for port to open:
Serial.begin(9600);
delay(100);
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
WiFi.begin(ssid, password);
// attempt to connect to Wifi network:
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
// wait 1 second for re-trying
delay(1000);
}
Serial.print("Connected to ");
Serial.println(ssid);
//Print LAN IP.
Serial.print("IP address set: ");
Serial.println(WiFi.localIP());
Tiny::PetApi petapi;
auto resp = petapi.getPetById(10);
Serial.println(resp.code);
Tiny::Pet pet = resp.obj;
Serial.println(pet.toJson().dump().c_str());
}
void loop(){}

View File

@@ -0,0 +1,204 @@
#include "ApiResponseTest.cpp"
#include "CategoryTest.cpp"
#include "OrderTest.cpp"
#include "PetTest.cpp"
#include "TagTest.cpp"
#include "UserTest.cpp"
void setUp(){}
void tearDown(){}
void runTests(){
RUN_TEST(test_ApiResponse_code_is_assigned_from_json);
RUN_TEST(test_ApiResponse_type_is_assigned_from_json);
RUN_TEST(test_ApiResponse_message_is_assigned_from_json);
RUN_TEST(test_Category_id_is_assigned_from_json);
RUN_TEST(test_Category_name_is_assigned_from_json);
RUN_TEST(test_Order_id_is_assigned_from_json);
RUN_TEST(test_Order_petId_is_assigned_from_json);
RUN_TEST(test_Order_quantity_is_assigned_from_json);
RUN_TEST(test_Order_shipDate_is_assigned_from_json);
RUN_TEST(test_Order_status_is_assigned_from_json);
RUN_TEST(test_Order_complete_is_assigned_from_json);
RUN_TEST(test_Pet_id_is_assigned_from_json);
RUN_TEST(test_Pet_name_is_assigned_from_json);
RUN_TEST(test_Pet_status_is_assigned_from_json);
RUN_TEST(test_Tag_id_is_assigned_from_json);
RUN_TEST(test_Tag_name_is_assigned_from_json);
RUN_TEST(test_User_id_is_assigned_from_json);
RUN_TEST(test_User_username_is_assigned_from_json);
RUN_TEST(test_User_firstName_is_assigned_from_json);
RUN_TEST(test_User_lastName_is_assigned_from_json);
RUN_TEST(test_User_email_is_assigned_from_json);
RUN_TEST(test_User_password_is_assigned_from_json);
RUN_TEST(test_User_phone_is_assigned_from_json);
RUN_TEST(test_User_userStatus_is_assigned_from_json);
RUN_TEST(test_ApiResponse_code_is_converted_to_json);
RUN_TEST(test_ApiResponse_type_is_converted_to_json);
RUN_TEST(test_ApiResponse_message_is_converted_to_json);
RUN_TEST(test_Category_id_is_converted_to_json);
RUN_TEST(test_Category_name_is_converted_to_json);
RUN_TEST(test_Order_id_is_converted_to_json);
RUN_TEST(test_Order_petId_is_converted_to_json);
RUN_TEST(test_Order_quantity_is_converted_to_json);
RUN_TEST(test_Order_shipDate_is_converted_to_json);
RUN_TEST(test_Order_status_is_converted_to_json);
RUN_TEST(test_Order_complete_is_converted_to_json);
RUN_TEST(test_Pet_id_is_converted_to_json);
RUN_TEST(test_Pet_name_is_converted_to_json);
RUN_TEST(test_Pet_status_is_converted_to_json);
RUN_TEST(test_Tag_id_is_converted_to_json);
RUN_TEST(test_Tag_name_is_converted_to_json);
RUN_TEST(test_User_id_is_converted_to_json);
RUN_TEST(test_User_username_is_converted_to_json);
RUN_TEST(test_User_firstName_is_converted_to_json);
RUN_TEST(test_User_lastName_is_converted_to_json);
RUN_TEST(test_User_email_is_converted_to_json);
RUN_TEST(test_User_password_is_converted_to_json);
RUN_TEST(test_User_phone_is_converted_to_json);
RUN_TEST(test_User_userStatus_is_converted_to_json);
}
int main(void) {
UNITY_BEGIN();
runTests();
return UNITY_END();
}
void setup() {
UNITY_BEGIN();
runTests();
UNITY_END();
}
void loop() {
}