[C++][Pistache] Fixed #2643 (#2653)

* Fixed #2643

Refactored to/from json functions to use universal object serialization method.

* Code review found incorrect indenting and I forgot to remove unused mustache files.

* Removed helpers class because it is not needed anymore.

* Removed helpers package from docs.

* Reverted helper class removal.
This commit is contained in:
SalDiAngelus 2019-04-19 08:00:12 -04:00 committed by sunn
parent cce35d75a4
commit 89eb603c17
37 changed files with 266 additions and 932 deletions

View File

@ -81,8 +81,6 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
reservedWords = new HashSet<>();
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "model", modelNamePrefix + "ModelBase.h"));
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
@ -124,8 +122,6 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
if (additionalProperties.containsKey("modelNamePrefix")) {
additionalProperties().put("prefix", modelNamePrefix);
supportingFiles.clear();
supportingFiles.add(new SupportingFile("modelbase-header.mustache", "model", modelNamePrefix + "ModelBase.h"));
supportingFiles.add(new SupportingFile("modelbase-source.mustache", "model", modelNamePrefix + "ModelBase.cpp"));
supportingFiles.add(new SupportingFile("helpers-header.mustache", "model", modelNamePrefix + "Helpers.h"));
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));

View File

@ -41,7 +41,7 @@ cd build
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model folder
put it under the model/nlohmann folder
## Namespaces
{{{apiPackage}}}

View File

