kleister 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +18 -0
  3. data/CONTRIBUTING.md +121 -0
  4. data/DCO +34 -0
  5. data/LICENSE +202 -0
  6. data/README.md +67 -0
  7. data/lib/kleister/api/auth_api.rb +331 -0
  8. data/lib/kleister/api/fabric_api.rb +367 -0
  9. data/lib/kleister/api/forge_api.rb +367 -0
  10. data/lib/kleister/api/minecraft_api.rb +367 -0
  11. data/lib/kleister/api/mod_api.rb +1603 -0
  12. data/lib/kleister/api/neoforge_api.rb +367 -0
  13. data/lib/kleister/api/pack_api.rb +1603 -0
  14. data/lib/kleister/api/profile_api.rb +198 -0
  15. data/lib/kleister/api/quilt_api.rb +367 -0
  16. data/lib/kleister/api/team_api.rb +1283 -0
  17. data/lib/kleister/api/user_api.rb +1283 -0
  18. data/lib/kleister/api_client.rb +429 -0
  19. data/lib/kleister/api_error.rb +56 -0
  20. data/lib/kleister/configuration.rb +397 -0
  21. data/lib/kleister/models/auth_login.rb +231 -0
  22. data/lib/kleister/models/auth_token.rb +227 -0
  23. data/lib/kleister/models/auth_verify.rb +227 -0
  24. data/lib/kleister/models/build.rb +365 -0
  25. data/lib/kleister/models/build_version.rb +261 -0
  26. data/lib/kleister/models/build_version_params.rb +233 -0
  27. data/lib/kleister/models/build_versions.rb +235 -0
  28. data/lib/kleister/models/builds.rb +227 -0
  29. data/lib/kleister/models/fabric.rb +235 -0
  30. data/lib/kleister/models/fabric_build_params.rb +233 -0
  31. data/lib/kleister/models/fabric_builds.rb +228 -0
  32. data/lib/kleister/models/fabrics.rb +220 -0
  33. data/lib/kleister/models/forge.rb +243 -0
  34. data/lib/kleister/models/forge_build_params.rb +233 -0
  35. data/lib/kleister/models/forge_builds.rb +227 -0
  36. data/lib/kleister/models/forges.rb +220 -0
  37. data/lib/kleister/models/minecraft.rb +243 -0
  38. data/lib/kleister/models/minecraft_build_params.rb +233 -0
  39. data/lib/kleister/models/minecraft_builds.rb +228 -0
  40. data/lib/kleister/models/minecrafts.rb +220 -0
  41. data/lib/kleister/models/mod.rb +350 -0
  42. data/lib/kleister/models/mod_team_params.rb +265 -0
  43. data/lib/kleister/models/mod_teams.rb +227 -0
  44. data/lib/kleister/models/mod_user_params.rb +265 -0
  45. data/lib/kleister/models/mod_users.rb +227 -0
  46. data/lib/kleister/models/mods.rb +220 -0
  47. data/lib/kleister/models/neoforge.rb +243 -0
  48. data/lib/kleister/models/neoforge_build_params.rb +233 -0
  49. data/lib/kleister/models/neoforge_builds.rb +228 -0
  50. data/lib/kleister/models/neoforges.rb +220 -0
  51. data/lib/kleister/models/notification.rb +228 -0
  52. data/lib/kleister/models/pack.rb +334 -0
  53. data/lib/kleister/models/pack_back.rb +289 -0
  54. data/lib/kleister/models/pack_icon.rb +289 -0
  55. data/lib/kleister/models/pack_logo.rb +289 -0
  56. data/lib/kleister/models/pack_team_params.rb +265 -0
  57. data/lib/kleister/models/pack_teams.rb +227 -0
  58. data/lib/kleister/models/pack_user_params.rb +265 -0
  59. data/lib/kleister/models/pack_users.rb +227 -0
  60. data/lib/kleister/models/packs.rb +220 -0
  61. data/lib/kleister/models/profile.rb +313 -0
  62. data/lib/kleister/models/quilt.rb +235 -0
  63. data/lib/kleister/models/quilt_build_params.rb +233 -0
  64. data/lib/kleister/models/quilt_builds.rb +227 -0
  65. data/lib/kleister/models/quilts.rb +220 -0
  66. data/lib/kleister/models/team.rb +267 -0
  67. data/lib/kleister/models/team_mod.rb +304 -0
  68. data/lib/kleister/models/team_mod_params.rb +265 -0
  69. data/lib/kleister/models/team_mods.rb +227 -0
  70. data/lib/kleister/models/team_pack.rb +304 -0
  71. data/lib/kleister/models/team_pack_params.rb +265 -0
  72. data/lib/kleister/models/team_packs.rb +227 -0
  73. data/lib/kleister/models/team_user_params.rb +265 -0
  74. data/lib/kleister/models/team_users.rb +227 -0
  75. data/lib/kleister/models/teams.rb +220 -0
  76. data/lib/kleister/models/user.rb +315 -0
  77. data/lib/kleister/models/user_auth.rb +234 -0
  78. data/lib/kleister/models/user_mod.rb +304 -0
  79. data/lib/kleister/models/user_mod_params.rb +265 -0
  80. data/lib/kleister/models/user_mods.rb +227 -0
  81. data/lib/kleister/models/user_pack.rb +304 -0
  82. data/lib/kleister/models/user_pack_params.rb +265 -0
  83. data/lib/kleister/models/user_packs.rb +227 -0
  84. data/lib/kleister/models/user_team.rb +304 -0
  85. data/lib/kleister/models/user_team_params.rb +265 -0
  86. data/lib/kleister/models/user_teams.rb +227 -0
  87. data/lib/kleister/models/users.rb +220 -0
  88. data/lib/kleister/models/validation.rb +220 -0
  89. data/lib/kleister/models/version.rb +280 -0
  90. data/lib/kleister/models/version_build_params.rb +233 -0
  91. data/lib/kleister/models/version_builds.rb +235 -0
  92. data/lib/kleister/models/version_file.rb +289 -0
  93. data/lib/kleister/models/versions.rb +227 -0
  94. data/lib/kleister/version.rb +13 -0
  95. data/lib/kleister.rb +121 -0
  96. metadata +180 -0
