hatchet-sdk 0.13.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +13 -0
  3. data/lib/hatchet/clients/rest/.openapi-generator/FILES +15 -0
  4. data/lib/hatchet/clients/rest/README.md +26 -6
  5. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/api_token_api.rb +71 -0
  6. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/concurrency_api.rb +71 -0
  7. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/sandbox_provider_api.rb +474 -0
  8. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/tenant_api.rb +71 -0
  9. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/api_token.rb +16 -4
  10. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/create_api_token_request.rb +32 -1
  11. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_role.rb +321 -0
  12. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_role_list.rb +239 -0
  13. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/token_capability.rb +341 -0
  14. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/token_capability_list.rb +239 -0
  15. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_key.rb +1 -0
  16. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_strategy.rb +1 -1
  17. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_totals.rb +320 -0
  18. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_create_sandbox_provider_request.rb +393 -0
  19. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider.rb +486 -0
  20. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_event.rb +374 -0
  21. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_event_kind.rb +46 -0
  22. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_event_list.rb +239 -0
  23. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_kind.rb +44 -0
  24. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_list.rb +231 -0
  25. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_sandbox_provider_status.rb +242 -0
  26. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_update_sandbox_provider_request.rb +329 -0
  27. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest.rb +15 -0
  28. data/lib/hatchet/version.rb +1 -1
  29. data/lib/hatchet/worker/durable_event_listener.rb +7 -7
  30. metadata +17 -2
