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,397 @@
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
+ module Kleister
12
+ class Configuration
13
+ # Defines url scheme
14
+ attr_accessor :scheme
15
+
16
+ # Defines url host
17
+ attr_accessor :host
18
+
19
+ # Defines url base path
20
+ attr_accessor :base_path
21
+
22
+ # Define server configuration index
23
+ attr_accessor :server_index
24
+
25
+ # Define server operation configuration index
26
+ attr_accessor :server_operation_index
27
+
28
+ # Default server variables
29
+ attr_accessor :server_variables
30
+
31
+ # Default server operation variables
32
+ attr_accessor :server_operation_variables
33
+
34
+ # Defines API keys used with API Key authentications.
35
+ #
36
+ # @return [Hash] key: parameter name, value: parameter value (API key)
37
+ #
38
+ # @example parameter name is "api_key", API key is "xxx" (e.g. "api_key=xxx" in query string)
39
+ # config.api_key['api_key'] = 'xxx'
40
+ attr_accessor :api_key
41
+
42
+ # Defines API key prefixes used with API Key authentications.
43
+ #
44
+ # @return [Hash] key: parameter name, value: API key prefix
45
+ #
46
+ # @example parameter name is "Authorization", API key prefix is "Token" (e.g. "Authorization: Token xxx" in headers)
47
+ # config.api_key_prefix['api_key'] = 'Token'
48
+ attr_accessor :api_key_prefix
49
+
50
+ # Defines the username used with HTTP basic authentication.
51
+ #
52
+ # @return [String]
53
+ attr_accessor :username
54
+
55
+ # Defines the password used with HTTP basic authentication.
56
+ #
57
+ # @return [String]
58
+ attr_accessor :password
59
+
60
+ # Defines the access token (Bearer) used with OAuth2.
61
+ attr_accessor :access_token
62
+
63
+ # Defines a Proc used to fetch or refresh access tokens (Bearer) used with OAuth2.
64
+ # Overrides the access_token if set
65
+ # @return [Proc]
66
+ attr_accessor :access_token_getter
67
+
68
+ # Set this to return data as binary instead of downloading a temp file. When enabled (set to true)
69
+ # HTTP responses with return type `File` will be returned as a stream of binary data.
70
+ # Default to false.
71
+ attr_accessor :return_binary_data
72
+
73
+ # Set this to enable/disable debugging. When enabled (set to true), HTTP request/response
74
+ # details will be logged with `logger.debug` (see the `logger` attribute).
75
+ # Default to false.
76
+ #
77
+ # @return [true, false]
78
+ attr_accessor :debugging
79
+
80
+ # Defines the logger used for debugging.
81
+ # Default to `Rails.logger` (when in Rails) or logging to STDOUT.
82
+ #
83
+ # @return [#debug]
84
+ attr_accessor :logger
85
+
86
+ # Defines the temporary folder to store downloaded files
87
+ # (for API endpoints that have file response).
88
+ # Default to use `Tempfile`.
89
+ #
90
+ # @return [String]
91
+ attr_accessor :temp_folder_path
92
+
93
+ # The time limit for HTTP request in seconds.
94
+ # Default to 0 (never times out).
95
+ attr_accessor :timeout
96
+
97
+ # Set this to false to skip client side validation in the operation.
98
+ # Default to true.
99
+ # @return [true, false]
100
+ attr_accessor :client_side_validation
101
+
102
+ ### TLS/SSL setting
103
+ # Set this to false to skip verifying SSL certificate when calling API from https server.
104
+ # Default to true.
105
+ #
106
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
107
+ #
108
+ # @return [true, false]
109
+ attr_accessor :ssl_verify
110
+
111
+ ### TLS/SSL setting
112
+ # Any `OpenSSL::SSL::` constant (see https://ruby-doc.org/stdlib-2.5.1/libdoc/openssl/rdoc/OpenSSL/SSL.html)
113
+ #
114
+ # @note Do NOT set it to false in production code, otherwise you would face multiple types of cryptographic attacks.
115
+ #
116
+ attr_accessor :ssl_verify_mode
117
+
118
+ ### TLS/SSL setting
119
+ # Set this to customize the certificate file to verify the peer.
120
+ #
121
+ # @return [String] the path to the certificate file
122
+ attr_accessor :ssl_ca_file
123
+
124
+ ### TLS/SSL setting
125
+ # Client certificate file (for client certificate)
126
+ attr_accessor :ssl_client_cert
127
+
128
+ ### TLS/SSL setting
129
+ # Client private key file (for client certificate)
130
+ attr_accessor :ssl_client_key
131
+
132
+ ### Proxy setting
133
+ # HTTP Proxy settings
134
+ attr_accessor :proxy
135
+
136
+ # Set this to customize parameters encoder of array parameter.
137
+ # Default to nil. Faraday uses NestedParamsEncoder when nil.
138
+ #
139
+ # @see The params_encoder option of Faraday. Related source code:
140
+ # https://github.com/lostisland/faraday/tree/main/lib/faraday/encoders
141
+ attr_accessor :params_encoder
142
+
143
+ attr_accessor :inject_format, :force_ending_format
144
+
145
+ def initialize
146
+ @scheme = 'https'
147
+ @host = 'try.kleister.eu'
148
+ @base_path = '/api/v1'
149
+ @server_index = nil
150
+ @server_operation_index = {}
151
+ @server_variables = {}
152
+ @server_operation_variables = {}
153
+ @api_key = {}
154
+ @api_key_prefix = {}
155
+ @client_side_validation = true
156
+ @ssl_verify = true
157
+ @ssl_verify_mode = nil
158
+ @ssl_ca_file = nil
159
+ @ssl_client_cert = nil
160
+ @ssl_client_key = nil
161
+ @middlewares = Hash.new { |h, k| h[k] = [] }
162
+ @configure_connection_blocks = []
163
+ @timeout = 60
164
+ # return data as binary instead of file
165
+ @return_binary_data = false
166
+ @params_encoder = nil
167
+ @debugging = false
168
+ @inject_format = false
169
+ @force_ending_format = false
170
+ @logger = defined?(Rails) ? Rails.logger : Logger.new($stdout)
171
+
172
+ yield(self) if block_given?
173
+ end
174
+
175
+ # The default Configuration object.
176
+ def self.default
177
+ @@default ||= Configuration.new
178
+ end
179
+
180
+ def configure
181
+ yield(self) if block_given?
182
+ end
183
+
184
+ def scheme=(scheme)
185
+ # remove :// from scheme
186
+ @scheme = scheme.sub('://', '')
187
+ end
188
+
189
+ def host=(host)
190
+ # remove http(s):// and anything after a slash
191
+ @host = host.sub(%r{https?://}, '').split('/').first
192
+ end
193
+
194
+ def base_path=(base_path)
195
+ # Add leading and trailing slashes to base_path
196
+ @base_path = "/#{base_path}".gsub(%r{/+}, '/')
197
+ @base_path = '' if @base_path == '/'
198
+ end
199
+
200
+ # Returns base URL for specified operation based on server settings
201
+ def base_url(operation = nil)
202
+ if operation_server_settings.key?(operation)
203
+ index = server_operation_index.fetch(operation, server_index)
204
+ server_url(index.nil? ? 0 : index, server_operation_variables.fetch(operation, server_variables), operation_server_settings[operation])
205
+ else
206
+ server_index.nil? ? "#{scheme}://#{[host, base_path].join('/').gsub(%r{/+}, '/')}".sub(%r{/+\z}, '') : server_url(server_index, server_variables, nil)
207
+ end
208
+ end
209
+
210
+ # Gets API key (with prefix if set).
211
+ # @param [String] param_name the parameter name of API key auth
212
+ def api_key_with_prefix(param_name, param_alias = nil)
213
+ key = @api_key[param_name]
214
+ key = @api_key.fetch(param_alias, key) unless param_alias.nil?
215
+ if @api_key_prefix[param_name]
216
+ "#{@api_key_prefix[param_name]} #{key}"
217
+ else
218
+ key
219
+ end
220
+ end
221
+
222
+ # Gets access_token using access_token_getter or uses the static access_token
223
+ def access_token_with_refresh
224
+ return access_token if access_token_getter.nil?
225
+
226
+ access_token_getter.call
227
+ end
228
+
229
+ # Gets Basic Auth token string
230
+ def basic_auth_token
231
+ 'Basic ' + ["#{username}:#{password}"].pack('m').delete("\r\n")
232
+ end
233
+
234
+ # Returns Auth Settings hash for api client.
235
+ def auth_settings
236
+ {
237
+ 'Header' =>
238
+ {
239
+ type: 'api_key',
240
+ in: 'header',
241
+ key: 'X-API-Key',
242
+ value: api_key_with_prefix('Header')
243
+ },
244
+ 'Bearer' =>
245
+ {
246
+ type: 'bearer',
247
+ in: 'header',
248
+ key: 'Authorization',
249
+ value: "Bearer #{access_token_with_refresh}"
250
+ },
251
+ 'Basic' =>
252
+ {
253
+ type: 'basic',
254
+ in: 'header',
255
+ key: 'Authorization',
256
+ value: basic_auth_token
257
+ },
258
+ 'Cookie' =>
259
+ {
260
+ type: 'api_key',
261
+ in: 'header',
262
+ key: 'Cookie',
263
+ value: api_key_with_prefix('Cookie')
264
+ }
265
+ }
266
+ end
267
+
268
+ # Returns an array of Server setting
269
+ def server_settings
270
+ [
271
+ {
272
+ url: 'https://try.kleister.eu/api/v1',
273
+ description: 'No description provided'
274
+ }
275
+ ]
276
+ end
277
+
278
+ def operation_server_settings
279
+ {}
280
+ end
281
+
282
+ # Returns URL based on server settings
283
+ #
284
+ # @param index array index of the server settings
285
+ # @param variables hash of variable and the corresponding value
286
+ def server_url(index, variables = {}, servers = nil)
287
+ servers = server_settings if servers.nil?
288
+
289
+ # check array index out of bound
290
+ if index.nil? || index.negative? || index >= servers.size
291
+ raise ArgumentError, "Invalid index #{index} when selecting the server. Must not be nil and must be less than #{servers.size}"
292
+ end
293
+
294
+ server = servers[index]
295
+ url = server[:url]
296
+
297
+ return url unless server.key? :variables
298
+
299
+ # go through variable and assign a value
300
+ server[:variables].each_key do |name|
301
+ if variables.key?(name)
302
+ if !server[:variables][name].key?(:enum_values) || server[:variables][name][:enum_values].include?(variables[name])
303
+ url.gsub! '{' + name.to_s + '}', variables[name]
304
+ else
305
+ raise ArgumentError, "The variable `#{name}` in the server URL has invalid value #{variables[name]}. Must be #{server[:variables][name][:enum_values]}."
306
+ end
307
+ else
308
+ # use default value
309
+ url.gsub! '{' + name.to_s + '}', server[:variables][name][:default_value]
310
+ end
311
+ end
312
+
313
+ url
314
+ end
315
+
316
+ # Configure Faraday connection directly.
317
+ #
318
+ # ```
319
+ # c.configure_faraday_connection do |conn|
320
+ # conn.use Faraday::HttpCache, shared_cache: false, logger: logger
321
+ # conn.response :logger, nil, headers: true, bodies: true, log_level: :debug do |logger|
322
+ # logger.filter(/(Authorization: )(.*)/, '\1[REDACTED]')
323
+ # end
324
+ # end
325
+ #
326
+ # c.configure_faraday_connection do |conn|
327
+ # conn.adapter :typhoeus
328
+ # end
329
+ # ```
330
+ #
331
+ # @param block [Proc] `#call`able object that takes one arg, the connection
332
+ def configure_faraday_connection(&block)
333
+ @configure_connection_blocks << block
334
+ end
335
+
336
+ def configure_connection(conn)
337
+ @configure_connection_blocks.each do |block|
338
+ block.call(conn)
339
+ end
340
+ end
341
+
342
+ # Adds middleware to the stack
343
+ def use(*middleware)
344
+ set_faraday_middleware(:use, *middleware)
345
+ end
346
+
347
+ # Adds request middleware to the stack
348
+ def request(*middleware)
349
+ set_faraday_middleware(:request, *middleware)
350
+ end
351
+
352
+ # Adds response middleware to the stack
353
+ def response(*middleware)
354
+ set_faraday_middleware(:response, *middleware)
355
+ end
356
+
357
+ # Adds Faraday middleware setting information to the stack
358
+ #
359
+ # @example Use the `set_faraday_middleware` method to set middleware information
360
+ # config.set_faraday_middleware(:request, :retry, max: 3, methods: [:get, :post], retry_statuses: [503])
361
+ # config.set_faraday_middleware(:response, :logger, nil, { bodies: true, log_level: :debug })
362
+ # config.set_faraday_middleware(:use, Faraday::HttpCache, store: Rails.cache, shared_cache: false)
363
+ # config.set_faraday_middleware(:insert, 0, FaradayMiddleware::FollowRedirects, { standards_compliant: true, limit: 1 })
364
+ # config.set_faraday_middleware(:swap, 0, Faraday::Response::Logger)
365
+ # config.set_faraday_middleware(:delete, Faraday::Multipart::Middleware)
366
+ #
367
+ # @see https://github.com/lostisland/faraday/blob/v2.3.0/lib/faraday/rack_builder.rb#L92-L143
368
+ def set_faraday_middleware(operation, key, *args, &block)
369
+ unless %i[request response use insert insert_before insert_after swap delete].include?(operation)
370
+ raise ArgumentError, "Invalid faraday middleware operation #{operation}. Must be " \
371
+ ':request, :response, :use, :insert, :insert_before, :insert_after, :swap or :delete.'
372
+ end
373
+
374
+ @middlewares[operation] << [key, args, block]
375
+ end
376
+ ruby2_keywords(:set_faraday_middleware) if respond_to?(:ruby2_keywords, true)
377
+
378
+ # Set up middleware on the connection
379
+ def configure_middleware(connection)
380
+ return if @middlewares.empty?
381
+
382
+ %i[request response use insert insert_before insert_after swap].each do |operation|
383
+ next unless @middlewares.key?(operation)
384
+
385
+ @middlewares[operation].each do |key, args, block|
386
+ connection.builder.send(operation, key, *args, &block)
387
+ end
388
+ end
389
+
390
+ if @middlewares.key?(:delete)
391
+ @middlewares[:delete].each do |key, _args, _block|
392
+ connection.builder.delete(key)
393
+ end
394
+ end
395
+ end
396
+ end
397
+ end
@@ -0,0 +1,231 @@
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
+ class AuthLogin
16
+ attr_accessor :username, :password
17
+
18
+ # Attribute mapping from ruby-style variable name to JSON key.
19
+ def self.attribute_map
20
+ {
21
+ username: :username,
22
+ password: :password
23
+ }
24
+ end
25
+
26
+ # Returns all the JSON keys this model knows about
27
+ def self.acceptable_attributes
28
+ attribute_map.values
29
+ end
30
+
31
+ # Attribute type mapping.
32
+ def self.openapi_types
33
+ {
34
+ username: :String,
35
+ password: :String
36
+ }
37
+ end
38
+
39
+ # List of attributes with nullable: true
40
+ def self.openapi_nullable
41
+ Set.new([
42
+ ])
43
+ end
44
+
45
+ # Initializes the object
46
+ # @param [Hash] attributes Model attributes in the form of hash
47
+ def initialize(attributes = {})
48
+ unless attributes.is_a?(Hash)
49
+ raise ArgumentError, 'The input argument (attributes) must be a hash in `Kleister::AuthLogin` initialize method'
50
+ end
51
+
52
+ # check to see if the attribute exists and convert string to symbol for hash key
53
+ attributes = attributes.each_with_object({}) do |(k, v), h|
54
+ unless self.class.attribute_map.key?(k.to_sym)
55
+ raise ArgumentError, "`#{k}` is not a valid attribute in `Kleister::AuthLogin`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
56
+ end
57
+
58
+ h[k.to_sym] = v
59
+ end
60
+
61
+ self.username = if attributes.key?(:username)
62
+ attributes[:username]
63
+ end
64
+
65
+ self.password = if attributes.key?(:password)
66
+ attributes[:password]
67
+ end
68
+ end
69
+
70
+ # Show invalid properties with the reasons. Usually used together with valid?
71
+ # @return Array for valid properties with the reasons
72
+ def list_invalid_properties
73
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
74
+ invalid_properties = []
75
+ if @username.nil?
76
+ invalid_properties.push('invalid value for "username", username cannot be nil.')
77
+ end
78
+
79
+ if @password.nil?
80
+ invalid_properties.push('invalid value for "password", password cannot be nil.')
81
+ end
82
+
83
+ invalid_properties
84
+ end
85
+
86
+ # Check to see if the all the properties in the model are valid
87
+ # @return true if the model is valid
88
+ def valid?
89
+ warn '[DEPRECATED] the `valid?` method is obsolete'
90
+ return false if @username.nil?
91
+ return false if @password.nil?
92
+
93
+ true
94
+ end
95
+
96
+ # Checks equality by comparing each attribute.
97
+ # @param [Object] Object to be compared
98
+ def ==(other)
99
+ return true if equal?(other)
100
+
101
+ self.class == other.class &&
102
+ username == other.username &&
103
+ password == other.password
104
+ end
105
+
106
+ # @see the `==` method
107
+ # @param [Object] Object to be compared
108
+ def eql?(other)
109
+ self == other
110
+ end
111
+
112
+ # Calculates hash code according to all attributes.
113
+ # @return [Integer] Hash code
114
+ def hash
115
+ [username, password].hash
116
+ end
117
+
118
+ # Builds the object from hash
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ # @return [Object] Returns the model itself
121
+ def self.build_from_hash(attributes)
122
+ return nil unless attributes.is_a?(Hash)
123
+
124
+ attributes = attributes.transform_keys(&:to_sym)
125
+ transformed_hash = {}
126
+ openapi_types.each_pair do |key, type|
127
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
128
+ transformed_hash[key.to_s] = nil
129
+ elsif type =~ /\AArray<(.*)>/i
130
+ # check to ensure the input is an array given that the attribute
131
+ # is documented as an array but the input is not
132
+ if attributes[attribute_map[key]].is_a?(Array)
133
+ transformed_hash[key.to_s] = attributes[attribute_map[key]].map { |v| _deserialize(::Regexp.last_match(1), v) }
134
+ end
135
+ elsif !attributes[attribute_map[key]].nil?
136
+ transformed_hash[key.to_s] = _deserialize(type, attributes[attribute_map[key]])
137
+ end
138
+ end
139
+ new(transformed_hash)
140
+ end
141
+
142
+ # Deserializes the data based on type
143
+ # @param string type Data type
144
+ # @param string value Value to be deserialized
145
+ # @return [Object] Deserialized data
146
+ def self._deserialize(type, value)
147
+ case type.to_sym
148
+ when :Time
149
+ Time.parse(value)
150
+ when :Date
151
+ Date.parse(value)
152
+ when :String
153
+ value.to_s
154
+ when :Integer
155
+ value.to_i
156
+ when :Float
157
+ value.to_f
158
+ when :Boolean
159
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
160
+ true
161
+ else
162
+ false
163
+ end
164
+ when :Object
165
+ # generic object (usually a Hash), return directly
166
+ value
167
+ when /\AArray<(?<inner_type>.+)>\z/
168
+ inner_type = Regexp.last_match[:inner_type]
169
+ value.map { |v| _deserialize(inner_type, v) }
170
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
171
+ k_type = Regexp.last_match[:k_type]
172
+ v_type = Regexp.last_match[:v_type]
173
+ {}.tap do |hash|
174
+ value.each do |k, v|
175
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
176
+ end
177
+ end
178
+ else # model
179
+ # models (e.g. Pet) or oneOf
180
+ klass = Kleister.const_get(type)
181
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
182
+ end
183
+ end
184
+
185
+ # Returns the string representation of the object
186
+ # @return [String] String presentation of the object
187
+ def to_s
188
+ to_hash.to_s
189
+ end
190
+
191
+ # to_body is an alias to to_hash (backward compatibility)
192
+ # @return [Hash] Returns the object in the form of hash
193
+ def to_body
194
+ to_hash
195
+ end
196
+
197
+ # Returns the object in the form of hash
198
+ # @return [Hash] Returns the object in the form of hash
199
+ def to_hash
200
+ hash = {}
201
+ self.class.attribute_map.each_pair do |attr, param|
202
+ value = send(attr)
203
+ if value.nil?
204
+ is_nullable = self.class.openapi_nullable.include?(attr)
205
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
206
+ end
207
+
208
+ hash[param] = _to_hash(value)
209
+ end
210
+ hash
211
+ end
212
+
213
+ # Outputs non-array value in the form of hash
214
+ # For object, use to_hash. Otherwise, just return the value
215
+ # @param [Object] value Any valid value
216
+ # @return [Hash] Returns the value in the form of hash
217
+ def _to_hash(value)
218
+ if value.is_a?(Array)
219
+ value.compact.map { |v| _to_hash(v) }
220
+ elsif value.is_a?(Hash)
221
+ {}.tap do |hash|
222
+ value.each { |k, v| hash[k] = _to_hash(v) }
223
+ end
224
+ elsif value.respond_to? :to_hash
225
+ value.to_hash
226
+ else
227
+ value
228
+ end
229
+ end
230
+ end
231
+ end