@@ -0,0 +1,365 @@
1
+ # Kleister OpenAPI
2
+ #
3
+ # API definition for Kleister, manage mod packs for Minecraft
4
+ #
5
+ # The version of the OpenAPI document: 1.0.0-alpha1
6
+ # Contact: kleister@webhippie.de
7
+ # Generated by: https://openapi-generator.tech
8
+ # Generator version: 7.6.0
9
+ #
10
+
11
+ require 'date'
12
+ require 'time'
13
+
14
+ module Kleister
15
+ # Model to represent build
16
+ class Build
17
+ attr_accessor :id, :pack_id, :pack, :minecraft_id, :minecraft, :forge_id, :forge, :neoforge_id, :neoforge, :quilt_id, :quilt, :fabric_id, :fabric, :slug, :name, :java, :memory, :public,
18
+ :created_at, :updated_at, :versions
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ id: :id,
24
+ pack_id: :pack_id,
25
+ pack: :pack,
26
+ minecraft_id: :minecraft_id,
27
+ minecraft: :minecraft,
28
+ forge_id: :forge_id,
29
+ forge: :forge,
30
+ neoforge_id: :neoforge_id,
31
+ neoforge: :neoforge,
32
+ quilt_id: :quilt_id,
33
+ quilt: :quilt,
34
+ fabric_id: :fabric_id,
35
+ fabric: :fabric,
36
+ slug: :slug,
37
+ name: :name,
38
+ java: :java,
39
+ memory: :memory,
40
+ public: :public,
41
+ created_at: :created_at,
42
+ updated_at: :updated_at,
43
+ versions: :versions
44
+ }
45
+ end
46
+
47
+ # Returns all the JSON keys this model knows about
48
+ def self.acceptable_attributes
49
+ attribute_map.values
50
+ end
51
+
52
+ # Attribute type mapping.
53
+ def self.openapi_types
54
+ {
55
+ id: :String,
56
+ pack_id: :String,
57
+ pack: :Pack,
58
+ minecraft_id: :String,
59
+ minecraft: :Minecraft,
60
+ forge_id: :String,
61
+ forge: :Forge,
62
+ neoforge_id: :String,
63
+ neoforge: :Neoforge,
64
+ quilt_id: :String,
65
+ quilt: :Quilt,
66
+ fabric_id: :String,
67
+ fabric: :Fabric,
68
+ slug: :String,
69
+ name: :String,
70
+ java: :String,
71
+ memory: :String,
72
+ public: :Boolean,
73
+ created_at: :Time,
74
+ updated_at: :Time,
75
+ versions: :'Array<BuildVersion>'
76
+ }
77
+ end
78
+
79
+ # List of attributes with nullable: true
80
+ def self.openapi_nullable
81
+ Set.new(%i[
82
+ minecraft_id
83
+ forge_id
84
+ neoforge_id
85
+ quilt_id
86
+ fabric_id
87
+ slug
88
+ name
89
+ java
90
+ memory
91
+ public
92
+ versions
93
+ ])
94
+ end
95
+
96
+ # Initializes the object
97
+ # @param [Hash] attributes Model attributes in the form of hash
98
+ def initialize(attributes = {})
99
+ unless attributes.is_a?(Hash)
100
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Kleister::Build` initialize method'
101
+ end
102
+
103
+ # check to see if the attribute exists and convert string to symbol for hash key
104
+ attributes = attributes.each_with_object({}) do |(k, v), h|
105
+ unless self.class.attribute_map.key?(k.to_sym)
106
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Kleister::Build`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
107
+ end
108
+
109
+ h[k.to_sym] = v
110
+ end
111
+
112
+ if attributes.key?(:id)
113
+ self.id = attributes[:id]
114
+ end
115
+
116
+ if attributes.key?(:pack_id)
117
+ self.pack_id = attributes[:pack_id]
118
+ end
119
+
120
+ if attributes.key?(:pack)
121
+ self.pack = attributes[:pack]
122
+ end
123
+
124
+ if attributes.key?(:minecraft_id)
125
+ self.minecraft_id = attributes[:minecraft_id]
126
+ end
127
+
128
+ if attributes.key?(:minecraft)
129
+ self.minecraft = attributes[:minecraft]
130
+ end
131
+
132
+ if attributes.key?(:forge_id)
133
+ self.forge_id = attributes[:forge_id]
134
+ end
135
+
136
+ if attributes.key?(:forge)
137
+ self.forge = attributes[:forge]
138
+ end
139
+
140
+ if attributes.key?(:neoforge_id)
141
+ self.neoforge_id = attributes[:neoforge_id]
142
+ end
143
+
144
+ if attributes.key?(:neoforge)
145
+ self.neoforge = attributes[:neoforge]
146
+ end
147
+
148
+ if attributes.key?(:quilt_id)
149
+ self.quilt_id = attributes[:quilt_id]
150
+ end
151
+
152
+ if attributes.key?(:quilt)
153
+ self.quilt = attributes[:quilt]
154
+ end
155
+
156
+ if attributes.key?(:fabric_id)
157
+ self.fabric_id = attributes[:fabric_id]
158
+ end
159
+
160
+ if attributes.key?(:fabric)
161
+ self.fabric = attributes[:fabric]
162
+ end
163
+
164
+ if attributes.key?(:slug)
165
+ self.slug = attributes[:slug]
166
+ end
167
+
168
+ if attributes.key?(:name)
169
+ self.name = attributes[:name]
170
+ end
171
+
172
+ if attributes.key?(:java)
173
+ self.java = attributes[:java]
174
+ end
175
+
176
+ if attributes.key?(:memory)
177
+ self.memory = attributes[:memory]
178
+ end
179
+
180
+ if attributes.key?(:public)
181
+ self.public = attributes[:public]
182
+ end
183
+
184
+ if attributes.key?(:created_at)
185
+ self.created_at = attributes[:created_at]
186
+ end
187
+
188
+ if attributes.key?(:updated_at)
189
+ self.updated_at = attributes[:updated_at]
190
+ end
191
+
192
+ if attributes.key?(:versions) && (value = attributes[:versions]).is_a?(Array)
193
+ self.versions = value
194
+ end
195
+ end
196
+
197
+ # Show invalid properties with the reasons. Usually used together with valid?
198
+ # @return Array for valid properties with the reasons
199
+ def list_invalid_properties
200
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
201
+ []
202
+ end
203
+
204
+ # Check to see if the all the properties in the model are valid
205
+ # @return true if the model is valid
206
+ def valid?
207
+ warn '[DEPRECATED] the `valid?` method is obsolete'
208
+ true
209
+ end
210
+
211
+ # Checks equality by comparing each attribute.
212
+ # @param [Object] Object to be compared
213
+ def ==(other)
214
+ return true if equal?(other)
215
+
216
+ self.class == other.class &&
217
+ id == other.id &&
218
+ pack_id == other.pack_id &&
219
+ pack == other.pack &&
220
+ minecraft_id == other.minecraft_id &&
221
+ minecraft == other.minecraft &&
222
+ forge_id == other.forge_id &&
223
+ forge == other.forge &&
224
+ neoforge_id == other.neoforge_id &&
225
+ neoforge == other.neoforge &&
226
+ quilt_id == other.quilt_id &&
227
+ quilt == other.quilt &&
228
+ fabric_id == other.fabric_id &&
229
+ fabric == other.fabric &&
230
+ slug == other.slug &&
231
+ name == other.name &&
232
+ java == other.java &&
233
+ memory == other.memory &&
234
+ public == other.public &&
235
+ created_at == other.created_at &&
236
+ updated_at == other.updated_at &&
237
+ versions == other.versions
238
+ end
239
+
240
+ # @see the `==` method
241
+ # @param [Object] Object to be compared
242
+ def eql?(other)
243
+ self == other
244
+ end
245
+
246
+ # Calculates hash code according to all attributes.
247
+ # @return [Integer] Hash code
248
+ def hash
249
+ [id, pack_id, pack, minecraft_id, minecraft, forge_id, forge, neoforge_id, neoforge, quilt_id, quilt, fabric_id, fabric, slug, name, java, memory, public, created_at, updated_at, versions].hash
250
+ end
251
+
252
+ # Builds the object from hash
253
+ # @param [Hash] attributes Model attributes in the form of hash
254
+ # @return [Object] Returns the model itself
255
+ def self.build_from_hash(attributes)
256
+ return nil unless attributes.is_a?(Hash)
257
+
258
+ attributes = attributes.transform_keys(&:to_sym)
259
+ transformed_hash = {}
260
+ openapi_types.each_pair do |key, type|
261
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
262
+ transformed_hash[key.to_s] = nil
263
+ elsif type =~ /\AArray<(.*)>/i
264
+ # check to ensure the input is an array given that the attribute
265
+ # is documented as an array but the input is not
266
+ if attributes[attribute_map[key]].is_a?(Array)
267
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
268
+ end
269
+ elsif !attributes[attribute_map[key]].nil?
270
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
271
+ end
272
+ end
273
+ new(transformed_hash)
274
+ end
275
+
276
+ # Deserializes the data based on type
277
+ # @param string type Data type
278
+ # @param string value Value to be deserialized
279
+ # @return [Object] Deserialized data
280
+ def self._deserialize(type, value)
281
+ case type.to_sym
282
+ when :Time
283
+ Time.parse(value)
284
+ when :Date
285
+ Date.parse(value)
286
+ when :String
287
+ value.to_s
288
+ when :Integer
289
+ value.to_i
290
+ when :Float
291
+ value.to_f
292
+ when :Boolean
293
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
294
+ true
295
+ else
296
+ false
297
+ end
298
+ when :Object
299
+ # generic object (usually a Hash), return directly
300
+ value
301
+ when /\AArray<(?<inner_type>.+)>\z/
302
+ inner_type = Regexp.last_match[:inner_type]
303
+ value.map { |v| _deserialize(inner_type, v) }
304
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
305
+ k_type = Regexp.last_match[:k_type]
306
+ v_type = Regexp.last_match[:v_type]
307
+ {}.tap do |hash|
308
+ value.each do |k, v|
309
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
310
+ end
311
+ end
312
+ else # model
313
+ # models (e.g. Pet) or oneOf
314
+ klass = Kleister.const_get(type)
315
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
316
+ end
317
+ end
318
+
319
+ # Returns the string representation of the object
320
+ # @return [String] String presentation of the object
321
+ def to_s
322
+ to_hash.to_s
323
+ end
324
+
325
+ # to_body is an alias to to_hash (backward compatibility)
326
+ # @return [Hash] Returns the object in the form of hash
327
+ def to_body
328
+ to_hash
329
+ end
330
+
331
+ # Returns the object in the form of hash
332
+ # @return [Hash] Returns the object in the form of hash
333
+ def to_hash
334
+ hash = {}
335
+ self.class.attribute_map.each_pair do |attr, param|
336
+ value = send(attr)
337
+ if value.nil?
338
+ is_nullable = self.class.openapi_nullable.include?(attr)
339
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
340
+ end
341
+
342
+ hash[param] = _to_hash(value)
343
+ end
344
+ hash
345
+ end
346
+
347
+ # Outputs non-array value in the form of hash
348
+ # For object, use to_hash. Otherwise, just return the value
349
+ # @param [Object] value Any valid value
350
+ # @return [Hash] Returns the value in the form of hash
351
+ def _to_hash(value)
352
+ if value.is_a?(Array)
353
+ value.compact.map { |v| _to_hash(v) }
354
+ elsif value.is_a?(Hash)
355
+ {}.tap do |hash|
356
+ value.each { |k, v| hash[k] = _to_hash(v) }
357
+ end
358
+ elsif value.respond_to? :to_hash
359
+ value.to_hash
360
+ else
361
+ value
362
+ end
363
+ end
364
+ end
365
+ end
@@ -0,0 +1,261 @@
1
+ # Kleister OpenAPI
2
+ #
3
+ # API definition for Kleister, manage mod packs for Minecraft
4
+ #
5
+ # The version of the OpenAPI document: 1.0.0-alpha1
6
+ # Contact: kleister@webhippie.de
7
+ # Generated by: https://openapi-generator.tech
8
+ # Generator version: 7.6.0
9
+ #
10
+
11
+ require 'date'
12
+ require 'time'
13
+
14
+ module Kleister
15
+ # Model to represent build version
16
+ class BuildVersion
17
+ attr_accessor :build_id, :build, :version_id, :version, :created_at, :updated_at
18
+
19
+ # Attribute mapping from ruby-style variable name to JSON key.
20
+ def self.attribute_map
21
+ {
22
+ build_id: :build_id,
23
+ build: :build,
24
+ version_id: :version_id,
25
+ version: :version,
26
+ created_at: :created_at,
27
+ updated_at: :updated_at
28
+ }
29
+ end
30
+
31
+ # Returns all the JSON keys this model knows about
32
+ def self.acceptable_attributes
33
+ attribute_map.values
34
+ end
35
+
36
+ # Attribute type mapping.
37
+ def self.openapi_types
38
+ {
39
+ build_id: :String,
40
+ build: :Build,
41
+ version_id: :String,
42
+ version: :Version,
43
+ created_at: :Time,
44
+ updated_at: :Time
45
+ }
46
+ end
47
+
48
+ # List of attributes with nullable: true
49
+ def self.openapi_nullable
50
+ Set.new([
51
+ ])
52
+ end
53
+
54
+ # Initializes the object
55
+ # @param [Hash] attributes Model attributes in the form of hash
56
+ def initialize(attributes = {})
57
+ unless attributes.is_a?(Hash)
58
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Kleister::BuildVersion` initialize method'
59
+ end
60
+
61
+ # check to see if the attribute exists and convert string to symbol for hash key
62
+ attributes = attributes.each_with_object({}) do |(k, v), h|
63
+ unless self.class.attribute_map.key?(k.to_sym)
64
+ raise ArgumentError,
65
+ "`#{k}` is not a valid attribute in `Kleister::BuildVersion`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
66
+ end
67
+
68
+ h[k.to_sym] = v
69
+ end
70
+
71
+ self.build_id = if attributes.key?(:build_id)
72
+ attributes[:build_id]
73
+ end
74
+
75
+ if attributes.key?(:build)
76
+ self.build = attributes[:build]
77
+ end
78
+
79
+ self.version_id = if attributes.key?(:version_id)
80
+ attributes[:version_id]
81
+ end
82
+
83
+ if attributes.key?(:version)
84
+ self.version = attributes[:version]
85
+ end
86
+
87
+ if attributes.key?(:created_at)
88
+ self.created_at = attributes[:created_at]
89
+ end
90
+
91
+ if attributes.key?(:updated_at)
92
+ self.updated_at = attributes[:updated_at]
93
+ end
94
+ end
95
+
96
+ # Show invalid properties with the reasons. Usually used together with valid?
97
+ # @return Array for valid properties with the reasons
98
+ def list_invalid_properties
99
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
100
+ invalid_properties = []
101
+ if @build_id.nil?
102
+ invalid_properties.push('invalid value for "build_id", build_id cannot be nil.')
103
+ end
104
+
105
+ if @version_id.nil?
106
+ invalid_properties.push('invalid value for "version_id", version_id cannot be nil.')
107
+ end
108
+
109
+ invalid_properties
110
+ end
111
+
112
+ # Check to see if the all the properties in the model are valid
113
+ # @return true if the model is valid
114
+ def valid?
115
+ warn '[DEPRECATED] the `valid?` method is obsolete'
116
+ return false if @build_id.nil?
117
+ return false if @version_id.nil?
118
+
119
+ true
120
+ end
121
+
122
+ # Checks equality by comparing each attribute.
123
+ # @param [Object] Object to be compared
124
+ def ==(other)
125
+ return true if equal?(other)
126
+
127
+ self.class == other.class &&
128
+ build_id == other.build_id &&
129
+ build == other.build &&
130
+ version_id == other.version_id &&
131
+ version == other.version &&
132
+ created_at == other.created_at &&
133
+ updated_at == other.updated_at
134
+ end
135
+
136
+ # @see the `==` method
137
+ # @param [Object] Object to be compared
138
+ def eql?(other)
139
+ self == other
140
+ end
141
+
142
+ # Calculates hash code according to all attributes.
143
+ # @return [Integer] Hash code
144
+ def hash
145
+ [build_id, build, version_id, version, created_at, updated_at].hash
146
+ end
147
+
148
+ # Builds the object from hash
149
+ # @param [Hash] attributes Model attributes in the form of hash
150
+ # @return [Object] Returns the model itself
151
+ def self.build_from_hash(attributes)
152
+ return nil unless attributes.is_a?(Hash)
153
+
154
+ attributes = attributes.transform_keys(&:to_sym)
155
+ transformed_hash = {}
156
+ openapi_types.each_pair do |key, type|
157
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
158
+ transformed_hash[key.to_s] = nil
159
+ elsif type =~ /\AArray<(.*)>/i
160
+ # check to ensure the input is an array given that the attribute
161
+ # is documented as an array but the input is not
162
+ if attributes[attribute_map[key]].is_a?(Array)
163
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
164
+ end
165
+ elsif !attributes[attribute_map[key]].nil?
166
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
167
+ end
168
+ end
169
+ new(transformed_hash)
170
+ end
171
+
172
+ # Deserializes the data based on type
173
+ # @param string type Data type
174
+ # @param string value Value to be deserialized
175
+ # @return [Object] Deserialized data
176
+ def self._deserialize(type, value)
177
+ case type.to_sym
178
+ when :Time
179
+ Time.parse(value)
180
+ when :Date
181
+ Date.parse(value)
182
+ when :String
183
+ value.to_s
184
+ when :Integer
185
+ value.to_i
186
+ when :Float
187
+ value.to_f
188
+ when :Boolean
189
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
190
+ true
191
+ else
192
+ false
193
+ end
194
+ when :Object
195
+ # generic object (usually a Hash), return directly
196
+ value
197
+ when /\AArray<(?<inner_type>.+)>\z/
198
+ inner_type = Regexp.last_match[:inner_type]
199
+ value.map { |v| _deserialize(inner_type, v) }
200
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
201
+ k_type = Regexp.last_match[:k_type]
202
+ v_type = Regexp.last_match[:v_type]
203
+ {}.tap do |hash|
204
+ value.each do |k, v|
205
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
206
+ end
207
+ end
208
+ else # model
209
+ # models (e.g. Pet) or oneOf
210
+ klass = Kleister.const_get(type)
211
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
212
+ end
213
+ end
214
+
215
+ # Returns the string representation of the object
216
+ # @return [String] String presentation of the object
217
+ def to_s
218
+ to_hash.to_s
219
+ end
220
+
221
+ # to_body is an alias to to_hash (backward compatibility)
222
+ # @return [Hash] Returns the object in the form of hash
223
+ def to_body
224
+ to_hash
225
+ end
226
+
227
+ # Returns the object in the form of hash
228
+ # @return [Hash] Returns the object in the form of hash
229
+ def to_hash
230
+ hash = {}
231
+ self.class.attribute_map.each_pair do |attr, param|
232
+ value = send(attr)
233
+ if value.nil?
234
+ is_nullable = self.class.openapi_nullable.include?(attr)
235
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
236
+ end
237
+
238
+ hash[param] = _to_hash(value)
239
+ end
240
+ hash
241
+ end
242
+
243
+ # Outputs non-array value in the form of hash
244
+ # For object, use to_hash. Otherwise, just return the value
245
+ # @param [Object] value Any valid value
246
+ # @return [Hash] Returns the value in the form of hash
247
+ def _to_hash(value)
248
+ if value.is_a?(Array)
249
+ value.compact.map { |v| _to_hash(v) }
250
+ elsif value.is_a?(Hash)
251
+ {}.tap do |hash|
252
+ value.each { |k, v| hash[k] = _to_hash(v) }
253
+ end
254
+ elsif value.respond_to? :to_hash
255
+ value.to_hash
256
+ else
257
+ value
258
+ end
259
+ end
260
+ end
261
+ end