forked from loafle/openapi-generator-original
* 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:
parent
cce35d75a4
commit
89eb603c17
@ -81,8 +81,6 @@ public class CppPistacheServerCodegen extends AbstractCppCodegen {
|
|||||||
|
|
||||||
reservedWords = new HashSet<>();
|
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-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.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")) {
|
if (additionalProperties.containsKey("modelNamePrefix")) {
|
||||||
additionalProperties().put("prefix", modelNamePrefix);
|
additionalProperties().put("prefix", modelNamePrefix);
|
||||||
supportingFiles.clear();
|
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-header.mustache", "model", modelNamePrefix + "Helpers.h"));
|
||||||
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
supportingFiles.add(new SupportingFile("helpers-source.mustache", "model", modelNamePrefix + "Helpers.cpp"));
|
||||||
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
supportingFiles.add(new SupportingFile("main-api-server.mustache", "", modelNamePrefix + "main-api-server.cpp"));
|
||||||
|
@ -41,7 +41,7 @@ cd build
|
|||||||
## Libraries required
|
## Libraries required
|
||||||
- [pistache](http://pistache.io/quickstart)
|
- [pistache](http://pistache.io/quickstart)
|
||||||
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
|
- [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
|
## Namespaces
|
||||||
{{{apiPackage}}}
|
{{{apiPackage}}}
|
||||||
|
@ -70,14 +70,7 @@ void {{classname}}::{{operationIdSnakeCase}}_handler(const Pistache::Rest::Reque
|
|||||||
try {
|
try {
|
||||||
{{#hasBodyParam}}
|
{{#hasBodyParam}}
|
||||||
{{#bodyParam}}
|
{{#bodyParam}}
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to({{paramName}});
|
||||||
{{^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}}
|
|
||||||
{{/bodyParam}}
|
{{/bodyParam}}
|
||||||
{{/hasBodyParam}}
|
{{/hasBodyParam}}
|
||||||
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
|
this->{{operationIdSnakeCase}}({{#allParams}}{{paramName}}{{#hasMore}}, {{/hasMore}}{{/allParams}}{{#hasParams}}, {{/hasParams}}response);
|
||||||
|
@ -20,7 +20,6 @@ ExternalProject_Add(NLOHMANN
|
|||||||
|
|
||||||
)
|
)
|
||||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
||||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
|
|
||||||
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
||||||
{{/addExternalLibs}}
|
{{/addExternalLibs}}
|
||||||
|
|
||||||
|
@ -9,10 +9,9 @@
|
|||||||
#define {{classname}}_H_
|
#define {{classname}}_H_
|
||||||
|
|
||||||
{{{defaultInclude}}}
|
{{{defaultInclude}}}
|
||||||
#include "{{prefix}}ModelBase.h"
|
|
||||||
|
|
||||||
{{#imports}}{{{this}}}
|
{{#imports}}{{{this}}}
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
{{#modelNamespaceDeclarations}}
|
{{#modelNamespaceDeclarations}}
|
||||||
namespace {{this}} {
|
namespace {{this}} {
|
||||||
@ -22,19 +21,12 @@ namespace {{this}} {
|
|||||||
/// {{description}}
|
/// {{description}}
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class {{declspec}} {{classname}}
|
class {{declspec}} {{classname}}
|
||||||
: public {{prefix}}ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
{{classname}}();
|
{{classname}}();
|
||||||
virtual ~{{classname}}();
|
virtual ~{{classname}}();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// {{prefix}}ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// {{classname}} members
|
/// {{classname}} members
|
||||||
@ -51,6 +43,8 @@ public:
|
|||||||
{{/required}}
|
{{/required}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const {{classname}}& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, {{classname}}& o);
|
||||||
protected:
|
protected:
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{{dataType}}} m_{{name}};
|
{{{dataType}}} m_{{name}};
|
||||||
|
@ -25,126 +25,26 @@ void {{classname}}::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json {{classname}}::toJson() const
|
void to_json(nlohmann::json& j, const {{classname}}& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
{{#vars}}
|
||||||
{{#vars}}{{#isPrimitiveType}}{{^isListContainer}}{{^required}}if(m_{{name}}IsSet)
|
{{#required}}j["{{baseName}}"] = o.m_{{name}};{{/required}}{{^required}}if(o.{{nameInCamelCase}}IsSet())
|
||||||
{
|
j["{{baseName}}"] = o.m_{{name}};{{/required}}
|
||||||
val["{{baseName}}"] = m_{{name}};
|
{{/vars}}
|
||||||
}
|
|
||||||
{{/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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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}}"));
|
j.at("{{baseName}}").get_to(o.m_{{name}});
|
||||||
}
|
o.m_{{name}}IsSet = true;
|
||||||
{{/required}}{{#required}}{{setter}}(val.at("{{baseName}}"));
|
} {{/required}}
|
||||||
{{/required}}{{/isListContainer}}{{/isPrimitiveType}}{{#isListContainer}}{
|
{{/vars}}
|
||||||
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}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
{{#vars}}{{#isContainer}}{{{dataType}}}& {{classname}}::{{getter}}()
|
{{#vars}}{{#isContainer}}{{{dataType}}}& {{classname}}::{{getter}}()
|
||||||
{
|
{
|
||||||
return m_{{name}};
|
return m_{{name}};
|
||||||
|
@ -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_ */
|
|
@ -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}}
|
|
@ -1 +1 @@
|
|||||||
3.1.2-SNAPSHOT
|
4.0.0-SNAPSHOT
|
@ -19,7 +19,6 @@ ExternalProject_Add(NLOHMANN
|
|||||||
|
|
||||||
)
|
)
|
||||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
include_directories(${EXTERNAL_INSTALL_LOCATION}/include)
|
||||||
include_directories(${EXTERNAL_INSTALL_LOCATION}/include/nlohmann)
|
|
||||||
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
link_directories(${EXTERNAL_INSTALL_LOCATION}/lib)
|
||||||
|
|
||||||
include_directories(model)
|
include_directories(model)
|
||||||
|
@ -41,7 +41,7 @@ cd build
|
|||||||
## Libraries required
|
## Libraries required
|
||||||
- [pistache](http://pistache.io/quickstart)
|
- [pistache](http://pistache.io/quickstart)
|
||||||
- [JSON for Modern C++](https://github.com/nlohmann/json/#integration): Please download the `json.hpp` file and
|
- [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
|
## Namespaces
|
||||||
org.openapitools.server.api
|
org.openapitools.server.api
|
||||||
|
@ -49,14 +49,11 @@ void PetApi::add_pet_handler(const Pistache::Rest::Request &request, Pistache::H
|
|||||||
|
|
||||||
// Getting the body param
|
// Getting the body param
|
||||||
|
|
||||||
Pet pet;
|
Pet body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
|
this->add_pet(body, response);
|
||||||
pet.fromJson(request_body);
|
|
||||||
|
|
||||||
this->add_pet(pet, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
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
|
// Getting the body param
|
||||||
|
|
||||||
Pet pet;
|
Pet body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
|
this->update_pet(body, response);
|
||||||
pet.fromJson(request_body);
|
|
||||||
|
|
||||||
this->update_pet(pet, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
@ -65,8 +65,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
///
|
///
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="pet">Pet object that needs to be added to the store</param>
|
/// <param name="body">Pet object that needs to be added to the store</param>
|
||||||
virtual void add_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void add_pet(const Pet &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Deletes a pet
|
/// Deletes a pet
|
||||||
@ -111,8 +111,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
///
|
///
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="pet">Pet object that needs to be added to the store</param>
|
/// <param name="body">Pet object that needs to be added to the store</param>
|
||||||
virtual void update_pet(const Pet &pet, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void update_pet(const Pet &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates a pet in the store with form data
|
/// Updates a pet in the store with form data
|
||||||
|
@ -82,14 +82,11 @@ void StoreApi::place_order_handler(const Pistache::Rest::Request &request, Pista
|
|||||||
|
|
||||||
// Getting the body param
|
// Getting the body param
|
||||||
|
|
||||||
Order order;
|
Order body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
|
this->place_order(body, response);
|
||||||
order.fromJson(request_body);
|
|
||||||
|
|
||||||
this->place_order(order, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
@ -87,8 +87,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
///
|
///
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="order">order placed for purchasing the pet</param>
|
/// <param name="body">order placed for purchasing the pet</param>
|
||||||
virtual void place_order(const Order &order, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void place_order(const Order &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -49,14 +49,11 @@ void UserApi::create_user_handler(const Pistache::Rest::Request &request, Pistac
|
|||||||
|
|
||||||
// Getting the body param
|
// Getting the body param
|
||||||
|
|
||||||
User user;
|
User body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
|
this->create_user(body, response);
|
||||||
user.fromJson(request_body);
|
|
||||||
|
|
||||||
this->create_user(user, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
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) {
|
void UserApi::create_users_with_array_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
|
||||||
// Getting the body param
|
// Getting the body param
|
||||||
std::vector<User> user;
|
std::vector<User> body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
user = ArrayHelper::fromJson<User>(request_body);
|
this->create_users_with_array_input(body, response);
|
||||||
this->create_users_with_array_input(user, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
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) {
|
void UserApi::create_users_with_list_input_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
|
||||||
|
|
||||||
// Getting the body param
|
// Getting the body param
|
||||||
std::vector<User> user;
|
std::vector<User> body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
user = ArrayHelper::fromJson<User>(request_body);
|
this->create_users_with_list_input(body, response);
|
||||||
this->create_users_with_list_input(user, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
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
|
// Getting the body param
|
||||||
|
|
||||||
User user;
|
User body;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nlohmann::json request_body = nlohmann::json::parse(request.body());
|
nlohmann::json::parse(request.body()).get_to(body);
|
||||||
|
this->update_user(username, body, response);
|
||||||
user.fromJson(request_body);
|
|
||||||
|
|
||||||
this->update_user(username, user, response);
|
|
||||||
} catch (std::runtime_error & e) {
|
} catch (std::runtime_error & e) {
|
||||||
//send a 400 error
|
//send a 400 error
|
||||||
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
response.send(Pistache::Http::Code::Bad_Request, e.what());
|
||||||
|
@ -65,8 +65,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="user">Created user object</param>
|
/// <param name="body">Created user object</param>
|
||||||
virtual void create_user(const User &user, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void create_user(const User &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
@ -74,8 +74,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
///
|
///
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="user">List of user object</param>
|
/// <param name="body">List of user object</param>
|
||||||
virtual void create_users_with_array_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void create_users_with_array_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates list of users with given input array
|
/// Creates list of users with given input array
|
||||||
@ -83,8 +83,8 @@ private:
|
|||||||
/// <remarks>
|
/// <remarks>
|
||||||
///
|
///
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="user">List of user object</param>
|
/// <param name="body">List of user object</param>
|
||||||
virtual void create_users_with_list_input(const std::vector<User> &user, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void create_users_with_list_input(const std::vector<User> &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Delete user
|
/// Delete user
|
||||||
@ -129,8 +129,8 @@ private:
|
|||||||
/// This can only be done by the logged in user.
|
/// This can only be done by the logged in user.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
/// <param name="username">name that need to be deleted</param>
|
/// <param name="username">name that need to be deleted</param>
|
||||||
/// <param name="user">Updated user object</param>
|
/// <param name="body">Updated user object</param>
|
||||||
virtual void update_user(const std::string &username, const User &user, Pistache::Http::ResponseWriter &response) = 0;
|
virtual void update_user(const std::string &username, const User &body, Pistache::Http::ResponseWriter &response) = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ PetApiImpl::PetApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
|||||||
: PetApi(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");
|
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) {
|
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) {
|
void PetApiImpl::get_pet_by_id(const int64_t &petId, Pistache::Http::ResponseWriter &response) {
|
||||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
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");
|
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){
|
void PetApiImpl::update_pet_with_form(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response){
|
||||||
|
@ -45,12 +45,12 @@ public:
|
|||||||
PetApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
PetApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
||||||
~PetApiImpl() {}
|
~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 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_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 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 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 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);
|
void upload_file(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter &response);
|
||||||
|
|
||||||
|
@ -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) {
|
void StoreApiImpl::get_order_by_id(const int64_t &orderId, Pistache::Http::ResponseWriter &response) {
|
||||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
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");
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ public:
|
|||||||
void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response);
|
void delete_order(const std::string &orderId, Pistache::Http::ResponseWriter &response);
|
||||||
void get_inventory(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 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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,13 +23,13 @@ UserApiImpl::UserApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
|
|||||||
: UserApi(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");
|
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");
|
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");
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
}
|
}
|
||||||
void UserApiImpl::delete_user(const std::string &username, Pistache::Http::ResponseWriter &response) {
|
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) {
|
void UserApiImpl::logout_user(Pistache::Http::ResponseWriter &response) {
|
||||||
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
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");
|
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,14 +45,14 @@ public:
|
|||||||
UserApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
UserApiImpl(std::shared_ptr<Pistache::Rest::Router>);
|
||||||
~UserApiImpl() {}
|
~UserApiImpl() {}
|
||||||
|
|
||||||
void create_user(const 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> &user, 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> &user, 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 delete_user(const std::string &username, Pistache::Http::ResponseWriter &response);
|
||||||
void get_user_by_name(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 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 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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -38,45 +38,36 @@ void ApiResponse::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json ApiResponse::toJson() const
|
void to_json(nlohmann::json& j, const ApiResponse& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.codeIsSet())
|
||||||
if(m_CodeIsSet)
|
j["code"] = o.m_Code;
|
||||||
{
|
if(o.typeIsSet())
|
||||||
val["code"] = m_Code;
|
j["type"] = o.m_Type;
|
||||||
}
|
if(o.messageIsSet())
|
||||||
if(m_TypeIsSet)
|
j["message"] = o.m_Message;
|
||||||
{
|
|
||||||
val["type"] = ModelBase::toJson(m_Type);
|
|
||||||
}
|
|
||||||
if(m_MessageIsSet)
|
|
||||||
{
|
|
||||||
val["message"] = ModelBase::toJson(m_Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("code").get_to(o.m_Code);
|
||||||
}
|
o.m_CodeIsSet = true;
|
||||||
if(val.find("type") != val.end())
|
}
|
||||||
|
if(!j.at("type").is_null())
|
||||||
{
|
{
|
||||||
setType(val.at("type"));
|
j.at("type").get_to(o.m_Type);
|
||||||
}
|
o.m_TypeIsSet = true;
|
||||||
if(val.find("message") != val.end())
|
}
|
||||||
|
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
|
int32_t ApiResponse::getCode() const
|
||||||
{
|
{
|
||||||
return m_Code;
|
return m_Code;
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#define ApiResponse_H_
|
#define ApiResponse_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -32,19 +31,12 @@ namespace model {
|
|||||||
/// Describes the result of uploading an image resource
|
/// Describes the result of uploading an image resource
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class ApiResponse
|
class ApiResponse
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ApiResponse();
|
ApiResponse();
|
||||||
virtual ~ApiResponse();
|
virtual ~ApiResponse();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// ApiResponse members
|
/// ApiResponse members
|
||||||
@ -71,6 +63,8 @@ public:
|
|||||||
bool messageIsSet() const;
|
bool messageIsSet() const;
|
||||||
void unsetMessage();
|
void unsetMessage();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const ApiResponse& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, ApiResponse& o);
|
||||||
protected:
|
protected:
|
||||||
int32_t m_Code;
|
int32_t m_Code;
|
||||||
bool m_CodeIsSet;
|
bool m_CodeIsSet;
|
||||||
|
@ -36,37 +36,29 @@ void Category::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Category::toJson() const
|
void to_json(nlohmann::json& j, const Category& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.idIsSet())
|
||||||
if(m_IdIsSet)
|
j["id"] = o.m_Id;
|
||||||
{
|
if(o.nameIsSet())
|
||||||
val["id"] = m_Id;
|
j["name"] = o.m_Name;
|
||||||
}
|
|
||||||
if(m_NameIsSet)
|
|
||||||
{
|
|
||||||
val["name"] = ModelBase::toJson(m_Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("id").get_to(o.m_Id);
|
||||||
}
|
o.m_IdIsSet = true;
|
||||||
if(val.find("name") != val.end())
|
}
|
||||||
|
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
|
int64_t Category::getId() const
|
||||||
{
|
{
|
||||||
return m_Id;
|
return m_Id;
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#define Category_H_
|
#define Category_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -32,19 +31,12 @@ namespace model {
|
|||||||
/// A category for a pet
|
/// A category for a pet
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Category
|
class Category
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Category();
|
Category();
|
||||||
virtual ~Category();
|
virtual ~Category();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// Category members
|
/// Category members
|
||||||
@ -64,6 +56,8 @@ public:
|
|||||||
bool nameIsSet() const;
|
bool nameIsSet() const;
|
||||||
void unsetName();
|
void unsetName();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Category& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Category& o);
|
||||||
protected:
|
protected:
|
||||||
int64_t m_Id;
|
int64_t m_Id;
|
||||||
bool m_IdIsSet;
|
bool m_IdIsSet;
|
||||||
|
@ -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();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -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_ */
|
|
@ -44,70 +44,57 @@ void Order::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Order::toJson() const
|
void to_json(nlohmann::json& j, const Order& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.idIsSet())
|
||||||
if(m_IdIsSet)
|
j["id"] = o.m_Id;
|
||||||
{
|
if(o.petIdIsSet())
|
||||||
val["id"] = m_Id;
|
j["petId"] = o.m_PetId;
|
||||||
}
|
if(o.quantityIsSet())
|
||||||
if(m_PetIdIsSet)
|
j["quantity"] = o.m_Quantity;
|
||||||
{
|
if(o.shipDateIsSet())
|
||||||
val["petId"] = m_PetId;
|
j["shipDate"] = o.m_ShipDate;
|
||||||
}
|
if(o.statusIsSet())
|
||||||
if(m_QuantityIsSet)
|
j["status"] = o.m_Status;
|
||||||
{
|
if(o.completeIsSet())
|
||||||
val["quantity"] = m_Quantity;
|
j["complete"] = o.m_Complete;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("id").get_to(o.m_Id);
|
||||||
}
|
o.m_IdIsSet = true;
|
||||||
if(val.find("petId") != val.end())
|
}
|
||||||
|
if(!j.at("petId").is_null())
|
||||||
{
|
{
|
||||||
setPetId(val.at("petId"));
|
j.at("petId").get_to(o.m_PetId);
|
||||||
}
|
o.m_PetIdIsSet = true;
|
||||||
if(val.find("quantity") != val.end())
|
}
|
||||||
|
if(!j.at("quantity").is_null())
|
||||||
{
|
{
|
||||||
setQuantity(val.at("quantity"));
|
j.at("quantity").get_to(o.m_Quantity);
|
||||||
}
|
o.m_QuantityIsSet = true;
|
||||||
if(val.find("shipDate") != val.end())
|
}
|
||||||
|
if(!j.at("shipDate").is_null())
|
||||||
{
|
{
|
||||||
setShipDate(val.at("shipDate"));
|
j.at("shipDate").get_to(o.m_ShipDate);
|
||||||
|
o.m_ShipDateIsSet = true;
|
||||||
}
|
}
|
||||||
if(val.find("status") != val.end())
|
if(!j.at("status").is_null())
|
||||||
{
|
{
|
||||||
setStatus(val.at("status"));
|
j.at("status").get_to(o.m_Status);
|
||||||
}
|
o.m_StatusIsSet = true;
|
||||||
if(val.find("complete") != val.end())
|
}
|
||||||
|
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
|
int64_t Order::getId() const
|
||||||
{
|
{
|
||||||
return m_Id;
|
return m_Id;
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#define Order_H_
|
#define Order_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -32,19 +31,12 @@ namespace model {
|
|||||||
/// An order for a pets from the pet store
|
/// An order for a pets from the pet store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Order
|
class Order
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Order();
|
Order();
|
||||||
virtual ~Order();
|
virtual ~Order();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// Order members
|
/// Order members
|
||||||
@ -92,6 +84,8 @@ public:
|
|||||||
bool completeIsSet() const;
|
bool completeIsSet() const;
|
||||||
void unsetComplete();
|
void unsetComplete();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Order& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Order& o);
|
||||||
protected:
|
protected:
|
||||||
int64_t m_Id;
|
int64_t m_Id;
|
||||||
bool m_IdIsSet;
|
bool m_IdIsSet;
|
||||||
|
@ -39,103 +39,47 @@ void Pet::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Pet::toJson() const
|
void to_json(nlohmann::json& j, const Pet& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.idIsSet())
|
||||||
if(m_IdIsSet)
|
j["id"] = o.m_Id;
|
||||||
{
|
if(o.categoryIsSet())
|
||||||
val["id"] = m_Id;
|
j["category"] = o.m_Category;
|
||||||
}
|
j["name"] = o.m_Name;
|
||||||
if(m_CategoryIsSet)
|
j["photoUrls"] = o.m_PhotoUrls;
|
||||||
{
|
if(o.tagsIsSet())
|
||||||
val["category"] = ModelBase::toJson(m_Category);
|
j["tags"] = o.m_Tags;
|
||||||
}
|
if(o.statusIsSet())
|
||||||
val["name"] = ModelBase::toJson(m_Name);
|
j["status"] = o.m_Status;
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("id").get_to(o.m_Id);
|
||||||
}
|
o.m_IdIsSet = true;
|
||||||
if(val.find("category") != val.end())
|
}
|
||||||
|
if(!j.at("category").is_null())
|
||||||
{
|
{
|
||||||
if(!val["category"].is_null())
|
j.at("category").get_to(o.m_Category);
|
||||||
{
|
o.m_CategoryIsSet = true;
|
||||||
Category newItem;
|
}
|
||||||
newItem.fromJson(val["category"]);
|
j.at("name").get_to(o.m_Name);
|
||||||
setCategory( newItem );
|
j.at("photoUrls").get_to(o.m_PhotoUrls);
|
||||||
}
|
if(!j.at("tags").is_null())
|
||||||
|
|
||||||
}
|
|
||||||
setName(val.at("name"));
|
|
||||||
{
|
{
|
||||||
m_PhotoUrls.clear();
|
j.at("tags").get_to(o.m_Tags);
|
||||||
for( auto& item : val["photoUrls"] )
|
o.m_TagsIsSet = true;
|
||||||
{
|
}
|
||||||
m_PhotoUrls.push_back(item);
|
if(!j.at("status").is_null())
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
{
|
{
|
||||||
m_Tags.clear();
|
j.at("status").get_to(o.m_Status);
|
||||||
if(val.find("tags") != val.end())
|
o.m_StatusIsSet = true;
|
||||||
{
|
}
|
||||||
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"));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int64_t Pet::getId() const
|
int64_t Pet::getId() const
|
||||||
{
|
{
|
||||||
return m_Id;
|
return m_Id;
|
||||||
|
@ -19,12 +19,11 @@
|
|||||||
#define Pet_H_
|
#define Pet_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include "Tag.h"
|
#include "Tag.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Category.h"
|
#include "Category.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -35,19 +34,12 @@ namespace model {
|
|||||||
/// A pet for sale in the pet store
|
/// A pet for sale in the pet store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Pet
|
class Pet
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Pet();
|
Pet();
|
||||||
virtual ~Pet();
|
virtual ~Pet();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// Pet members
|
/// Pet members
|
||||||
@ -89,6 +81,8 @@ public:
|
|||||||
bool statusIsSet() const;
|
bool statusIsSet() const;
|
||||||
void unsetStatus();
|
void unsetStatus();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Pet& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Pet& o);
|
||||||
protected:
|
protected:
|
||||||
int64_t m_Id;
|
int64_t m_Id;
|
||||||
bool m_IdIsSet;
|
bool m_IdIsSet;
|
||||||
|
@ -36,37 +36,29 @@ void Tag::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json Tag::toJson() const
|
void to_json(nlohmann::json& j, const Tag& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.idIsSet())
|
||||||
if(m_IdIsSet)
|
j["id"] = o.m_Id;
|
||||||
{
|
if(o.nameIsSet())
|
||||||
val["id"] = m_Id;
|
j["name"] = o.m_Name;
|
||||||
}
|
|
||||||
if(m_NameIsSet)
|
|
||||||
{
|
|
||||||
val["name"] = ModelBase::toJson(m_Name);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
return val;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("id").get_to(o.m_Id);
|
||||||
}
|
o.m_IdIsSet = true;
|
||||||
if(val.find("name") != val.end())
|
}
|
||||||
|
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
|
int64_t Tag::getId() const
|
||||||
{
|
{
|
||||||
return m_Id;
|
return m_Id;
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#define Tag_H_
|
#define Tag_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -32,19 +31,12 @@ namespace model {
|
|||||||
/// A tag for a pet
|
/// A tag for a pet
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class Tag
|
class Tag
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Tag();
|
Tag();
|
||||||
virtual ~Tag();
|
virtual ~Tag();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// Tag members
|
/// Tag members
|
||||||
@ -64,6 +56,8 @@ public:
|
|||||||
bool nameIsSet() const;
|
bool nameIsSet() const;
|
||||||
void unsetName();
|
void unsetName();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const Tag& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, Tag& o);
|
||||||
protected:
|
protected:
|
||||||
int64_t m_Id;
|
int64_t m_Id;
|
||||||
bool m_IdIsSet;
|
bool m_IdIsSet;
|
||||||
|
@ -48,85 +48,71 @@ void User::validate()
|
|||||||
// TODO: implement validation
|
// TODO: implement validation
|
||||||
}
|
}
|
||||||
|
|
||||||
nlohmann::json User::toJson() const
|
void to_json(nlohmann::json& j, const User& o)
|
||||||
{
|
{
|
||||||
nlohmann::json val = nlohmann::json::object();
|
j = nlohmann::json();
|
||||||
|
if(o.idIsSet())
|
||||||
if(m_IdIsSet)
|
j["id"] = o.m_Id;
|
||||||
{
|
if(o.usernameIsSet())
|
||||||
val["id"] = m_Id;
|
j["username"] = o.m_Username;
|
||||||
}
|
if(o.firstNameIsSet())
|
||||||
if(m_UsernameIsSet)
|
j["firstName"] = o.m_FirstName;
|
||||||
{
|
if(o.lastNameIsSet())
|
||||||
val["username"] = ModelBase::toJson(m_Username);
|
j["lastName"] = o.m_LastName;
|
||||||
}
|
if(o.emailIsSet())
|
||||||
if(m_FirstNameIsSet)
|
j["email"] = o.m_Email;
|
||||||
{
|
if(o.passwordIsSet())
|
||||||
val["firstName"] = ModelBase::toJson(m_FirstName);
|
j["password"] = o.m_Password;
|
||||||
}
|
if(o.phoneIsSet())
|
||||||
if(m_LastNameIsSet)
|
j["phone"] = o.m_Phone;
|
||||||
{
|
if(o.userStatusIsSet())
|
||||||
val["lastName"] = ModelBase::toJson(m_LastName);
|
j["userStatus"] = o.m_UserStatus;
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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"));
|
j.at("id").get_to(o.m_Id);
|
||||||
}
|
o.m_IdIsSet = true;
|
||||||
if(val.find("username") != val.end())
|
}
|
||||||
|
if(!j.at("username").is_null())
|
||||||
{
|
{
|
||||||
setUsername(val.at("username"));
|
j.at("username").get_to(o.m_Username);
|
||||||
}
|
o.m_UsernameIsSet = true;
|
||||||
if(val.find("firstName") != val.end())
|
}
|
||||||
|
if(!j.at("firstName").is_null())
|
||||||
{
|
{
|
||||||
setFirstName(val.at("firstName"));
|
j.at("firstName").get_to(o.m_FirstName);
|
||||||
}
|
o.m_FirstNameIsSet = true;
|
||||||
if(val.find("lastName") != val.end())
|
}
|
||||||
|
if(!j.at("lastName").is_null())
|
||||||
{
|
{
|
||||||
setLastName(val.at("lastName"));
|
j.at("lastName").get_to(o.m_LastName);
|
||||||
}
|
o.m_LastNameIsSet = true;
|
||||||
if(val.find("email") != val.end())
|
}
|
||||||
|
if(!j.at("email").is_null())
|
||||||
{
|
{
|
||||||
setEmail(val.at("email"));
|
j.at("email").get_to(o.m_Email);
|
||||||
}
|
o.m_EmailIsSet = true;
|
||||||
if(val.find("password") != val.end())
|
}
|
||||||
|
if(!j.at("password").is_null())
|
||||||
{
|
{
|
||||||
setPassword(val.at("password"));
|
j.at("password").get_to(o.m_Password);
|
||||||
}
|
o.m_PasswordIsSet = true;
|
||||||
if(val.find("phone") != val.end())
|
}
|
||||||
|
if(!j.at("phone").is_null())
|
||||||
{
|
{
|
||||||
setPhone(val.at("phone"));
|
j.at("phone").get_to(o.m_Phone);
|
||||||
}
|
o.m_PhoneIsSet = true;
|
||||||
if(val.find("userStatus") != val.end())
|
}
|
||||||
|
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
|
int64_t User::getId() const
|
||||||
{
|
{
|
||||||
return m_Id;
|
return m_Id;
|
||||||
|
@ -19,9 +19,8 @@
|
|||||||
#define User_H_
|
#define User_H_
|
||||||
|
|
||||||
|
|
||||||
#include "ModelBase.h"
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
namespace org {
|
namespace org {
|
||||||
namespace openapitools {
|
namespace openapitools {
|
||||||
@ -32,19 +31,12 @@ namespace model {
|
|||||||
/// A User who is purchasing from the pet store
|
/// A User who is purchasing from the pet store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class User
|
class User
|
||||||
: public ModelBase
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
User();
|
User();
|
||||||
virtual ~User();
|
virtual ~User();
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
void validate();
|
||||||
/// ModelBase overrides
|
|
||||||
|
|
||||||
void validate() override;
|
|
||||||
|
|
||||||
nlohmann::json toJson() const override;
|
|
||||||
void fromJson(const nlohmann::json& json) override;
|
|
||||||
|
|
||||||
/////////////////////////////////////////////
|
/////////////////////////////////////////////
|
||||||
/// User members
|
/// User members
|
||||||
@ -106,6 +98,8 @@ public:
|
|||||||
bool userStatusIsSet() const;
|
bool userStatusIsSet() const;
|
||||||
void unsetUserStatus();
|
void unsetUserStatus();
|
||||||
|
|
||||||
|
friend void to_json(nlohmann::json& j, const User& o);
|
||||||
|
friend void from_json(const nlohmann::json& j, User& o);
|
||||||
protected:
|
protected:
|
||||||
int64_t m_Id;
|
int64_t m_Id;
|
||||||
bool m_IdIsSet;
|
bool m_IdIsSet;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user