hatchet-sdk 0.11.2 → 0.12.0

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +6 -0
  3. data/README.md +1 -0
  4. data/lib/hatchet/clients/rest/.openapi-generator/FILES +13 -0
  5. data/lib/hatchet/clients/rest/README.md +15 -0
  6. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/concurrency_api.rb +188 -0
  7. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/serverless_api.rb +77 -0
  8. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/api_token.rb +28 -1
  9. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/create_api_token_request.rb +11 -1
  10. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/feature_flag_id.rb +2 -1
  11. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_key.rb +326 -0
  12. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_key_list.rb +275 -0
  13. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_limit_strategy.rb +44 -0
  14. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_scope.rb +41 -0
  15. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_strategy.rb +676 -0
  16. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_strategy_list.rb +239 -0
  17. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_concurrency_strategy_usage.rb +307 -0
  18. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_create_serverless_endpoint_request.rb +1 -1
  19. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_check_stage.rb +42 -0
  20. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_event.rb +363 -0
  21. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_event_details.rb +358 -0
  22. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_event_kind.rb +44 -0
  23. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_event_list.rb +239 -0
  24. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_kind.rb +2 -1
  25. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest.rb +13 -0
  26. data/lib/hatchet/contracts/v1/streams_pb.rb +28 -0
  27. data/lib/hatchet/contracts/v1/streams_services_pb.rb +26 -0
  28. data/lib/hatchet/features/streams.rb +498 -0
  29. data/lib/hatchet/version.rb +1 -1
  30. data/lib/hatchet-sdk.rb +11 -0
  31. data/sig/hatchet/features/streams.rbs +39 -0
  32. data/sig/hatchet-sdk.rbs +1 -0
  33. metadata +19 -2
