You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

342 lines
14 KiB

2 years ago
  1. /**
  2. * Seaweedfs Master Server API
  3. * The Seaweedfs Master Server API allows you to store blobs
  4. *
  5. * The version of the OpenAPI document: 3.43.0
  6. *
  7. * NOTE: This class is auto generated by OpenAPI-Generator 6.4.0.
  8. * https://openapi-generator.tech
  9. * Do not edit the class manually.
  10. */
  11. /*
  12. * ModelBase.h
  13. *
  14. * This is the base class for all model classes
  15. */
  16. #ifndef ORG_OPENAPITOOLS_CLIENT_MODEL_ModelBase_H_
  17. #define ORG_OPENAPITOOLS_CLIENT_MODEL_ModelBase_H_
  18. #include "CppRestOpenAPIClient/HttpContent.h"
  19. #include "CppRestOpenAPIClient/MultipartFormData.h"
  20. #include <cpprest/details/basic_types.h>
  21. #include <cpprest/json.h>
  22. #include <map>
  23. #include <vector>
  24. namespace org {
  25. namespace openapitools {
  26. namespace client {
  27. namespace model {
  28. class ModelBase
  29. {
  30. public:
  31. ModelBase();
  32. virtual ~ModelBase();
  33. virtual void validate() = 0;
  34. virtual web::json::value toJson() const = 0;
  35. virtual bool fromJson( const web::json::value& json ) = 0;
  36. virtual void toMultipart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) const = 0;
  37. virtual bool fromMultiPart( std::shared_ptr<MultipartFormData> multipart, const utility::string_t& namePrefix ) = 0;
  38. virtual bool isSet() const;
  39. static utility::string_t toString( const bool val );
  40. static utility::string_t toString( const float val );
  41. static utility::string_t toString( const double val );
  42. static utility::string_t toString( const int32_t val );
  43. static utility::string_t toString( const int64_t val );
  44. static utility::string_t toString( const utility::string_t &val );
  45. static utility::string_t toString( const utility::datetime &val );
  46. static utility::string_t toString( const web::json::value &val );
  47. static utility::string_t toString( const std::shared_ptr<HttpContent>& val );
  48. template <typename T>
  49. static utility::string_t toString( const std::shared_ptr<T>& val );
  50. template <typename T>
  51. static utility::string_t toString( const std::vector<T> & val );
  52. static web::json::value toJson( bool val );
  53. static web::json::value toJson( float val );
  54. static web::json::value toJson( double val );
  55. static web::json::value toJson( int32_t val );
  56. static web::json::value toJson( int64_t val );
  57. static web::json::value toJson( const utility::string_t& val );
  58. static web::json::value toJson( const utility::datetime& val );
  59. static web::json::value toJson( const web::json::value& val );
  60. static web::json::value toJson( const std::shared_ptr<HttpContent>& val );
  61. template<typename T>
  62. static web::json::value toJson( const std::shared_ptr<T>& val );
  63. static web::json::value toJson( const std::shared_ptr<utility::datetime>& val );
  64. template<typename T>
  65. static web::json::value toJson( const std::vector<T>& val );
  66. template<typename T>
  67. static web::json::value toJson( const std::map<utility::string_t, T>& val );
  68. static bool fromString( const utility::string_t& val, bool & );
  69. static bool fromString( const utility::string_t& val, float & );
  70. static bool fromString( const utility::string_t& val, double & );
  71. static bool fromString( const utility::string_t& val, int32_t & );
  72. static bool fromString( const utility::string_t& val, int64_t & );
  73. static bool fromString( const utility::string_t& val, utility::string_t & );
  74. static bool fromString( const utility::string_t& val, utility::datetime & );
  75. static bool fromString( const utility::string_t& val, web::json::value & );
  76. static bool fromString( const utility::string_t& val, std::shared_ptr<HttpContent> & );
  77. template<typename T>
  78. static bool fromString( const utility::string_t& val, std::shared_ptr<T>& );
  79. static bool fromString( const utility::string_t& val, std::shared_ptr<utility::datetime>& outVal );
  80. template<typename T>
  81. static bool fromString( const utility::string_t& val, std::vector<T> & );
  82. template<typename T>
  83. static bool fromString( const utility::string_t& val, std::map<utility::string_t, T> & );
  84. static bool fromJson( const web::json::value& val, bool & );
  85. static bool fromJson( const web::json::value& val, float & );
  86. static bool fromJson( const web::json::value& val, double & );
  87. static bool fromJson( const web::json::value& val, int32_t & );
  88. static bool fromJson( const web::json::value& val, int64_t & );
  89. static bool fromJson( const web::json::value& val, utility::string_t & );
  90. static bool fromJson( const web::json::value& val, utility::datetime & );
  91. static bool fromJson( const web::json::value& val, web::json::value & );
  92. static bool fromJson( const web::json::value& val, std::shared_ptr<HttpContent> & );
  93. template<typename T>
  94. static bool fromJson( const web::json::value& val, std::shared_ptr<T>& );
  95. static bool fromJson( const web::json::value& val, std::shared_ptr<utility::datetime> &outVal );
  96. template<typename T>
  97. static bool fromJson( const web::json::value& val, std::vector<T> & );
  98. template<typename T>
  99. static bool fromJson( const web::json::value& val, std::map<utility::string_t, T> & );
  100. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, bool value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  101. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, float value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  102. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, double value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  103. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int32_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  104. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, int64_t value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  105. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::string_t& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
  106. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const utility::datetime& value, const utility::string_t& contentType = utility::conversions::to_string_t(""));
  107. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const web::json::value& value, const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
  108. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<HttpContent>& );
  109. template <typename T>
  110. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::shared_ptr<T>& , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
  111. static std::shared_ptr<HttpContent> toHttpContent(const utility::string_t& name, const std::shared_ptr<utility::datetime>& value , const utility::string_t& contentType = utility::conversions::to_string_t("application/json") );
  112. template <typename T>
  113. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  114. template <typename T>
  115. static std::shared_ptr<HttpContent> toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType = utility::conversions::to_string_t("") );
  116. static bool fromHttpContent( std::shared_ptr<HttpContent> val, bool & );
  117. static bool fromHttpContent( std::shared_ptr<HttpContent> val, float & );
  118. static bool fromHttpContent( std::shared_ptr<HttpContent> val, double & );
  119. static bool fromHttpContent( std::shared_ptr<HttpContent> val, int64_t & );
  120. static bool fromHttpContent( std::shared_ptr<HttpContent> val, int32_t & );
  121. static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::string_t & );
  122. static bool fromHttpContent( std::shared_ptr<HttpContent> val, utility::datetime & );
  123. static bool fromHttpContent( std::shared_ptr<HttpContent> val, web::json::value & );
  124. static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<HttpContent>& );
  125. template <typename T>
  126. static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& );
  127. template <typename T>
  128. static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & );
  129. template <typename T>
  130. static bool fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & );
  131. static utility::string_t toBase64( utility::string_t value );
  132. static utility::string_t toBase64( std::shared_ptr<std::istream> value );
  133. static std::shared_ptr<std::istream> fromBase64( const utility::string_t& encoded );
  134. protected:
  135. bool m_IsSet;
  136. };
  137. template <typename T>
  138. utility::string_t ModelBase::toString( const std::shared_ptr<T>& val )
  139. {
  140. utility::stringstream_t ss;
  141. if( val != nullptr )
  142. {
  143. val->toJson().serialize(ss);
  144. }
  145. return utility::string_t(ss.str());
  146. }
  147. template<typename T>
  148. utility::string_t ModelBase::toString( const std::vector<T> & val )
  149. {
  150. utility::string_t strArray;
  151. for ( const auto &item : val )
  152. {
  153. strArray.append( toString(item) + "," );
  154. }
  155. if (val.count() > 0)
  156. {
  157. strArray.pop_back();
  158. }
  159. return strArray;
  160. }
  161. template<typename T>
  162. web::json::value ModelBase::toJson( const std::shared_ptr<T>& val )
  163. {
  164. web::json::value retVal;
  165. if(val != nullptr)
  166. {
  167. retVal = val->toJson();
  168. }
  169. return retVal;
  170. }
  171. template<typename T>
  172. web::json::value ModelBase::toJson( const std::vector<T>& value )
  173. {
  174. std::vector<web::json::value> ret;
  175. for ( const auto& x : value )
  176. {
  177. ret.push_back( toJson(x) );
  178. }
  179. return web::json::value::array(ret);
  180. }
  181. template<typename T>
  182. web::json::value ModelBase::toJson( const std::map<utility::string_t, T>& val )
  183. {
  184. web::json::value obj;
  185. for ( const auto &itemkey : val )
  186. {
  187. obj[itemkey.first] = toJson( itemkey.second );
  188. }
  189. return obj;
  190. }
  191. template<typename T>
  192. bool ModelBase::fromString( const utility::string_t& val, std::shared_ptr<T>& outVal )
  193. {
  194. bool ok = false;
  195. if(outVal == nullptr)
  196. {
  197. outVal = std::shared_ptr<T>(new T());
  198. }
  199. if( outVal != nullptr )
  200. {
  201. ok = outVal->fromJson(web::json::value::parse(val));
  202. }
  203. return ok;
  204. }
  205. template<typename T>
  206. bool ModelBase::fromJson( const web::json::value& val, std::shared_ptr<T> &outVal )
  207. {
  208. bool ok = false;
  209. if(outVal == nullptr)
  210. {
  211. outVal = std::shared_ptr<T>(new T());
  212. }
  213. if( outVal != nullptr )
  214. {
  215. ok = outVal->fromJson(val);
  216. }
  217. return ok;
  218. }
  219. template<typename T>
  220. bool ModelBase::fromJson( const web::json::value& val, std::vector<T> &outVal )
  221. {
  222. bool ok = true;
  223. if (val.is_array())
  224. {
  225. for (const auto jitem : val.as_array())
  226. {
  227. T item;
  228. ok &= fromJson(jitem, item);
  229. outVal.push_back(item);
  230. }
  231. }
  232. else
  233. {
  234. ok = false;
  235. }
  236. return ok;
  237. }
  238. template<typename T>
  239. bool ModelBase::fromJson( const web::json::value& jval, std::map<utility::string_t, T> &outVal )
  240. {
  241. bool ok = true;
  242. if ( jval.is_object() )
  243. {
  244. auto obj = jval.as_object();
  245. for( auto objItr = obj.begin() ; objItr != obj.end() ; objItr++ )
  246. {
  247. T itemVal;
  248. ok &= fromJson(objItr->second, itemVal);
  249. outVal.insert(std::pair<utility::string_t, T>(objItr->first, itemVal));
  250. }
  251. }
  252. else
  253. {
  254. ok = false;
  255. }
  256. return ok;
  257. }
  258. template <typename T>
  259. std::shared_ptr<HttpContent> ModelBase::toHttpContent(const utility::string_t& name, const std::shared_ptr<T>& value , const utility::string_t& contentType )
  260. {
  261. std::shared_ptr<HttpContent> content( new HttpContent );
  262. if (value != nullptr )
  263. {
  264. content->setName( name );
  265. content->setContentDisposition( utility::conversions::to_string_t("form-data") );
  266. content->setContentType( contentType );
  267. content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string( value->toJson().serialize() ) ) ) );
  268. }
  269. return content;
  270. }
  271. template <typename T>
  272. std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::vector<T>& value, const utility::string_t& contentType )
  273. {
  274. web::json::value json_array = ModelBase::toJson(value);
  275. std::shared_ptr<HttpContent> content( new HttpContent );
  276. content->setName( name );
  277. content->setContentDisposition( utility::conversions::to_string_t("form-data") );
  278. content->setContentType( contentType );
  279. content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(json_array.serialize()) ) ) );
  280. return content;
  281. }
  282. template <typename T>
  283. std::shared_ptr<HttpContent> ModelBase::toHttpContent( const utility::string_t& name, const std::map<utility::string_t, T>& value, const utility::string_t& contentType )
  284. {
  285. web::json::value jobj = ModelBase::toJson(value);
  286. std::shared_ptr<HttpContent> content( new HttpContent );
  287. content->setName( name );
  288. content->setContentDisposition( utility::conversions::to_string_t("form-data") );
  289. content->setContentType( contentType );
  290. content->setData( std::shared_ptr<std::istream>( new std::stringstream( utility::conversions::to_utf8string(jobj.serialize()) ) ) );
  291. return content;
  292. }
  293. template <typename T>
  294. bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::shared_ptr<T>& outVal )
  295. {
  296. utility::string_t str;
  297. if(val == nullptr) return false;
  298. if( outVal == nullptr )
  299. {
  300. outVal = std::shared_ptr<T>(new T());
  301. }
  302. ModelBase::fromHttpContent(val, str);
  303. return fromString(str, outVal);
  304. }
  305. template <typename T>
  306. bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::vector<T> & )
  307. {
  308. return true;
  309. }
  310. template <typename T>
  311. bool ModelBase::fromHttpContent( std::shared_ptr<HttpContent> val, std::map<utility::string_t, T> & )
  312. {
  313. return true;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. #endif /* ORG_OPENAPITOOLS_CLIENT_MODEL_ModelBase_H_ */