@ -70,14 +70,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
try {
{{#hasBodyParam}}
{{#bodyParam}}
nlohmann::json request_body = nlohmann::json::parse(request.body());
{{^isPrimitiveType}}{{^isContainer}}
{{paramName}}.fromJson(request_body);
{{/isContainer}}{{/isPrimitiveType}}{{#isContainer}} {{paramName}} = {{#isListContainer}} {{prefix}}ArrayHelper{{/isListContainer}}{{#isMapContainer}} {{prefix}}MapHelper{{/isMapContainer}}::fromJson<{{items.baseType}}>(request_body);{{/isContainer}}
{{#isPrimitiveType}}
// The conversion is done automatically by the json library
{{paramName}} = request_body;
{{/isPrimitiveType}}
nlohmann::json::parse(request.body()).get_to({{paramName}});
{{/bodyParam}}
{{/hasBodyParam}}
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);

View File

@ -20,7 +20,6 @@ ExternalProject_Add(NLOHMANN
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
{{/addExternalLibs}}

View File

@ -9,10 +9,9 @@
#define {{classname}}_H_
{{{defaultInclude}}}
#include "{{prefix}}ModelBase.h"
{{#imports}}{{{this}}}
{{/imports}}
#include <nlohmann/json.hpp>
{{#modelNamespaceDeclarations}}
namespace {{this}} {
@ -22,19 +21,12 @@ namespace {{this}} {
/// {{description}}
/// </summary>
class {{declspec}} {{classname}}
: public {{prefix}}ModelBase
{
public:
{{classname}}();
virtual ~{{classname}}();
/////////////////////////////////////////////
/// {{prefix}}ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// {{classname}} members
@ -51,6 +43,8 @@ public:
{{/required}}
{{/vars}}
friend void to_json(nlohmann::json& j, const {{classname}}& o);
friend void from_json(const nlohmann::json& j, {{classname}}& o);
protected:
{{#vars}}
{{{dataType}}} m_{{name}};

View File

@ -25,126 +25,26 @@ void {{classname}}::validate()
// TODO: implement validation
}
nlohmann::json {{classname}}::toJson() const
void to_json(nlohmann::json& j, const {{classname}}& o)
{
nlohmann::json val = nlohmann::json::object();
{{#vars}}{{#isPrimitiveType}}{{^isListContainer}}{{^required}}if(m_{{name}}IsSet)
{
val["{{baseName}}"] = m_{{name}};
}
{{/required}}{{#required}}val["{{baseName}}"] = m_{{name}};
{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{#isListContainer}}{
nlohmann::json jsonArray;
for( const auto& item : m_{{name}} )
{
jsonArray.push_back({{prefix}}ModelBase::toJson(item));
}
{{#required}}val["{{baseName}}"] = jsonArray;
{{/required}}{{^required}}
if(jsonArray.size() > 0)
{
val["{{baseName}}"] = jsonArray;
} {{/required}}
}
{{/isListContainer}}{{#isMapContainer}}{
nlohmann::json jsonObj;
for( const auto& item : m_{{name}} )
{ {{^items.isContainer}}
jsonObj[item.first] = {{prefix}}ModelBase::toJson(item.second);{{/items.isContainer}} {{#items.isListContainer}}
jsonObj[item.first] = {{prefix}}ArrayHelper::toJson<{{{items.items.datatype}}}>(item.second);
{{/items.isListContainer}} {{#items.isMapContainer}}
jsonObj[item.first] = {{prefix}}MapHelper::toJson<{{{items.items.datatype}}}>(item.second); {{/items.isMapContainer}}
}
{{#required}}val["{{baseName}}"] = jsonObj; {{/required}}{{^required}}
if(jsonObj.size() > 0)
{
val["{{baseName}}"] = jsonObj;
} {{/required}}
}
{{/isMapContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^required}}if(m_{{name}}IsSet)
{
val["{{baseName}}"] = {{prefix}}ModelBase::toJson(m_{{name}});
}
{{/required}}{{#required}}val["{{baseName}}"] = {{prefix}}ModelBase::toJson(m_{{name}});
{{/required}}{{/isPrimitiveType}}{{/isContainer}}{{/vars}}
return val;
j = nlohmann::json();
{{#vars}}
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet())
j["{{baseName}}"] = o.m_{{name}};{{/required}}
{{/vars}}
}
void {{classname}}::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, {{classname}}& o)
{
{{#vars}}{{#isPrimitiveType}}{{^isListContainer}}{{^required}}if(val.find("{{baseName}}") != val.end())
{{#vars}}
{{#required}}j.at("{{baseName}}").get_to(o.m_{{name}});{{/required}}{{^required}}if(!j.at("{{baseName}}").is_null())
{
{{setter}}(val.at("{{baseName}}"));
}
{{/required}}{{#required}}{{setter}}(val.at("{{baseName}}"));
{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{#isListContainer}}{
m_{{name}}.clear();
{{^required}}if(val.find("{{baseName}}") != val.end())
{
{{/required}}
for( const auto& item : val["{{baseName}}"] )
{
{{#isPrimitiveType}}m_{{name}}.push_back(item);
{{/isPrimitiveType}}{{^isPrimitiveType}}{{#items.isString}}m_{{name}}.push_back(item);
{{/items.isString}}{{^items.isString}}{{#items.isDateTime}}m_{{name}}.push_back(item);
{{/items.isDateTime}}{{^items.isDateTime}}
if(item.is_null())
{
m_{{name}}.push_back( {{{items.datatype}}}() );
}
else
{
{{{items.datatype}}} newItem;
newItem.fromJson(item);
m_{{name}}.push_back( newItem );
}
{{/items.isDateTime}}{{/items.isString}}{{/isPrimitiveType}}
}
{{^required}}
}
{{/required}}
}
{{/isListContainer}}{{#isMapContainer}}{
m_{{name}}.clear();
{{^required}}if(val.find("{{baseName}}") != val.end())
{
{{/required}}
if(val["{{baseName}}"].is_object()) { {{^items.isContainer}}
m_{{name}} = {{prefix}}MapHelper::fromJson<{{{items.datatype}}}>(val["{{baseName}}"]);
{{/items.isContainer}} {{#items.isContainer}}
for( const auto& item : val["{{baseName}}"].items() )
{ {{#items.isMapContainer}}
{{{items.datatype}}} newItem = {{prefix}}MapHelper::fromJson<{{{items.items.datatype}}}>(item.value());
{{/items.isMapContainer}}{{#items.isListContainer}}
{{{items.datatype}}} newItem = {{prefix}}ArrayHelper::fromJson<{{{items.items.datatype}}}>(item.value());
{{/items.isListContainer}}
m_{{name}}.insert(m_{{name}}.end(), std::pair< std::string, {{{items.datatype}}} >(item.key(), newItem));
} {{/items.isContainer}}
}
{{^required}}
}
{{/required}}
}
{{/isMapContainer}}{{^isContainer}}{{^isPrimitiveType}}{{^required}}if(val.find("{{baseName}}") != val.end())
{
{{#isString}}{{setter}}(val.at("{{baseName}}"));{{/isString}}{{#isByteArray}}{{setter}}(val.at("{{baseName}}"));{{/isByteArray}}{{#isBinary}}{{setter}}(val.at("{{baseName}}"));
{{/isBinary}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
{{/isDateTime}}{{^isDateTime}}{{^isByteArray}}{{^isBinary}}if(!val["{{baseName}}"].is_null())
{
{{{dataType}}} newItem;
newItem.fromJson(val["{{baseName}}"]);
{{setter}}( newItem );
}
{{/isBinary}}{{/isByteArray}}{{/isDateTime}}{{/isString}}
}
{{/required}}{{#required}}{{#isString}}{{setter}}(val.at("{{baseName}}"));
{{/isString}}{{^isString}}{{#isDateTime}}{{setter}}(val.at("{{baseName}}"));
{{/isDateTime}}{{/isString}}{{/required}}{{/isPrimitiveType}}{{/isContainer}}{{/vars}}
j.at("{{baseName}}").get_to(o.m_{{name}});
o.m_{{name}}IsSet = true;
} {{/required}}
{{/vars}}
}
{{#vars}}{{#isContainer}}{{{dataType}}}& {{classname}}::{{getter}}()
{
return m_{{name}};

View File

@ -1,127 +0,0 @@
{{>licenseInfo}}
/*
* {{prefix}}ModelBase.h
*
* This is the base class for all model classes
*/
#ifndef {{prefix}}ModelBase_H_
#define {{prefix}}ModelBase_H_
{{{defaultInclude}}}
#include "json.hpp"
#include <ctime>
#include <string>
#include <vector>
#include <map>
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
class {{declspec}} {{prefix}}ModelBase
{
public:
{{prefix}}ModelBase();
virtual ~{{prefix}}ModelBase();
virtual void validate() = 0;
virtual nlohmann::json toJson() const = 0;
virtual void fromJson(const nlohmann::json& json) = 0;
static std::string toJson( std::string const& value );
static std::string toJson( std::time_t const& value );
static int32_t toJson( int32_t const value );
static int64_t toJson( int64_t const value );
static double toJson( double const value );
static bool toJson( bool const value );
static nlohmann::json toJson({{prefix}}ModelBase const& content );
};
class {{prefix}}ArrayHelper {
private:
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static void itemFromJson(T& item, const nlohmann::json& json){
item = json;
}
static void itemFromJson(ModelBase& item, const nlohmann::json& json){
item.fromJson(json);
}
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static nlohmann::json itemtoJson(const T& item){
return item;
}
static nlohmann::json itemtoJson(const ModelBase& item){
return item.toJson();
}
public:
template<typename T>
static std::vector<T> fromJson(const nlohmann::json& json) {
std::vector<T> val;
if (!json.empty()) {
for (const auto& item : json.items()) {
T entry;
itemFromJson(entry, item.value());
val.push_back(entry);
}
}
return val;
}
template<typename T>
static nlohmann::json toJson(const std::vector<T>& val) {
nlohmann::json json;
for(const auto& item : val){
json.push_back(itemtoJson(item));
}
return json;
}
};
class {{prefix}}MapHelper {
private:
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static void itemFromJson(T &item, const nlohmann::json& json){
item = json;
}
static void itemFromJson(ModelBase &item, const nlohmann::json& json){
item.fromJson(json);
}
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static nlohmann::json itemtoJson(const T& item){
return item;
}
static nlohmann::json itemtoJson(const ModelBase& item){
return item.toJson();
}
public:
template<typename T>
static std::map<std::string, T> fromJson(const nlohmann::json& json) {
std::map<std::string, T> val;
if (!json.empty()) {
for (const auto& item : json.items()) {
T entry;
itemfromJson(entry, item.value());
val.insert(val.end(),
std::pair<std::string, T>(item.key(), entry));
}
}
return val;
}
template<typename T>
static nlohmann::json toJson(const std::map<std::string, T>& val) {
nlohmann::json json;
for (const auto& item : val) {
nlohmann::json jitem = itemtoJson(item.second);
json[item.first] = jitem;
}
return json;
}
};
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}
#endif /* {{prefix}}ModelBase_H_ */

View File

@ -1,54 +0,0 @@
{{>licenseInfo}}
#include "{{prefix}}ModelBase.h"
{{#modelNamespaceDeclarations}}
namespace {{this}} {
{{/modelNamespaceDeclarations}}
{{prefix}}ModelBase::{{prefix}}ModelBase()
{
}
{{prefix}}ModelBase::~{{prefix}}ModelBase()
{
}
std::string {{prefix}}ModelBase::toJson( std::string const& value )
{
return value;
}
std::string {{prefix}}ModelBase::toJson( std::time_t const& value )
{
char buf[sizeof "2011-10-08T07:07:09Z"];
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&value));
return buf;
}
int32_t {{prefix}}ModelBase::toJson( int32_t const value )
{
return value;
}
int64_t {{prefix}}ModelBase::toJson( int64_t const value )
{
return value;
}
double {{prefix}}ModelBase::toJson( double const value )
{
return value;
}
bool {{prefix}}ModelBase::toJson( bool const value )
{
return value;
}
nlohmann::json {{prefix}}ModelBase::toJson({{prefix}}ModelBase const& content )
{
return content.toJson();
}
{{#modelNamespaceDeclarations}}
}
{{/modelNamespaceDeclarations}}

View File

@ -1 +1 @@
3.1.2-SNAPSHOT
4.0.0-SNAPSHOT

View File

@ -19,7 +19,6 @@ ExternalProject_Add(NLOHMANN
)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
include_directories(model)

View File

@ -41,7 +41,7 @@ cd build
## Libraries required
- [pistache](http://pistache.io/quickstart)
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
put it under the model folder
put it under the model/nlohmann folder
## Namespaces
org.openapitools.server.api

View File

@ -49,14 +49,11 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
// Getting the body param
Pet pet;
Pet body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
pet.fromJson(request_body);
this->add_pet(pet, response);
nlohmann::json::parse(request.body()).get_to(body);
this->add_pet(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@ -139,14 +136,11 @@ void PetApi::update_pet_handler(const Pistache::Rest::Request &request, Pistache
// Getting the body param
Pet pet;
Pet body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
pet.fromJson(request_body);
this->update_pet(pet, response);
nlohmann::json::parse(request.body()).get_to(body);
this->update_pet(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());

View File

@ -65,8 +65,8 @@ private:
/// <remarks>
///
/// </remarks>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">Pet object that needs to be added to the store</param>
virtual void add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Deletes a pet
@ -111,8 +111,8 @@ private:
/// <remarks>
///
/// </remarks>
/// <param name="pet">Pet object that needs to be added to the store</param>
virtual void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">Pet object that needs to be added to the store</param>
virtual void update_pet(const Pet &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Updates a pet in the store with form data

View File

@ -82,14 +82,11 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
// Getting the body param
Order order;
Order body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
order.fromJson(request_body);
this->place_order(order, response);
nlohmann::json::parse(request.body()).get_to(body);
this->place_order(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());

View File

@ -87,8 +87,8 @@ private:
/// <remarks>
///
/// </remarks>
/// <param name="order">order placed for purchasing the pet</param>
virtual void place_order(const Order &order, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">order placed for purchasing the pet</param>
virtual void place_order(const Order &body, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -49,14 +49,11 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
// Getting the body param
User user;
User body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user.fromJson(request_body);
this->create_user(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_user(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@ -67,12 +64,11 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
std::vector<User> user;
std::vector<User> body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user = ArrayHelper::fromJson<User>(request_body);
this->create_users_with_array_input(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_users_with_array_input(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@ -83,12 +79,11 @@ void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Reques
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the body param
std::vector<User> user;
std::vector<User> body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user = ArrayHelper::fromJson<User>(request_body);
this->create_users_with_list_input(user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->create_users_with_list_input(body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());
@ -168,14 +163,11 @@ void UserApi::update_user_handler(const Pistache::Rest::Request &request, Pistac
// Getting the body param
User user;
User body;
try {
nlohmann::json request_body = nlohmann::json::parse(request.body());
user.fromJson(request_body);
this->update_user(username, user, response);
nlohmann::json::parse(request.body()).get_to(body);
this->update_user(username, body, response);
} catch (std::runtime_error & e) {
//send a 400 error
response.send(Pistache::Http::Code::Bad_Request, e.what());

View File

@ -65,8 +65,8 @@ private:
/// <remarks>
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="user">Created user object</param>
virtual void create_user(const User &user, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">Created user object</param>
virtual void create_user(const User &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
@ -74,8 +74,8 @@ private:
/// <remarks>
///
/// </remarks>
/// <param name="user">List of user object</param>
virtual void create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">List of user object</param>
virtual void create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Creates list of users with given input array
@ -83,8 +83,8 @@ private:
/// <remarks>
///
/// </remarks>
/// <param name="user">List of user object</param>
virtual void create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">List of user object</param>
virtual void create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
/// <summary>
/// Delete user
@ -129,8 +129,8 @@ private:
/// This can only be done by the logged in user.
/// </remarks>
/// <param name="username">name that need to be deleted</param>
/// <param name="user">Updated user object</param>
virtual void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) = 0;
/// <param name="body">Updated user object</param>
virtual void update_user(const std::string &username, const User &body, Pistache::Http::ResponseWriter &response) = 0;
};

View File

@ -23,7 +23,7 @@ PetApiImpl::PetApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
: PetApi(rtr)
{ }
void PetApiImpl::add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
void PetApiImpl::add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void PetApiImpl::delete_pet(const int64_t &petId, const Pistache::Optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response) {
@ -38,7 +38,7 @@ void PetApiImpl::find_pets_by_tags(const Pistache::Optional<std::vector<std::str
void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void PetApiImpl::update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) {
void PetApiImpl::update_pet(const Pet &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){

View File

@ -45,12 +45,12 @@ public:
PetApiImpl(std::shared_ptr<Pistache::Rest::Router>);
~PetApiImpl() {}
void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
void add_pet(const Pet &body, Pistache::Http::ResponseWriter &response);
void delete_pet(const int64_t &petId, const Pistache::Optional<Pistache::Http::Header::Raw> &apiKey, Pistache::Http::ResponseWriter &response);
void find_pets_by_status(const Pistache::Optional<std::vector<std::string>> &status, Pistache::Http::ResponseWriter &response);
void find_pets_by_tags(const Pistache::Optional<std::vector<std::string>> &tags, Pistache::Http::ResponseWriter &response);
void get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response);
void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response);
void update_pet(const Pet &body, Pistache::Http::ResponseWriter &response);
void update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);

View File

@ -32,7 +32,7 @@ void StoreApiImpl::get_inventory(Pistache::Http::ResponseWriter &response) {
void StoreApiImpl::get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void StoreApiImpl::place_order(const Order &order, Pistache::Http::ResponseWriter &response) {
void StoreApiImpl::place_order(const Order &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}

View File

@ -48,7 +48,7 @@ public:
void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response);
void get_inventory(Pistache::Http::ResponseWriter &response);
void get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response);
void place_order(const Order &order, Pistache::Http::ResponseWriter &response);
void place_order(const Order &body, Pistache::Http::ResponseWriter &response);
};

View File

@ -23,13 +23,13 @@ UserApiImpl::UserApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
: UserApi(rtr)
{ }
void UserApiImpl::create_user(const User &user, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::create_user(const User &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) {
@ -44,7 +44,7 @@ void UserApiImpl::login_user(const Pistache::Optional<std::string> &username, co
void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void UserApiImpl::update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) {
void UserApiImpl::update_user(const std::string &username, const User &body, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}

View File

@ -45,14 +45,14 @@ public:
UserApiImpl(std::shared_ptr<Pistache::Rest::Router>);
~UserApiImpl() {}
void create_user(const User &user, Pistache::Http::ResponseWriter &response);
void create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response);
void create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response);
void create_user(const User &body, Pistache::Http::ResponseWriter &response);
void create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response);
void create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response);
void delete_user(const std::string &username, Pistache::Http::ResponseWriter &response);
void get_user_by_name(const std::string &username, Pistache::Http::ResponseWriter &response);
void login_user(const Pistache::Optional<std::string> &username, const Pistache::Optional<std::string> &password, Pistache::Http::ResponseWriter &response);
void logout_user(Pistache::Http::ResponseWriter &response);
void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response);
void update_user(const std::string &username, const User &body, Pistache::Http::ResponseWriter &response);
};

View File

@ -38,45 +38,36 @@ void ApiResponse::validate()
// TODO: implement validation
}
nlohmann::json ApiResponse::toJson() const
void to_json(nlohmann::json& j, const ApiResponse& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_CodeIsSet)
{
val["code"] = m_Code;
}
if(m_TypeIsSet)
{
val["type"] = ModelBase::toJson(m_Type);
}
if(m_MessageIsSet)
{
val["message"] = ModelBase::toJson(m_Message);
}
return val;
j = nlohmann::json();
if(o.codeIsSet())
j["code"] = o.m_Code;
if(o.typeIsSet())
j["type"] = o.m_Type;
if(o.messageIsSet())
j["message"] = o.m_Message;
}
void ApiResponse::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, ApiResponse& o)
{
if(val.find("code") != val.end())
if(!j.at("code").is_null())
{
setCode(val.at("code"));
}
if(val.find("type") != val.end())
j.at("code").get_to(o.m_Code);
o.m_CodeIsSet = true;
}
if(!j.at("type").is_null())
{
setType(val.at("type"));
}
if(val.find("message") != val.end())
j.at("type").get_to(o.m_Type);
o.m_TypeIsSet = true;
}
if(!j.at("message").is_null())
{
setMessage(val.at("message"));
}
j.at("message").get_to(o.m_Message);
o.m_MessageIsSet = true;
}
}
int32_t ApiResponse::getCode() const
{
return m_Code;

View File

@ -19,9 +19,8 @@
#define ApiResponse_H_
#include "ModelBase.h"
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -32,19 +31,12 @@ namespace model {
/// Describes the result of uploading an image resource
/// </summary>
class ApiResponse
: public ModelBase
{
public:
ApiResponse();
virtual ~ApiResponse();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// ApiResponse members
@ -71,6 +63,8 @@ public:
bool messageIsSet() const;
void unsetMessage();
friend void to_json(nlohmann::json& j, const ApiResponse& o);
friend void from_json(const nlohmann::json& j, ApiResponse& o);
protected:
int32_t m_Code;
bool m_CodeIsSet;

View File

@ -36,37 +36,29 @@ void Category::validate()
// TODO: implement validation
}
nlohmann::json Category::toJson() const
void to_json(nlohmann::json& j, const Category& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_NameIsSet)
{
val["name"] = ModelBase::toJson(m_Name);
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.nameIsSet())
j["name"] = o.m_Name;
}
void Category::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, Category& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("name") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("name").is_null())
{
setName(val.at("name"));
}
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
}
}
int64_t Category::getId() const
{
return m_Id;

View File

@ -19,9 +19,8 @@
#define Category_H_
#include "ModelBase.h"
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -32,19 +31,12 @@ namespace model {
/// A category for a pet
/// </summary>
class Category
: public ModelBase
{
public:
Category();
virtual ~Category();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// Category members
@ -64,6 +56,8 @@ public:
bool nameIsSet() const;
void unsetName();
friend void to_json(nlohmann::json& j, const Category& o);
friend void from_json(const nlohmann::json& j, Category& o);
protected:
int64_t m_Id;
bool m_IdIsSet;

View File

@ -1,66 +0,0 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
#include "ModelBase.h"
namespace org {
namespace openapitools {
namespace server {
namespace model {
ModelBase::ModelBase()
{
}
ModelBase::~ModelBase()
{
}
std::string ModelBase::toJson( std::string const& value )
{
return value;
}
std::string ModelBase::toJson( std::time_t const& value )
{
char buf[sizeof "2011-10-08T07:07:09Z"];
strftime(buf, sizeof buf, "%FT%TZ", gmtime(&value));
return buf;
}
int32_t ModelBase::toJson( int32_t const value )
{
return value;
}
int64_t ModelBase::toJson( int64_t const value )
{
return value;
}
double ModelBase::toJson( double const value )
{
return value;
}
bool ModelBase::toJson( bool const value )
{
return value;
}
nlohmann::json ModelBase::toJson(ModelBase const& content )
{
return content.toJson();
}
}
}
}
}

View File

@ -1,139 +0,0 @@
/**
* OpenAPI Petstore
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* OpenAPI spec version: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
/*
* ModelBase.h
*
* This is the base class for all model classes
*/
#ifndef ModelBase_H_
#define ModelBase_H_
#include "json.hpp"
#include <ctime>
#include <string>
#include <vector>
#include <map>
namespace org {
namespace openapitools {
namespace server {
namespace model {
class ModelBase
{
public:
ModelBase();
virtual ~ModelBase();
virtual void validate() = 0;
virtual nlohmann::json toJson() const = 0;
virtual void fromJson(const nlohmann::json& json) = 0;
static std::string toJson( std::string const& value );
static std::string toJson( std::time_t const& value );
static int32_t toJson( int32_t const value );
static int64_t toJson( int64_t const value );
static double toJson( double const value );
static bool toJson( bool const value );
static nlohmann::json toJson(ModelBase const& content );
};
class ArrayHelper {
private:
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static void itemFromJson(T& item, const nlohmann::json& json){
item = json;
}
static void itemFromJson(ModelBase& item, const nlohmann::json& json){
item.fromJson(json);
}
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static nlohmann::json itemtoJson(const T& item){
return item;
}
static nlohmann::json itemtoJson(const ModelBase& item){
return item.toJson();
}
public:
template<typename T>
static std::vector<T> fromJson(const nlohmann::json& json) {
std::vector<T> val;
if (!json.empty()) {
for (const auto& item : json.items()) {
T entry;
itemFromJson(entry, item.value());
val.push_back(entry);
}
}
return val;
}
template<typename T>
static nlohmann::json toJson(const std::vector<T>& val) {
nlohmann::json json;
for(const auto& item : val){
json.push_back(itemtoJson(item));
}
return json;
}
};
class MapHelper {
private:
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static void itemFromJson(T &item, const nlohmann::json& json){
item = json;
}
static void itemFromJson(ModelBase &item, const nlohmann::json& json){
item.fromJson(json);
}
template<typename T, typename std::enable_if<!std::is_base_of<ModelBase, T>::value>::value>
static nlohmann::json itemtoJson(const T& item){
return item;
}
static nlohmann::json itemtoJson(const ModelBase& item){
return item.toJson();
}
public:
template<typename T>
static std::map<std::string, T> fromJson(const nlohmann::json& json) {
std::map<std::string, T> val;
if (!json.empty()) {
for (const auto& item : json.items()) {
T entry;
itemfromJson(entry, item.value());
val.insert(val.end(),
std::pair<std::string, T>(item.key(), entry));
}
}
return val;
}
template<typename T>
static nlohmann::json toJson(const std::map<std::string, T>& val) {
nlohmann::json json;
for (const auto& item : val) {
nlohmann::json jitem = itemtoJson(item.second);
json[item.first] = jitem;
}
return json;
}
};
}
}
}
}
#endif /* ModelBase_H_ */

View File

@ -44,70 +44,57 @@ void Order::validate()
// TODO: implement validation
}
nlohmann::json Order::toJson() const
void to_json(nlohmann::json& j, const Order& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_PetIdIsSet)
{
val["petId"] = m_PetId;
}
if(m_QuantityIsSet)
{
val["quantity"] = m_Quantity;
}
if(m_ShipDateIsSet)
{
val["shipDate"] = ModelBase::toJson(m_ShipDate);
}
if(m_StatusIsSet)
{
val["status"] = ModelBase::toJson(m_Status);
}
if(m_CompleteIsSet)
{
val["complete"] = m_Complete;
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.petIdIsSet())
j["petId"] = o.m_PetId;
if(o.quantityIsSet())
j["quantity"] = o.m_Quantity;
if(o.shipDateIsSet())
j["shipDate"] = o.m_ShipDate;
if(o.statusIsSet())
j["status"] = o.m_Status;
if(o.completeIsSet())
j["complete"] = o.m_Complete;
}
void Order::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, Order& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("petId") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("petId").is_null())
{
setPetId(val.at("petId"));
}
if(val.find("quantity") != val.end())
j.at("petId").get_to(o.m_PetId);
o.m_PetIdIsSet = true;
}
if(!j.at("quantity").is_null())
{
setQuantity(val.at("quantity"));
}
if(val.find("shipDate") != val.end())
j.at("quantity").get_to(o.m_Quantity);
o.m_QuantityIsSet = true;
}
if(!j.at("shipDate").is_null())
{
setShipDate(val.at("shipDate"));
}
if(val.find("status") != val.end())
j.at("shipDate").get_to(o.m_ShipDate);
o.m_ShipDateIsSet = true;
}
if(!j.at("status").is_null())
{
setStatus(val.at("status"));
}
if(val.find("complete") != val.end())
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
}
if(!j.at("complete").is_null())
{
setComplete(val.at("complete"));
}
j.at("complete").get_to(o.m_Complete);
o.m_CompleteIsSet = true;
}
}
int64_t Order::getId() const
{
return m_Id;

View File

@ -19,9 +19,8 @@
#define Order_H_
#include "ModelBase.h"
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -32,19 +31,12 @@ namespace model {
/// An order for a pets from the pet store
/// </summary>
class Order
: public ModelBase
{
public:
Order();
virtual ~Order();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// Order members
@ -92,6 +84,8 @@ public:
bool completeIsSet() const;
void unsetComplete();
friend void to_json(nlohmann::json& j, const Order& o);
friend void from_json(const nlohmann::json& j, Order& o);
protected:
int64_t m_Id;
bool m_IdIsSet;

View File

@ -39,103 +39,47 @@ void Pet::validate()
// TODO: implement validation
}
nlohmann::json Pet::toJson() const
void to_json(nlohmann::json& j, const Pet& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_CategoryIsSet)
{
val["category"] = ModelBase::toJson(m_Category);
}
val["name"] = ModelBase::toJson(m_Name);
{
nlohmann::json jsonArray;
for( auto& item : m_PhotoUrls )
{
jsonArray.push_back(ModelBase::toJson(item));
}
val["photoUrls"] = jsonArray;
}
{
nlohmann::json jsonArray;
for( auto& item : m_Tags )
{
jsonArray.push_back(ModelBase::toJson(item));
}
if(jsonArray.size() > 0)
{
val["tags"] = jsonArray;
}
}
if(m_StatusIsSet)
{
val["status"] = ModelBase::toJson(m_Status);
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.categoryIsSet())
j["category"] = o.m_Category;
j["name"] = o.m_Name;
j["photoUrls"] = o.m_PhotoUrls;
if(o.tagsIsSet())
j["tags"] = o.m_Tags;
if(o.statusIsSet())
j["status"] = o.m_Status;
}
void Pet::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, Pet& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("category") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("category").is_null())
{
if(!val["category"].is_null())
{
Category newItem;
newItem.fromJson(val["category"]);
setCategory( newItem );
}
}
setName(val.at("name"));
j.at("category").get_to(o.m_Category);
o.m_CategoryIsSet = true;
}
j.at("name").get_to(o.m_Name);
j.at("photoUrls").get_to(o.m_PhotoUrls);
if(!j.at("tags").is_null())
{
m_PhotoUrls.clear();
for( auto& item : val["photoUrls"] )
{
m_PhotoUrls.push_back(item);
}
}
j.at("tags").get_to(o.m_Tags);
o.m_TagsIsSet = true;
}
if(!j.at("status").is_null())
{
m_Tags.clear();
if(val.find("tags") != val.end())
{
for( auto& item : val["tags"] )
{
if(item.is_null())
{
m_Tags.push_back( Tag() );
}
else
{
Tag newItem;
newItem.fromJson(item);
m_Tags.push_back( newItem );
}
}
}
}
if(val.find("status") != val.end())
{
setStatus(val.at("status"));
}
j.at("status").get_to(o.m_Status);
o.m_StatusIsSet = true;
}
}
int64_t Pet::getId() const
{
return m_Id;

View File

@ -19,12 +19,11 @@
#define Pet_H_
#include "ModelBase.h"
#include "Tag.h"
#include <string>
#include "Category.h"
#include <vector>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -35,19 +34,12 @@ namespace model {
/// A pet for sale in the pet store
/// </summary>
class Pet
: public ModelBase
{
public:
Pet();
virtual ~Pet();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// Pet members
@ -89,6 +81,8 @@ public:
bool statusIsSet() const;
void unsetStatus();
friend void to_json(nlohmann::json& j, const Pet& o);
friend void from_json(const nlohmann::json& j, Pet& o);
protected:
int64_t m_Id;
bool m_IdIsSet;

View File

@ -36,37 +36,29 @@ void Tag::validate()
// TODO: implement validation
}
nlohmann::json Tag::toJson() const
void to_json(nlohmann::json& j, const Tag& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_NameIsSet)
{
val["name"] = ModelBase::toJson(m_Name);
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.nameIsSet())
j["name"] = o.m_Name;
}
void Tag::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, Tag& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("name") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("name").is_null())
{
setName(val.at("name"));
}
j.at("name").get_to(o.m_Name);
o.m_NameIsSet = true;
}
}
int64_t Tag::getId() const
{
return m_Id;

View File

@ -19,9 +19,8 @@
#define Tag_H_
#include "ModelBase.h"
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -32,19 +31,12 @@ namespace model {
/// A tag for a pet
/// </summary>
class Tag
: public ModelBase
{
public:
Tag();
virtual ~Tag();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// Tag members
@ -64,6 +56,8 @@ public:
bool nameIsSet() const;
void unsetName();
friend void to_json(nlohmann::json& j, const Tag& o);
friend void from_json(const nlohmann::json& j, Tag& o);
protected:
int64_t m_Id;
bool m_IdIsSet;

View File

@ -48,85 +48,71 @@ void User::validate()
// TODO: implement validation
}
nlohmann::json User::toJson() const
void to_json(nlohmann::json& j, const User& o)
{
nlohmann::json val = nlohmann::json::object();
if(m_IdIsSet)
{
val["id"] = m_Id;
}
if(m_UsernameIsSet)
{
val["username"] = ModelBase::toJson(m_Username);
}
if(m_FirstNameIsSet)
{
val["firstName"] = ModelBase::toJson(m_FirstName);
}
if(m_LastNameIsSet)
{
val["lastName"] = ModelBase::toJson(m_LastName);
}
if(m_EmailIsSet)
{
val["email"] = ModelBase::toJson(m_Email);
}
if(m_PasswordIsSet)
{
val["password"] = ModelBase::toJson(m_Password);
}
if(m_PhoneIsSet)
{
val["phone"] = ModelBase::toJson(m_Phone);
}
if(m_UserStatusIsSet)
{
val["userStatus"] = m_UserStatus;
}
return val;
j = nlohmann::json();
if(o.idIsSet())
j["id"] = o.m_Id;
if(o.usernameIsSet())
j["username"] = o.m_Username;
if(o.firstNameIsSet())
j["firstName"] = o.m_FirstName;
if(o.lastNameIsSet())
j["lastName"] = o.m_LastName;
if(o.emailIsSet())
j["email"] = o.m_Email;
if(o.passwordIsSet())
j["password"] = o.m_Password;
if(o.phoneIsSet())
j["phone"] = o.m_Phone;
if(o.userStatusIsSet())
j["userStatus"] = o.m_UserStatus;
}
void User::fromJson(const nlohmann::json& val)
void from_json(const nlohmann::json& j, User& o)
{
if(val.find("id") != val.end())
if(!j.at("id").is_null())
{
setId(val.at("id"));
}
if(val.find("username") != val.end())
j.at("id").get_to(o.m_Id);
o.m_IdIsSet = true;
}
if(!j.at("username").is_null())
{
setUsername(val.at("username"));
}
if(val.find("firstName") != val.end())
j.at("username").get_to(o.m_Username);
o.m_UsernameIsSet = true;
}
if(!j.at("firstName").is_null())
{
setFirstName(val.at("firstName"));
}
if(val.find("lastName") != val.end())
j.at("firstName").get_to(o.m_FirstName);
o.m_FirstNameIsSet = true;
}
if(!j.at("lastName").is_null())
{
setLastName(val.at("lastName"));
}
if(val.find("email") != val.end())
j.at("lastName").get_to(o.m_LastName);
o.m_LastNameIsSet = true;
}
if(!j.at("email").is_null())
{
setEmail(val.at("email"));
}
if(val.find("password") != val.end())
j.at("email").get_to(o.m_Email);
o.m_EmailIsSet = true;
}
if(!j.at("password").is_null())
{
setPassword(val.at("password"));
}
if(val.find("phone") != val.end())
j.at("password").get_to(o.m_Password);
o.m_PasswordIsSet = true;
}
if(!j.at("phone").is_null())
{
setPhone(val.at("phone"));
}
if(val.find("userStatus") != val.end())
j.at("phone").get_to(o.m_Phone);
o.m_PhoneIsSet = true;
}
if(!j.at("userStatus").is_null())
{
setUserStatus(val.at("userStatus"));
}
j.at("userStatus").get_to(o.m_UserStatus);
o.m_UserStatusIsSet = true;
}
}
int64_t User::getId() const
{
return m_Id;

View File

@ -19,9 +19,8 @@
#define User_H_
#include "ModelBase.h"
#include <string>
#include <nlohmann/json.hpp>
namespace org {
namespace openapitools {
@ -32,19 +31,12 @@ namespace model {
/// A User who is purchasing from the pet store
/// </summary>
class User
: public ModelBase
{
public:
User();
virtual ~User();
/////////////////////////////////////////////
/// ModelBase overrides
void validate() override;
nlohmann::json toJson() const override;
void fromJson(const nlohmann::json& json) override;
void validate();
/////////////////////////////////////////////
/// User members
@ -106,6 +98,8 @@ public:
bool userStatusIsSet() const;
void unsetUserStatus();
friend void to_json(nlohmann::json& j, const User& o);
friend void from_json(const nlohmann::json& j, User& o);
protected:
int64_t m_Id;
bool m_IdIsSet;