@@ -0,0 +1,363 @@
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 V1ServerlessEndpointEvent
18
+ attr_accessor :id
19
+
20
+ attr_accessor :created_at
21
+
22
+ attr_accessor :kind
23
+
24
+ attr_accessor :message
25
+
26
+ attr_accessor :details
27
+
28
+ class EnumAttributeValidator
29
+ attr_reader :datatype
30
+ attr_reader :allowable_values
31
+
32
+ def initialize(datatype, allowable_values)
33
+ @allowable_values = allowable_values.map do |value|
34
+ case datatype.to_s
35
+ when /Integer/i
36
+ value.to_i
37
+ when /Float/i
38
+ value.to_f
39
+ else
40
+ value
41
+ end
42
+ end
43
+ end
44
+
45
+ def valid?(value)
46
+ !value || allowable_values.include?(value)
47
+ end
48
+ end
49
+
50
+ # Attribute mapping from ruby-style variable name to JSON key.
51
+ def self.attribute_map
52
+ {
53
+ :'id' => :'id',
54
+ :'created_at' => :'createdAt',
55
+ :'kind' => :'kind',
56
+ :'message' => :'message',
57
+ :'details' => :'details'
58
+ }
59
+ end
60
+
61
+ # Returns attribute mapping this model knows about
62
+ def self.acceptable_attribute_map
63
+ attribute_map
64
+ end
65
+
66
+ # Returns all the JSON keys this model knows about
67
+ def self.acceptable_attributes
68
+ acceptable_attribute_map.values
69
+ end
70
+
71
+ # Attribute type mapping.
72
+ def self.openapi_types
73
+ {
74
+ :'id' => :'Integer',
75
+ :'created_at' => :'Time',
76
+ :'kind' => :'V1ServerlessEndpointEventKind',
77
+ :'message' => :'String',
78
+ :'details' => :'V1ServerlessEndpointEventDetails'
79
+ }
80
+ end
81
+
82
+ # List of attributes with nullable: true
83
+ def self.openapi_nullable
84
+ Set.new([
85
+ ])
86
+ end
87
+
88
+ # Initializes the object
89
+ # @param [Hash] attributes Model attributes in the form of hash
90
+ def initialize(attributes = {})
91
+ if (!attributes.is_a?(Hash))
92
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1ServerlessEndpointEvent` initialize method"
93
+ end
94
+
95
+ # check to see if the attribute exists and convert string to symbol for hash key
96
+ acceptable_attribute_map = self.class.acceptable_attribute_map
97
+ attributes = attributes.each_with_object({}) { |(k, v), h|
98
+ if (!acceptable_attribute_map.key?(k.to_sym))
99
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1ServerlessEndpointEvent`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
100
+ end
101
+ h[k.to_sym] = v
102
+ }
103
+
104
+ if attributes.key?(:'id')
105
+ self.id = attributes[:'id']
106
+ else
107
+ self.id = nil
108
+ end
109
+
110
+ if attributes.key?(:'created_at')
111
+ self.created_at = attributes[:'created_at']
112
+ else
113
+ self.created_at = nil
114
+ end
115
+
116
+ if attributes.key?(:'kind')
117
+ self.kind = attributes[:'kind']
118
+ else
119
+ self.kind = nil
120
+ end
121
+
122
+ if attributes.key?(:'message')
123
+ self.message = attributes[:'message']
124
+ else
125
+ self.message = nil
126
+ end
127
+
128
+ if attributes.key?(:'details')
129
+ self.details = attributes[:'details']
130
+ else
131
+ self.details = nil
132
+ end
133
+ end
134
+
135
+ # Show invalid properties with the reasons. Usually used together with valid?
136
+ # @return Array for valid properties with the reasons
137
+ def list_invalid_properties
138
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
139
+ invalid_properties = Array.new
140
+ if @id.nil?
141
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
142
+ end
143
+
144
+ if @created_at.nil?
145
+ invalid_properties.push('invalid value for "created_at", created_at cannot be nil.')
146
+ end
147
+
148
+ if @kind.nil?
149
+ invalid_properties.push('invalid value for "kind", kind cannot be nil.')
150
+ end
151
+
152
+ if @message.nil?
153
+ invalid_properties.push('invalid value for "message", message cannot be nil.')
154
+ end
155
+
156
+ if @details.nil?
157
+ invalid_properties.push('invalid value for "details", details cannot be nil.')
158
+ end
159
+
160
+ invalid_properties
161
+ end
162
+
163
+ # Check to see if the all the properties in the model are valid
164
+ # @return true if the model is valid
165
+ def valid?
166
+ warn '[DEPRECATED] the `valid?` method is obsolete'
167
+ return false if @id.nil?
168
+ return false if @created_at.nil?
169
+ return false if @kind.nil?
170
+ return false if @message.nil?
171
+ return false if @details.nil?
172
+ true
173
+ end
174
+
175
+ # Custom attribute writer method with validation
176
+ # @param [Object] id Value to be assigned
177
+ def id=(id)
178
+ if id.nil?
179
+ fail ArgumentError, 'id cannot be nil'
180
+ end
181
+
182
+ @id = id
183
+ end
184
+
185
+ # Custom attribute writer method with validation
186
+ # @param [Object] created_at Value to be assigned
187
+ def created_at=(created_at)
188
+ if created_at.nil?
189
+ fail ArgumentError, 'created_at cannot be nil'
190
+ end
191
+
192
+ @created_at = created_at
193
+ end
194
+
195
+ # Custom attribute writer method with validation
196
+ # @param [Object] kind Value to be assigned
197
+ def kind=(kind)
198
+ if kind.nil?
199
+ fail ArgumentError, 'kind cannot be nil'
200
+ end
201
+
202
+ @kind = kind
203
+ end
204
+
205
+ # Custom attribute writer method with validation
206
+ # @param [Object] message Value to be assigned
207
+ def message=(message)
208
+ if message.nil?
209
+ fail ArgumentError, 'message cannot be nil'
210
+ end
211
+
212
+ @message = message
213
+ end
214
+
215
+ # Custom attribute writer method with validation
216
+ # @param [Object] details Value to be assigned
217
+ def details=(details)
218
+ if details.nil?
219
+ fail ArgumentError, 'details cannot be nil'
220
+ end
221
+
222
+ @details = details
223
+ end
224
+
225
+ # Checks equality by comparing each attribute.
226
+ # @param [Object] Object to be compared
227
+ def ==(o)
228
+ return true if self.equal?(o)
229
+ self.class == o.class &&
230
+ id == o.id &&
231
+ created_at == o.created_at &&
232
+ kind == o.kind &&
233
+ message == o.message &&
234
+ details == o.details
235
+ end
236
+
237
+ # @see the `==` method
238
+ # @param [Object] Object to be compared
239
+ def eql?(o)
240
+ self == o
241
+ end
242
+
243
+ # Calculates hash code according to all attributes.
244
+ # @return [Integer] Hash code
245
+ def hash
246
+ [id, created_at, kind, message, details].hash
247
+ end
248
+
249
+ # Builds the object from hash
250
+ # @param [Hash] attributes Model attributes in the form of hash
251
+ # @return [Object] Returns the model itself
252
+ def self.build_from_hash(attributes)
253
+ return nil unless attributes.is_a?(Hash)
254
+ attributes = attributes.transform_keys(&:to_sym)
255
+ transformed_hash = {}
256
+ openapi_types.each_pair do |key, type|
257
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
258
+ transformed_hash["#{key}"] = nil
259
+ elsif type =~ /\AArray<(.*)>/i
260
+ # check to ensure the input is an array given that the attribute
261
+ # is documented as an array but the input is not
262
+ if attributes[attribute_map[key]].is_a?(Array)
263
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
264
+ end
265
+ elsif !attributes[attribute_map[key]].nil?
266
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
267
+ end
268
+ end
269
+ new(transformed_hash)
270
+ end
271
+
272
+ # Deserializes the data based on type
273
+ # @param string type Data type
274
+ # @param string value Value to be deserialized
275
+ # @return [Object] Deserialized data
276
+ def self._deserialize(type, value)
277
+ case type.to_sym
278
+ when :Time
279
+ Time.parse(value)
280
+ when :Date
281
+ Date.parse(value)
282
+ when :String
283
+ value.to_s
284
+ when :Integer
285
+ value.to_i
286
+ when :Float
287
+ value.to_f
288
+ when :Boolean
289
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
290
+ true
291
+ else
292
+ false
293
+ end
294
+ when :Object
295
+ # generic object (usually a Hash), return directly
296
+ value
297
+ when /\AArray<(?<inner_type>.+)>\z/
298
+ inner_type = Regexp.last_match[:inner_type]
299
+ value.map { |v| _deserialize(inner_type, v) }
300
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
301
+ k_type = Regexp.last_match[:k_type]
302
+ v_type = Regexp.last_match[:v_type]
303
+ {}.tap do |hash|
304
+ value.each do |k, v|
305
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
306
+ end
307
+ end
308
+ else # model
309
+ # models (e.g. Pet) or oneOf
310
+ klass = HatchetSdkRest.const_get(type)
311
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
312
+ end
313
+ end
314
+
315
+ # Returns the string representation of the object
316
+ # @return [String] String presentation of the object
317
+ def to_s
318
+ to_hash.to_s
319
+ end
320
+
321
+ # to_body is an alias to to_hash (backward compatibility)
322
+ # @return [Hash] Returns the object in the form of hash
323
+ def to_body
324
+ to_hash
325
+ end
326
+
327
+ # Returns the object in the form of hash
328
+ # @return [Hash] Returns the object in the form of hash
329
+ def to_hash
330
+ hash = {}
331
+ self.class.attribute_map.each_pair do |attr, param|
332
+ value = self.send(attr)
333
+ if value.nil?
334
+ is_nullable = self.class.openapi_nullable.include?(attr)
335
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
336
+ end
337
+
338
+ hash[param] = _to_hash(value)
339
+ end
340
+ hash
341
+ end
342
+
343
+ # Outputs non-array value in the form of hash
344
+ # For object, use to_hash. Otherwise, just return the value
345
+ # @param [Object] value Any valid value
346
+ # @return [Hash] Returns the value in the form of hash
347
+ def _to_hash(value)
348
+ if value.is_a?(Array)
349
+ value.compact.map { |v| _to_hash(v) }
350
+ elsif value.is_a?(Hash)
351
+ {}.tap do |hash|
352
+ value.each { |k, v| hash[k] = _to_hash(v) }
353
+ end
354
+ elsif value.respond_to? :to_hash
355
+ value.to_hash
356
+ else
357
+ value
358
+ end
359
+ end
360
+
361
+ end
362
+
363
+ end
@@ -0,0 +1,358 @@
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 V1ServerlessEndpointEventDetails
18
+ attr_accessor :stage
19
+
20
+ attr_accessor :url
21
+
22
+ attr_accessor :status_code
23
+
24
+ attr_accessor :duration_ms
25
+
26
+ # The start of the response body, at most 1 KiB. Omitted for members who cannot view payloads.
27
+ attr_accessor :response_excerpt
28
+
29
+ attr_accessor :actions
30
+
31
+ attr_accessor :workflows
32
+
33
+ attr_accessor :task_run_external_id
34
+
35
+ attr_accessor :action_id
36
+
37
+ attr_accessor :retry_count
38
+
39
+ # Whether the engine will retry the failed delivery.
40
+ attr_accessor :retryable
41
+
42
+ # Events of this kind since the previous one that were not recorded on their own, because they came too soon after it or past the endpoint's event budget.
43
+ attr_accessor :suppressed
44
+
45
+ # Whether the details were cut to bound the event's size: the workflows and actions lists keep their first 50 entries, and long names are shortened.
46
+ attr_accessor :truncated
47
+
48
+ class EnumAttributeValidator
49
+ attr_reader :datatype
50
+ attr_reader :allowable_values
51
+
52
+ def initialize(datatype, allowable_values)
53
+ @allowable_values = allowable_values.map do |value|
54
+ case datatype.to_s
55
+ when /Integer/i
56
+ value.to_i
57
+ when /Float/i
58
+ value.to_f
59
+ else
60
+ value
61
+ end
62
+ end
63
+ end
64
+
65
+ def valid?(value)
66
+ !value || allowable_values.include?(value)
67
+ end
68
+ end
69
+
70
+ # Attribute mapping from ruby-style variable name to JSON key.
71
+ def self.attribute_map
72
+ {
73
+ :'stage' => :'stage',
74
+ :'url' => :'url',
75
+ :'status_code' => :'statusCode',
76
+ :'duration_ms' => :'durationMs',
77
+ :'response_excerpt' => :'responseExcerpt',
78
+ :'actions' => :'actions',
79
+ :'workflows' => :'workflows',
80
+ :'task_run_external_id' => :'taskRunExternalId',
81
+ :'action_id' => :'actionId',
82
+ :'retry_count' => :'retryCount',
83
+ :'retryable' => :'retryable',
84
+ :'suppressed' => :'suppressed',
85
+ :'truncated' => :'truncated'
86
+ }
87
+ end
88
+
89
+ # Returns attribute mapping this model knows about
90
+ def self.acceptable_attribute_map
91
+ attribute_map
92
+ end
93
+
94
+ # Returns all the JSON keys this model knows about
95
+ def self.acceptable_attributes
96
+ acceptable_attribute_map.values
97
+ end
98
+
99
+ # Attribute type mapping.
100
+ def self.openapi_types
101
+ {
102
+ :'stage' => :'V1ServerlessEndpointCheckStage',
103
+ :'url' => :'String',
104
+ :'status_code' => :'Integer',
105
+ :'duration_ms' => :'Integer',
106
+ :'response_excerpt' => :'String',
107
+ :'actions' => :'Array<String>',
108
+ :'workflows' => :'Array<String>',
109
+ :'task_run_external_id' => :'String',
110
+ :'action_id' => :'String',
111
+ :'retry_count' => :'Integer',
112
+ :'retryable' => :'Boolean',
113
+ :'suppressed' => :'Integer',
114
+ :'truncated' => :'Boolean'
115
+ }
116
+ end
117
+
118
+ # List of attributes with nullable: true
119
+ def self.openapi_nullable
120
+ Set.new([
121
+ ])
122
+ end
123
+
124
+ # Initializes the object
125
+ # @param [Hash] attributes Model attributes in the form of hash
126
+ def initialize(attributes = {})
127
+ if (!attributes.is_a?(Hash))
128
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1ServerlessEndpointEventDetails` initialize method"
129
+ end
130
+
131
+ # check to see if the attribute exists and convert string to symbol for hash key
132
+ acceptable_attribute_map = self.class.acceptable_attribute_map
133
+ attributes = attributes.each_with_object({}) { |(k, v), h|
134
+ if (!acceptable_attribute_map.key?(k.to_sym))
135
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1ServerlessEndpointEventDetails`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
136
+ end
137
+ h[k.to_sym] = v
138
+ }
139
+
140
+ if attributes.key?(:'stage')
141
+ self.stage = attributes[:'stage']
142
+ end
143
+
144
+ if attributes.key?(:'url')
145
+ self.url = attributes[:'url']
146
+ end
147
+
148
+ if attributes.key?(:'status_code')
149
+ self.status_code = attributes[:'status_code']
150
+ end
151
+
152
+ if attributes.key?(:'duration_ms')
153
+ self.duration_ms = attributes[:'duration_ms']
154
+ end
155
+
156
+ if attributes.key?(:'response_excerpt')
157
+ self.response_excerpt = attributes[:'response_excerpt']
158
+ end
159
+
160
+ if attributes.key?(:'actions')
161
+ if (value = attributes[:'actions']).is_a?(Array)
162
+ self.actions = value
163
+ end
164
+ end
165
+
166
+ if attributes.key?(:'workflows')
167
+ if (value = attributes[:'workflows']).is_a?(Array)
168
+ self.workflows = value
169
+ end
170
+ end
171
+
172
+ if attributes.key?(:'task_run_external_id')
173
+ self.task_run_external_id = attributes[:'task_run_external_id']
174
+ end
175
+
176
+ if attributes.key?(:'action_id')
177
+ self.action_id = attributes[:'action_id']
178
+ end
179
+
180
+ if attributes.key?(:'retry_count')
181
+ self.retry_count = attributes[:'retry_count']
182
+ end
183
+
184
+ if attributes.key?(:'retryable')
185
+ self.retryable = attributes[:'retryable']
186
+ end
187
+
188
+ if attributes.key?(:'suppressed')
189
+ self.suppressed = attributes[:'suppressed']
190
+ end
191
+
192
+ if attributes.key?(:'truncated')
193
+ self.truncated = attributes[:'truncated']
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
+ invalid_properties = Array.new
202
+ invalid_properties
203
+ end
204
+
205
+ # Check to see if the all the properties in the model are valid
206
+ # @return true if the model is valid
207
+ def valid?
208
+ warn '[DEPRECATED] the `valid?` method is obsolete'
209
+ true
210
+ end
211
+
212
+ # Checks equality by comparing each attribute.
213
+ # @param [Object] Object to be compared
214
+ def ==(o)
215
+ return true if self.equal?(o)
216
+ self.class == o.class &&
217
+ stage == o.stage &&
218
+ url == o.url &&
219
+ status_code == o.status_code &&
220
+ duration_ms == o.duration_ms &&
221
+ response_excerpt == o.response_excerpt &&
222
+ actions == o.actions &&
223
+ workflows == o.workflows &&
224
+ task_run_external_id == o.task_run_external_id &&
225
+ action_id == o.action_id &&
226
+ retry_count == o.retry_count &&
227
+ retryable == o.retryable &&
228
+ suppressed == o.suppressed &&
229
+ truncated == o.truncated
230
+ end
231
+
232
+ # @see the `==` method
233
+ # @param [Object] Object to be compared
234
+ def eql?(o)
235
+ self == o
236
+ end
237
+
238
+ # Calculates hash code according to all attributes.
239
+ # @return [Integer] Hash code
240
+ def hash
241
+ [stage, url, status_code, duration_ms, response_excerpt, actions, workflows, task_run_external_id, action_id, retry_count, retryable, suppressed, truncated].hash
242
+ end
243
+
244
+ # Builds the object from hash
245
+ # @param [Hash] attributes Model attributes in the form of hash
246
+ # @return [Object] Returns the model itself
247
+ def self.build_from_hash(attributes)
248
+ return nil unless attributes.is_a?(Hash)
249
+ attributes = attributes.transform_keys(&:to_sym)
250
+ transformed_hash = {}
251
+ openapi_types.each_pair do |key, type|
252
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
253
+ transformed_hash["#{key}"] = nil
254
+ elsif type =~ /\AArray<(.*)>/i
255
+ # check to ensure the input is an array given that the attribute
256
+ # is documented as an array but the input is not
257
+ if attributes[attribute_map[key]].is_a?(Array)
258
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
259
+ end
260
+ elsif !attributes[attribute_map[key]].nil?
261
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
262
+ end
263
+ end
264
+ new(transformed_hash)
265
+ end
266
+
267
+ # Deserializes the data based on type
268
+ # @param string type Data type
269
+ # @param string value Value to be deserialized
270
+ # @return [Object] Deserialized data
271
+ def self._deserialize(type, value)
272
+ case type.to_sym
273
+ when :Time
274
+ Time.parse(value)
275
+ when :Date
276
+ Date.parse(value)
277
+ when :String
278
+ value.to_s
279
+ when :Integer
280
+ value.to_i
281
+ when :Float
282
+ value.to_f
283
+ when :Boolean
284
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
285
+ true
286
+ else
287
+ false
288
+ end
289
+ when :Object
290
+ # generic object (usually a Hash), return directly
291
+ value
292
+ when /\AArray<(?<inner_type>.+)>\z/
293
+ inner_type = Regexp.last_match[:inner_type]
294
+ value.map { |v| _deserialize(inner_type, v) }
295
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
296
+ k_type = Regexp.last_match[:k_type]
297
+ v_type = Regexp.last_match[:v_type]
298
+ {}.tap do |hash|
299
+ value.each do |k, v|
300
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
301
+ end
302
+ end
303
+ else # model
304
+ # models (e.g. Pet) or oneOf
305
+ klass = HatchetSdkRest.const_get(type)
306
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
307
+ end
308
+ end
309
+
310
+ # Returns the string representation of the object
311
+ # @return [String] String presentation of the object
312
+ def to_s
313
+ to_hash.to_s
314
+ end
315
+
316
+ # to_body is an alias to to_hash (backward compatibility)
317
+ # @return [Hash] Returns the object in the form of hash
318
+ def to_body
319
+ to_hash
320
+ end
321
+
322
+ # Returns the object in the form of hash
323
+ # @return [Hash] Returns the object in the form of hash
324
+ def to_hash
325
+ hash = {}
326
+ self.class.attribute_map.each_pair do |attr, param|
327
+ value = self.send(attr)
328
+ if value.nil?
329
+ is_nullable = self.class.openapi_nullable.include?(attr)
330
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
331
+ end
332
+
333
+ hash[param] = _to_hash(value)
334
+ end
335
+ hash
336
+ end
337
+
338
+ # Outputs non-array value in the form of hash
339
+ # For object, use to_hash. Otherwise, just return the value
340
+ # @param [Object] value Any valid value
341
+ # @return [Hash] Returns the value in the form of hash
342
+ def _to_hash(value)
343
+ if value.is_a?(Array)
344
+ value.compact.map { |v| _to_hash(v) }
345
+ elsif value.is_a?(Hash)
346
+ {}.tap do |hash|
347
+ value.each { |k, v| hash[k] = _to_hash(v) }
348
+ end
349
+ elsif value.respond_to? :to_hash
350
+ value.to_hash
351
+ else
352
+ value
353
+ end
354
+ end
355
+
356
+ end
357
+
358
+ end