@@ -0,0 +1,320 @@
1
+ =begin
2
+ #Hatchet API
3
+
4
+ #The Hatchet API
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.14.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module HatchetSdkRest
17
+ # Tenant-wide counts. A run in a chain of strategies holds a slot in each of them, so these are not the sums of the per-strategy counts.
18
+ class V1ConcurrencyTotals
19
+ # Keys with a slot in use or a queued run, across all strategies.
20
+ attr_accessor :key_count
21
+
22
+ # Keys with at least one queued run, across all strategies.
23
+ attr_accessor :queued_key_count
24
+
25
+ # Runs that passed every strategy of their chain, each counted once.
26
+ attr_accessor :running_count
27
+
28
+ # Runs waiting at a strategy. A run waits at one strategy at a time.
29
+ attr_accessor :queued_count
30
+
31
+ # Attribute mapping from ruby-style variable name to JSON key.
32
+ def self.attribute_map
33
+ {
34
+ :'key_count' => :'keyCount',
35
+ :'queued_key_count' => :'queuedKeyCount',
36
+ :'running_count' => :'runningCount',
37
+ :'queued_count' => :'queuedCount'
38
+ }
39
+ end
40
+
41
+ # Returns attribute mapping this model knows about
42
+ def self.acceptable_attribute_map
43
+ attribute_map
44
+ end
45
+
46
+ # Returns all the JSON keys this model knows about
47
+ def self.acceptable_attributes
48
+ acceptable_attribute_map.values
49
+ end
50
+
51
+ # Attribute type mapping.
52
+ def self.openapi_types
53
+ {
54
+ :'key_count' => :'Integer',
55
+ :'queued_key_count' => :'Integer',
56
+ :'running_count' => :'Integer',
57
+ :'queued_count' => :'Integer'
58
+ }
59
+ end
60
+
61
+ # List of attributes with nullable: true
62
+ def self.openapi_nullable
63
+ Set.new([
64
+ ])
65
+ end
66
+
67
+ # Initializes the object
68
+ # @param [Hash] attributes Model attributes in the form of hash
69
+ def initialize(attributes = {})
70
+ if (!attributes.is_a?(Hash))
71
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1ConcurrencyTotals` initialize method"
72
+ end
73
+
74
+ # check to see if the attribute exists and convert string to symbol for hash key
75
+ acceptable_attribute_map = self.class.acceptable_attribute_map
76
+ attributes = attributes.each_with_object({}) { |(k, v), h|
77
+ if (!acceptable_attribute_map.key?(k.to_sym))
78
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1ConcurrencyTotals`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
79
+ end
80
+ h[k.to_sym] = v
81
+ }
82
+
83
+ if attributes.key?(:'key_count')
84
+ self.key_count = attributes[:'key_count']
85
+ else
86
+ self.key_count = nil
87
+ end
88
+
89
+ if attributes.key?(:'queued_key_count')
90
+ self.queued_key_count = attributes[:'queued_key_count']
91
+ else
92
+ self.queued_key_count = nil
93
+ end
94
+
95
+ if attributes.key?(:'running_count')
96
+ self.running_count = attributes[:'running_count']
97
+ else
98
+ self.running_count = nil
99
+ end
100
+
101
+ if attributes.key?(:'queued_count')
102
+ self.queued_count = attributes[:'queued_count']
103
+ else
104
+ self.queued_count = nil
105
+ end
106
+ end
107
+
108
+ # Show invalid properties with the reasons. Usually used together with valid?
109
+ # @return Array for valid properties with the reasons
110
+ def list_invalid_properties
111
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
112
+ invalid_properties = Array.new
113
+ if @key_count.nil?
114
+ invalid_properties.push('invalid value for "key_count", key_count cannot be nil.')
115
+ end
116
+
117
+ if @queued_key_count.nil?
118
+ invalid_properties.push('invalid value for "queued_key_count", queued_key_count cannot be nil.')
119
+ end
120
+
121
+ if @running_count.nil?
122
+ invalid_properties.push('invalid value for "running_count", running_count cannot be nil.')
123
+ end
124
+
125
+ if @queued_count.nil?
126
+ invalid_properties.push('invalid value for "queued_count", queued_count cannot be nil.')
127
+ end
128
+
129
+ invalid_properties
130
+ end
131
+
132
+ # Check to see if the all the properties in the model are valid
133
+ # @return true if the model is valid
134
+ def valid?
135
+ warn '[DEPRECATED] the `valid?` method is obsolete'
136
+ return false if @key_count.nil?
137
+ return false if @queued_key_count.nil?
138
+ return false if @running_count.nil?
139
+ return false if @queued_count.nil?
140
+ true
141
+ end
142
+
143
+ # Custom attribute writer method with validation
144
+ # @param [Object] key_count Value to be assigned
145
+ def key_count=(key_count)
146
+ if key_count.nil?
147
+ fail ArgumentError, 'key_count cannot be nil'
148
+ end
149
+
150
+ @key_count = key_count
151
+ end
152
+
153
+ # Custom attribute writer method with validation
154
+ # @param [Object] queued_key_count Value to be assigned
155
+ def queued_key_count=(queued_key_count)
156
+ if queued_key_count.nil?
157
+ fail ArgumentError, 'queued_key_count cannot be nil'
158
+ end
159
+
160
+ @queued_key_count = queued_key_count
161
+ end
162
+
163
+ # Custom attribute writer method with validation
164
+ # @param [Object] running_count Value to be assigned
165
+ def running_count=(running_count)
166
+ if running_count.nil?
167
+ fail ArgumentError, 'running_count cannot be nil'
168
+ end
169
+
170
+ @running_count = running_count
171
+ end
172
+
173
+ # Custom attribute writer method with validation
174
+ # @param [Object] queued_count Value to be assigned
175
+ def queued_count=(queued_count)
176
+ if queued_count.nil?
177
+ fail ArgumentError, 'queued_count cannot be nil'
178
+ end
179
+
180
+ @queued_count = queued_count
181
+ end
182
+
183
+ # Checks equality by comparing each attribute.
184
+ # @param [Object] Object to be compared
185
+ def ==(o)
186
+ return true if self.equal?(o)
187
+ self.class == o.class &&
188
+ key_count == o.key_count &&
189
+ queued_key_count == o.queued_key_count &&
190
+ running_count == o.running_count &&
191
+ queued_count == o.queued_count
192
+ end
193
+
194
+ # @see the `==` method
195
+ # @param [Object] Object to be compared
196
+ def eql?(o)
197
+ self == o
198
+ end
199
+
200
+ # Calculates hash code according to all attributes.
201
+ # @return [Integer] Hash code
202
+ def hash
203
+ [key_count, queued_key_count, running_count, queued_count].hash
204
+ end
205
+
206
+ # Builds the object from hash
207
+ # @param [Hash] attributes Model attributes in the form of hash
208
+ # @return [Object] Returns the model itself
209
+ def self.build_from_hash(attributes)
210
+ return nil unless attributes.is_a?(Hash)
211
+ attributes = attributes.transform_keys(&:to_sym)
212
+ transformed_hash = {}
213
+ openapi_types.each_pair do |key, type|
214
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
215
+ transformed_hash["#{key}"] = nil
216
+ elsif type =~ /\AArray<(.*)>/i
217
+ # check to ensure the input is an array given that the attribute
218
+ # is documented as an array but the input is not
219
+ if attributes[attribute_map[key]].is_a?(Array)
220
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
221
+ end
222
+ elsif !attributes[attribute_map[key]].nil?
223
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
224
+ end
225
+ end
226
+ new(transformed_hash)
227
+ end
228
+
229
+ # Deserializes the data based on type
230
+ # @param string type Data type
231
+ # @param string value Value to be deserialized
232
+ # @return [Object] Deserialized data
233
+ def self._deserialize(type, value)
234
+ case type.to_sym
235
+ when :Time
236
+ Time.parse(value)
237
+ when :Date
238
+ Date.parse(value)
239
+ when :String
240
+ value.to_s
241
+ when :Integer
242
+ value.to_i
243
+ when :Float
244
+ value.to_f
245
+ when :Boolean
246
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
247
+ true
248
+ else
249
+ false
250
+ end
251
+ when :Object
252
+ # generic object (usually a Hash), return directly
253
+ value
254
+ when /\AArray<(?<inner_type>.+)>\z/
255
+ inner_type = Regexp.last_match[:inner_type]
256
+ value.map { |v| _deserialize(inner_type, v) }
257
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
258
+ k_type = Regexp.last_match[:k_type]
259
+ v_type = Regexp.last_match[:v_type]
260
+ {}.tap do |hash|
261
+ value.each do |k, v|
262
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
263
+ end
264
+ end
265
+ else # model
266
+ # models (e.g. Pet) or oneOf
267
+ klass = HatchetSdkRest.const_get(type)
268
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
269
+ end
270
+ end
271
+
272
+ # Returns the string representation of the object
273
+ # @return [String] String presentation of the object
274
+ def to_s
275
+ to_hash.to_s
276
+ end
277
+
278
+ # to_body is an alias to to_hash (backward compatibility)
279
+ # @return [Hash] Returns the object in the form of hash
280
+ def to_body
281
+ to_hash
282
+ end
283
+
284
+ # Returns the object in the form of hash
285
+ # @return [Hash] Returns the object in the form of hash
286
+ def to_hash
287
+ hash = {}
288
+ self.class.attribute_map.each_pair do |attr, param|
289
+ value = self.send(attr)
290
+ if value.nil?
291
+ is_nullable = self.class.openapi_nullable.include?(attr)
292
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
293
+ end
294
+
295
+ hash[param] = _to_hash(value)
296
+ end
297
+ hash
298
+ end
299
+
300
+ # Outputs non-array value in the form of hash
301
+ # For object, use to_hash. Otherwise, just return the value
302
+ # @param [Object] value Any valid value
303
+ # @return [Hash] Returns the value in the form of hash
304
+ def _to_hash(value)
305
+ if value.is_a?(Array)
306
+ value.compact.map { |v| _to_hash(v) }
307
+ elsif value.is_a?(Hash)
308
+ {}.tap do |hash|
309
+ value.each { |k, v| hash[k] = _to_hash(v) }
310
+ end
311
+ elsif value.respond_to? :to_hash
312
+ value.to_hash
313
+ else
314
+ value
315
+ end
316
+ end
317
+
318
+ end
319
+
320
+ end
@@ -0,0 +1,393 @@
1
+ =begin
2
+ #Hatchet API
3
+
4
+ #The Hatchet API
5
+
6
+ The version of the OpenAPI document: 1.0.0
7
+
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.14.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module HatchetSdkRest
17
+ class V1CreateSandboxProviderRequest
18
+ # The name of the provider. Unique within the tenant.
19
+ attr_accessor :name
20
+
21
+ attr_accessor :kind
22
+
23
+ # The sandbox provider API key. It is write-only, stored encrypted and never returned.
24
+ attr_accessor :api_key
25
+
26
+ # Provider settings as JSON. Unknown keys are rejected.
27
+ attr_accessor :config
28
+
29
+ attr_accessor :default_template
30
+
31
+ # Defaults to 900.
32
+ attr_accessor :max_idle_ttl_seconds
33
+
34
+ # Default metadata for every sandbox this provider creates.
35
+ attr_accessor :labels
36
+
37
+ # Defaults to true.
38
+ attr_accessor :enabled
39
+
40
+ class EnumAttributeValidator
41
+ attr_reader :datatype
42
+ attr_reader :allowable_values
43
+
44
+ def initialize(datatype, allowable_values)
45
+ @allowable_values = allowable_values.map do |value|
46
+ case datatype.to_s
47
+ when /Integer/i
48
+ value.to_i
49
+ when /Float/i
50
+ value.to_f
51
+ else
52
+ value
53
+ end
54
+ end
55
+ end
56
+
57
+ def valid?(value)
58
+ !value || allowable_values.include?(value)
59
+ end
60
+ end
61
+
62
+ # Attribute mapping from ruby-style variable name to JSON key.
63
+ def self.attribute_map
64
+ {
65
+ :'name' => :'name',
66
+ :'kind' => :'kind',
67
+ :'api_key' => :'apiKey',
68
+ :'config' => :'config',
69
+ :'default_template' => :'defaultTemplate',
70
+ :'max_idle_ttl_seconds' => :'maxIdleTtlSeconds',
71
+ :'labels' => :'labels',
72
+ :'enabled' => :'enabled'
73
+ }
74
+ end
75
+
76
+ # Returns attribute mapping this model knows about
77
+ def self.acceptable_attribute_map
78
+ attribute_map
79
+ end
80
+
81
+ # Returns all the JSON keys this model knows about
82
+ def self.acceptable_attributes
83
+ acceptable_attribute_map.values
84
+ end
85
+
86
+ # Attribute type mapping.
87
+ def self.openapi_types
88
+ {
89
+ :'name' => :'String',
90
+ :'kind' => :'V1SandboxProviderKind',
91
+ :'api_key' => :'String',
92
+ :'config' => :'Hash<String, Object>',
93
+ :'default_template' => :'String',
94
+ :'max_idle_ttl_seconds' => :'Integer',
95
+ :'labels' => :'Hash<String, String>',
96
+ :'enabled' => :'Boolean'
97
+ }
98
+ end
99
+
100
+ # List of attributes with nullable: true
101
+ def self.openapi_nullable
102
+ Set.new([
103
+ ])
104
+ end
105
+
106
+ # Initializes the object
107
+ # @param [Hash] attributes Model attributes in the form of hash
108
+ def initialize(attributes = {})
109
+ if (!attributes.is_a?(Hash))
110
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1CreateSandboxProviderRequest` initialize method"
111
+ end
112
+
113
+ # check to see if the attribute exists and convert string to symbol for hash key
114
+ acceptable_attribute_map = self.class.acceptable_attribute_map
115
+ attributes = attributes.each_with_object({}) { |(k, v), h|
116
+ if (!acceptable_attribute_map.key?(k.to_sym))
117
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1CreateSandboxProviderRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
118
+ end
119
+ h[k.to_sym] = v
120
+ }
121
+
122
+ if attributes.key?(:'name')
123
+ self.name = attributes[:'name']
124
+ else
125
+ self.name = nil
126
+ end
127
+
128
+ if attributes.key?(:'kind')
129
+ self.kind = attributes[:'kind']
130
+ else
131
+ self.kind = nil
132
+ end
133
+
134
+ if attributes.key?(:'api_key')
135
+ self.api_key = attributes[:'api_key']
136
+ else
137
+ self.api_key = nil
138
+ end
139
+
140
+ if attributes.key?(:'config')
141
+ if (value = attributes[:'config']).is_a?(Hash)
142
+ self.config = value
143
+ end
144
+ end
145
+
146
+ if attributes.key?(:'default_template')
147
+ self.default_template = attributes[:'default_template']
148
+ end
149
+
150
+ if attributes.key?(:'max_idle_ttl_seconds')
151
+ self.max_idle_ttl_seconds = attributes[:'max_idle_ttl_seconds']
152
+ end
153
+
154
+ if attributes.key?(:'labels')
155
+ if (value = attributes[:'labels']).is_a?(Hash)
156
+ self.labels = value
157
+ end
158
+ end
159
+
160
+ if attributes.key?(:'enabled')
161
+ self.enabled = attributes[:'enabled']
162
+ end
163
+ end
164
+
165
+ # Show invalid properties with the reasons. Usually used together with valid?
166
+ # @return Array for valid properties with the reasons
167
+ def list_invalid_properties
168
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
169
+ invalid_properties = Array.new
170
+ if @name.nil?
171
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
172
+ end
173
+
174
+ if @name.to_s.length > 255
175
+ invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 255.')
176
+ end
177
+
178
+ if @name.to_s.length < 1
179
+ invalid_properties.push('invalid value for "name", the character length must be greater than or equal to 1.')
180
+ end
181
+
182
+ if @kind.nil?
183
+ invalid_properties.push('invalid value for "kind", kind cannot be nil.')
184
+ end
185
+
186
+ if @api_key.nil?
187
+ invalid_properties.push('invalid value for "api_key", api_key cannot be nil.')
188
+ end
189
+
190
+ if @api_key.to_s.length < 1
191
+ invalid_properties.push('invalid value for "api_key", the character length must be greater than or equal to 1.')
192
+ end
193
+
194
+ invalid_properties
195
+ end
196
+
197
+ # Check to see if the all the properties in the model are valid
198
+ # @return true if the model is valid
199
+ def valid?
200
+ warn '[DEPRECATED] the `valid?` method is obsolete'
201
+ return false if @name.nil?
202
+ return false if @name.to_s.length > 255
203
+ return false if @name.to_s.length < 1
204
+ return false if @kind.nil?
205
+ return false if @api_key.nil?
206
+ return false if @api_key.to_s.length < 1
207
+ true
208
+ end
209
+
210
+ # Custom attribute writer method with validation
211
+ # @param [Object] name Value to be assigned
212
+ def name=(name)
213
+ if name.nil?
214
+ fail ArgumentError, 'name cannot be nil'
215
+ end
216
+
217
+ if name.to_s.length > 255
218
+ fail ArgumentError, 'invalid value for "name", the character length must be smaller than or equal to 255.'
219
+ end
220
+
221
+ if name.to_s.length < 1
222
+ fail ArgumentError, 'invalid value for "name", the character length must be greater than or equal to 1.'
223
+ end
224
+
225
+ @name = name
226
+ end
227
+
228
+ # Custom attribute writer method with validation
229
+ # @param [Object] kind Value to be assigned
230
+ def kind=(kind)
231
+ if kind.nil?
232
+ fail ArgumentError, 'kind cannot be nil'
233
+ end
234
+
235
+ @kind = kind
236
+ end
237
+
238
+ # Custom attribute writer method with validation
239
+ # @param [Object] api_key Value to be assigned
240
+ def api_key=(api_key)
241
+ if api_key.nil?
242
+ fail ArgumentError, 'api_key cannot be nil'
243
+ end
244
+
245
+ if api_key.to_s.length < 1
246
+ fail ArgumentError, 'invalid value for "api_key", the character length must be greater than or equal to 1.'
247
+ end
248
+
249
+ @api_key = api_key
250
+ end
251
+
252
+ # Checks equality by comparing each attribute.
253
+ # @param [Object] Object to be compared
254
+ def ==(o)
255
+ return true if self.equal?(o)
256
+ self.class == o.class &&
257
+ name == o.name &&
258
+ kind == o.kind &&
259
+ api_key == o.api_key &&
260
+ config == o.config &&
261
+ default_template == o.default_template &&
262
+ max_idle_ttl_seconds == o.max_idle_ttl_seconds &&
263
+ labels == o.labels &&
264
+ enabled == o.enabled
265
+ end
266
+
267
+ # @see the `==` method
268
+ # @param [Object] Object to be compared
269
+ def eql?(o)
270
+ self == o
271
+ end
272
+
273
+ # Calculates hash code according to all attributes.
274
+ # @return [Integer] Hash code
275
+ def hash
276
+ [name, kind, api_key, config, default_template, max_idle_ttl_seconds, labels, enabled].hash
277
+ end
278
+
279
+ # Builds the object from hash
280
+ # @param [Hash] attributes Model attributes in the form of hash
281
+ # @return [Object] Returns the model itself
282
+ def self.build_from_hash(attributes)
283
+ return nil unless attributes.is_a?(Hash)
284
+ attributes = attributes.transform_keys(&:to_sym)
285
+ transformed_hash = {}
286
+ openapi_types.each_pair do |key, type|
287
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
288
+ transformed_hash["#{key}"] = nil
289
+ elsif type =~ /\AArray<(.*)>/i
290
+ # check to ensure the input is an array given that the attribute
291
+ # is documented as an array but the input is not
292
+ if attributes[attribute_map[key]].is_a?(Array)
293
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
294
+ end
295
+ elsif !attributes[attribute_map[key]].nil?
296
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
297
+ end
298
+ end
299
+ new(transformed_hash)
300
+ end
301
+
302
+ # Deserializes the data based on type
303
+ # @param string type Data type
304
+ # @param string value Value to be deserialized
305
+ # @return [Object] Deserialized data
306
+ def self._deserialize(type, value)
307
+ case type.to_sym
308
+ when :Time
309
+ Time.parse(value)
310
+ when :Date
311
+ Date.parse(value)
312
+ when :String
313
+ value.to_s
314
+ when :Integer
315
+ value.to_i
316
+ when :Float
317
+ value.to_f
318
+ when :Boolean
319
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
320
+ true
321
+ else
322
+ false
323
+ end
324
+ when :Object
325
+ # generic object (usually a Hash), return directly
326
+ value
327
+ when /\AArray<(?<inner_type>.+)>\z/
328
+ inner_type = Regexp.last_match[:inner_type]
329
+ value.map { |v| _deserialize(inner_type, v) }
330
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
331
+ k_type = Regexp.last_match[:k_type]
332
+ v_type = Regexp.last_match[:v_type]
333
+ {}.tap do |hash|
334
+ value.each do |k, v|
335
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
336
+ end
337
+ end
338
+ else # model
339
+ # models (e.g. Pet) or oneOf
340
+ klass = HatchetSdkRest.const_get(type)
341
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
342
+ end
343
+ end
344
+
345
+ # Returns the string representation of the object
346
+ # @return [String] String presentation of the object
347
+ def to_s
348
+ to_hash.to_s
349
+ end
350
+
351
+ # to_body is an alias to to_hash (backward compatibility)
352
+ # @return [Hash] Returns the object in the form of hash
353
+ def to_body
354
+ to_hash
355
+ end
356
+
357
+ # Returns the object in the form of hash
358
+ # @return [Hash] Returns the object in the form of hash
359
+ def to_hash
360
+ hash = {}
361
+ self.class.attribute_map.each_pair do |attr, param|
362
+ value = self.send(attr)
363
+ if value.nil?
364
+ is_nullable = self.class.openapi_nullable.include?(attr)
365
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
366
+ end
367
+
368
+ hash[param] = _to_hash(value)
369
+ end
370
+ hash
371
+ end
372
+
373
+ # Outputs non-array value in the form of hash
374
+ # For object, use to_hash. Otherwise, just return the value
375
+ # @param [Object] value Any valid value
376
+ # @return [Hash] Returns the value in the form of hash
377
+ def _to_hash(value)
378
+ if value.is_a?(Array)
379
+ value.compact.map { |v| _to_hash(v) }
380
+ elsif value.is_a?(Hash)
381
+ {}.tap do |hash|
382
+ value.each { |k, v| hash[k] = _to_hash(v) }
383
+ end
384
+ elsif value.respond_to? :to_hash
385
+ value.to_hash
386
+ else
387
+ value
388
+ end
389
+ end
390
+
391
+ end
392
+
393
+ end