/** * 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 #include #include #include 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::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::value>::value> static nlohmann::json itemtoJson(const T& item){ return item; } static nlohmann::json itemtoJson(const ModelBase& item){ return item.toJson(); } public: template static std::vector fromJson(const nlohmann::json& json) { std::vector val; if (!json.empty()) { for (const auto& item : json.items()) { T entry; itemFromJson(entry, item.value()); val.push_back(entry); } } return val; } template static nlohmann::json toJson(const std::vector& val) { nlohmann::json json; for(const auto& item : val){ json.push_back(itemtoJson(item)); } return json; } }; class MapHelper { private: template::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::value>::value> static nlohmann::json itemtoJson(const T& item){ return item; } static nlohmann::json itemtoJson(const ModelBase& item){ return item.toJson(); } public: template static std::map fromJson(const nlohmann::json& json) { std::map val; if (!json.empty()) { for (const auto& item : json.items()) { T entry; itemfromJson(entry, item.value()); val.insert(val.end(), std::pair(item.key(), entry)); } } return val; } template static nlohmann::json toJson(const std::map& val) { nlohmann::json json; for (const auto& item : val) { nlohmann::json jitem = itemtoJson(item.second); json[item.first] = jitem; } return json; } }; } } } } #endif /* ModelBase_H_ */