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,676 @@
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 V1ConcurrencyStrategy
18
+ # The strategy id. Unique within a scope; WORKFLOW ids can collide with SHARED and TASK ids.
19
+ attr_accessor :id
20
+
21
+ attr_accessor :scope
22
+
23
+ # The shared strategy's name, the workflow name for WORKFLOW strategies, or the task name for TASK strategies.
24
+ attr_accessor :name
25
+
26
+ # Whether no latest workflow version uses this strategy, and it is only listed because runs of an older version still hold or wait for its slots.
27
+ attr_accessor :is_draining
28
+
29
+ # The CEL expression that computes a run's key.
30
+ attr_accessor :expression
31
+
32
+ attr_accessor :limit_strategy
33
+
34
+ # The static max runs per key.
35
+ attr_accessor :max_runs
36
+
37
+ # Keys with at least one run running or queued.
38
+ attr_accessor :key_count
39
+
40
+ # Keys with at least one queued run.
41
+ attr_accessor :queued_key_count
42
+
43
+ # Running runs, each holding a slot.
44
+ attr_accessor :running_count
45
+
46
+ # Queued runs.
47
+ attr_accessor :queued_count
48
+
49
+ # The workflow the strategy is defined on. Unset for SHARED strategies.
50
+ attr_accessor :workflow_id
51
+
52
+ # Unset for SHARED strategies.
53
+ attr_accessor :workflow_name
54
+
55
+ # The workflow version the strategy is attached to. Unset for SHARED strategies.
56
+ attr_accessor :workflow_version_id
57
+
58
+ # The workflow version's user-defined label, when one was set. Unset for SHARED strategies.
59
+ attr_accessor :workflow_version
60
+
61
+ # The task the strategy is defined on. Only set for TASK strategies.
62
+ attr_accessor :task_name
63
+
64
+ # Tasks on their workflow's latest version that use this strategy. Only set for SHARED strategies.
65
+ attr_accessor :used_by
66
+
67
+ # CEL expression computing max runs per key from the task input, when set. Overrides maxRuns.
68
+ attr_accessor :max_runs_expression
69
+
70
+ # When the longest-queued run was created. Unset when nothing is queued.
71
+ attr_accessor :oldest_queued_at
72
+
73
+ # The key of the longest-queued run. Unset when nothing is queued.
74
+ attr_accessor :oldest_queued_key
75
+
76
+ class EnumAttributeValidator
77
+ attr_reader :datatype
78
+ attr_reader :allowable_values
79
+
80
+ def initialize(datatype, allowable_values)
81
+ @allowable_values = allowable_values.map do |value|
82
+ case datatype.to_s
83
+ when /Integer/i
84
+ value.to_i
85
+ when /Float/i
86
+ value.to_f
87
+ else
88
+ value
89
+ end
90
+ end
91
+ end
92
+
93
+ def valid?(value)
94
+ !value || allowable_values.include?(value)
95
+ end
96
+ end
97
+
98
+ # Attribute mapping from ruby-style variable name to JSON key.
99
+ def self.attribute_map
100
+ {
101
+ :'id' => :'id',
102
+ :'scope' => :'scope',
103
+ :'name' => :'name',
104
+ :'is_draining' => :'isDraining',
105
+ :'expression' => :'expression',
106
+ :'limit_strategy' => :'limitStrategy',
107
+ :'max_runs' => :'maxRuns',
108
+ :'key_count' => :'keyCount',
109
+ :'queued_key_count' => :'queuedKeyCount',
110
+ :'running_count' => :'runningCount',
111
+ :'queued_count' => :'queuedCount',
112
+ :'workflow_id' => :'workflowId',
113
+ :'workflow_name' => :'workflowName',
114
+ :'workflow_version_id' => :'workflowVersionId',
115
+ :'workflow_version' => :'workflowVersion',
116
+ :'task_name' => :'taskName',
117
+ :'used_by' => :'usedBy',
118
+ :'max_runs_expression' => :'maxRunsExpression',
119
+ :'oldest_queued_at' => :'oldestQueuedAt',
120
+ :'oldest_queued_key' => :'oldestQueuedKey'
121
+ }
122
+ end
123
+
124
+ # Returns attribute mapping this model knows about
125
+ def self.acceptable_attribute_map
126
+ attribute_map
127
+ end
128
+
129
+ # Returns all the JSON keys this model knows about
130
+ def self.acceptable_attributes
131
+ acceptable_attribute_map.values
132
+ end
133
+
134
+ # Attribute type mapping.
135
+ def self.openapi_types
136
+ {
137
+ :'id' => :'Integer',
138
+ :'scope' => :'V1ConcurrencyScope',
139
+ :'name' => :'String',
140
+ :'is_draining' => :'Boolean',
141
+ :'expression' => :'String',
142
+ :'limit_strategy' => :'V1ConcurrencyLimitStrategy',
143
+ :'max_runs' => :'Integer',
144
+ :'key_count' => :'Integer',
145
+ :'queued_key_count' => :'Integer',
146
+ :'running_count' => :'Integer',
147
+ :'queued_count' => :'Integer',
148
+ :'workflow_id' => :'String',
149
+ :'workflow_name' => :'String',
150
+ :'workflow_version_id' => :'String',
151
+ :'workflow_version' => :'String',
152
+ :'task_name' => :'String',
153
+ :'used_by' => :'Array<V1ConcurrencyStrategyUsage>',
154
+ :'max_runs_expression' => :'String',
155
+ :'oldest_queued_at' => :'Time',
156
+ :'oldest_queued_key' => :'String'
157
+ }
158
+ end
159
+
160
+ # List of attributes with nullable: true
161
+ def self.openapi_nullable
162
+ Set.new([
163
+ ])
164
+ end
165
+
166
+ # Initializes the object
167
+ # @param [Hash] attributes Model attributes in the form of hash
168
+ def initialize(attributes = {})
169
+ if (!attributes.is_a?(Hash))
170
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1ConcurrencyStrategy` initialize method"
171
+ end
172
+
173
+ # check to see if the attribute exists and convert string to symbol for hash key
174
+ acceptable_attribute_map = self.class.acceptable_attribute_map
175
+ attributes = attributes.each_with_object({}) { |(k, v), h|
176
+ if (!acceptable_attribute_map.key?(k.to_sym))
177
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1ConcurrencyStrategy`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
178
+ end
179
+ h[k.to_sym] = v
180
+ }
181
+
182
+ if attributes.key?(:'id')
183
+ self.id = attributes[:'id']
184
+ else
185
+ self.id = nil
186
+ end
187
+
188
+ if attributes.key?(:'scope')
189
+ self.scope = attributes[:'scope']
190
+ else
191
+ self.scope = nil
192
+ end
193
+
194
+ if attributes.key?(:'name')
195
+ self.name = attributes[:'name']
196
+ else
197
+ self.name = nil
198
+ end
199
+
200
+ if attributes.key?(:'is_draining')
201
+ self.is_draining = attributes[:'is_draining']
202
+ else
203
+ self.is_draining = nil
204
+ end
205
+
206
+ if attributes.key?(:'expression')
207
+ self.expression = attributes[:'expression']
208
+ else
209
+ self.expression = nil
210
+ end
211
+
212
+ if attributes.key?(:'limit_strategy')
213
+ self.limit_strategy = attributes[:'limit_strategy']
214
+ else
215
+ self.limit_strategy = nil
216
+ end
217
+
218
+ if attributes.key?(:'max_runs')
219
+ self.max_runs = attributes[:'max_runs']
220
+ else
221
+ self.max_runs = nil
222
+ end
223
+
224
+ if attributes.key?(:'key_count')
225
+ self.key_count = attributes[:'key_count']
226
+ else
227
+ self.key_count = nil
228
+ end
229
+
230
+ if attributes.key?(:'queued_key_count')
231
+ self.queued_key_count = attributes[:'queued_key_count']
232
+ else
233
+ self.queued_key_count = nil
234
+ end
235
+
236
+ if attributes.key?(:'running_count')
237
+ self.running_count = attributes[:'running_count']
238
+ else
239
+ self.running_count = nil
240
+ end
241
+
242
+ if attributes.key?(:'queued_count')
243
+ self.queued_count = attributes[:'queued_count']
244
+ else
245
+ self.queued_count = nil
246
+ end
247
+
248
+ if attributes.key?(:'workflow_id')
249
+ self.workflow_id = attributes[:'workflow_id']
250
+ end
251
+
252
+ if attributes.key?(:'workflow_name')
253
+ self.workflow_name = attributes[:'workflow_name']
254
+ end
255
+
256
+ if attributes.key?(:'workflow_version_id')
257
+ self.workflow_version_id = attributes[:'workflow_version_id']
258
+ end
259
+
260
+ if attributes.key?(:'workflow_version')
261
+ self.workflow_version = attributes[:'workflow_version']
262
+ end
263
+
264
+ if attributes.key?(:'task_name')
265
+ self.task_name = attributes[:'task_name']
266
+ end
267
+
268
+ if attributes.key?(:'used_by')
269
+ if (value = attributes[:'used_by']).is_a?(Array)
270
+ self.used_by = value
271
+ end
272
+ end
273
+
274
+ if attributes.key?(:'max_runs_expression')
275
+ self.max_runs_expression = attributes[:'max_runs_expression']
276
+ end
277
+
278
+ if attributes.key?(:'oldest_queued_at')
279
+ self.oldest_queued_at = attributes[:'oldest_queued_at']
280
+ end
281
+
282
+ if attributes.key?(:'oldest_queued_key')
283
+ self.oldest_queued_key = attributes[:'oldest_queued_key']
284
+ end
285
+ end
286
+
287
+ # Show invalid properties with the reasons. Usually used together with valid?
288
+ # @return Array for valid properties with the reasons
289
+ def list_invalid_properties
290
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
291
+ invalid_properties = Array.new
292
+ if @id.nil?
293
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
294
+ end
295
+
296
+ if @scope.nil?
297
+ invalid_properties.push('invalid value for "scope", scope cannot be nil.')
298
+ end
299
+
300
+ if @name.nil?
301
+ invalid_properties.push('invalid value for "name", name cannot be nil.')
302
+ end
303
+
304
+ if @is_draining.nil?
305
+ invalid_properties.push('invalid value for "is_draining", is_draining cannot be nil.')
306
+ end
307
+
308
+ if @expression.nil?
309
+ invalid_properties.push('invalid value for "expression", expression cannot be nil.')
310
+ end
311
+
312
+ if @limit_strategy.nil?
313
+ invalid_properties.push('invalid value for "limit_strategy", limit_strategy cannot be nil.')
314
+ end
315
+
316
+ if @max_runs.nil?
317
+ invalid_properties.push('invalid value for "max_runs", max_runs cannot be nil.')
318
+ end
319
+
320
+ if @key_count.nil?
321
+ invalid_properties.push('invalid value for "key_count", key_count cannot be nil.')
322
+ end
323
+
324
+ if @queued_key_count.nil?
325
+ invalid_properties.push('invalid value for "queued_key_count", queued_key_count cannot be nil.')
326
+ end
327
+
328
+ if @running_count.nil?
329
+ invalid_properties.push('invalid value for "running_count", running_count cannot be nil.')
330
+ end
331
+
332
+ if @queued_count.nil?
333
+ invalid_properties.push('invalid value for "queued_count", queued_count cannot be nil.')
334
+ end
335
+
336
+ if !@workflow_id.nil? && @workflow_id.to_s.length > 36
337
+ invalid_properties.push('invalid value for "workflow_id", the character length must be smaller than or equal to 36.')
338
+ end
339
+
340
+ if !@workflow_id.nil? && @workflow_id.to_s.length < 36
341
+ invalid_properties.push('invalid value for "workflow_id", the character length must be greater than or equal to 36.')
342
+ end
343
+
344
+ if !@workflow_version_id.nil? && @workflow_version_id.to_s.length > 36
345
+ invalid_properties.push('invalid value for "workflow_version_id", the character length must be smaller than or equal to 36.')
346
+ end
347
+
348
+ if !@workflow_version_id.nil? && @workflow_version_id.to_s.length < 36
349
+ invalid_properties.push('invalid value for "workflow_version_id", the character length must be greater than or equal to 36.')
350
+ end
351
+
352
+ invalid_properties
353
+ end
354
+
355
+ # Check to see if the all the properties in the model are valid
356
+ # @return true if the model is valid
357
+ def valid?
358
+ warn '[DEPRECATED] the `valid?` method is obsolete'
359
+ return false if @id.nil?
360
+ return false if @scope.nil?
361
+ return false if @name.nil?
362
+ return false if @is_draining.nil?
363
+ return false if @expression.nil?
364
+ return false if @limit_strategy.nil?
365
+ return false if @max_runs.nil?
366
+ return false if @key_count.nil?
367
+ return false if @queued_key_count.nil?
368
+ return false if @running_count.nil?
369
+ return false if @queued_count.nil?
370
+ return false if !@workflow_id.nil? && @workflow_id.to_s.length > 36
371
+ return false if !@workflow_id.nil? && @workflow_id.to_s.length < 36
372
+ return false if !@workflow_version_id.nil? && @workflow_version_id.to_s.length > 36
373
+ return false if !@workflow_version_id.nil? && @workflow_version_id.to_s.length < 36
374
+ true
375
+ end
376
+
377
+ # Custom attribute writer method with validation
378
+ # @param [Object] id Value to be assigned
379
+ def id=(id)
380
+ if id.nil?
381
+ fail ArgumentError, 'id cannot be nil'
382
+ end
383
+
384
+ @id = id
385
+ end
386
+
387
+ # Custom attribute writer method with validation
388
+ # @param [Object] scope Value to be assigned
389
+ def scope=(scope)
390
+ if scope.nil?
391
+ fail ArgumentError, 'scope cannot be nil'
392
+ end
393
+
394
+ @scope = scope
395
+ end
396
+
397
+ # Custom attribute writer method with validation
398
+ # @param [Object] name Value to be assigned
399
+ def name=(name)
400
+ if name.nil?
401
+ fail ArgumentError, 'name cannot be nil'
402
+ end
403
+
404
+ @name = name
405
+ end
406
+
407
+ # Custom attribute writer method with validation
408
+ # @param [Object] is_draining Value to be assigned
409
+ def is_draining=(is_draining)
410
+ if is_draining.nil?
411
+ fail ArgumentError, 'is_draining cannot be nil'
412
+ end
413
+
414
+ @is_draining = is_draining
415
+ end
416
+
417
+ # Custom attribute writer method with validation
418
+ # @param [Object] expression Value to be assigned
419
+ def expression=(expression)
420
+ if expression.nil?
421
+ fail ArgumentError, 'expression cannot be nil'
422
+ end
423
+
424
+ @expression = expression
425
+ end
426
+
427
+ # Custom attribute writer method with validation
428
+ # @param [Object] limit_strategy Value to be assigned
429
+ def limit_strategy=(limit_strategy)
430
+ if limit_strategy.nil?
431
+ fail ArgumentError, 'limit_strategy cannot be nil'
432
+ end
433
+
434
+ @limit_strategy = limit_strategy
435
+ end
436
+
437
+ # Custom attribute writer method with validation
438
+ # @param [Object] max_runs Value to be assigned
439
+ def max_runs=(max_runs)
440
+ if max_runs.nil?
441
+ fail ArgumentError, 'max_runs cannot be nil'
442
+ end
443
+
444
+ @max_runs = max_runs
445
+ end
446
+
447
+ # Custom attribute writer method with validation
448
+ # @param [Object] key_count Value to be assigned
449
+ def key_count=(key_count)
450
+ if key_count.nil?
451
+ fail ArgumentError, 'key_count cannot be nil'
452
+ end
453
+
454
+ @key_count = key_count
455
+ end
456
+
457
+ # Custom attribute writer method with validation
458
+ # @param [Object] queued_key_count Value to be assigned
459
+ def queued_key_count=(queued_key_count)
460
+ if queued_key_count.nil?
461
+ fail ArgumentError, 'queued_key_count cannot be nil'
462
+ end
463
+
464
+ @queued_key_count = queued_key_count
465
+ end
466
+
467
+ # Custom attribute writer method with validation
468
+ # @param [Object] running_count Value to be assigned
469
+ def running_count=(running_count)
470
+ if running_count.nil?
471
+ fail ArgumentError, 'running_count cannot be nil'
472
+ end
473
+
474
+ @running_count = running_count
475
+ end
476
+
477
+ # Custom attribute writer method with validation
478
+ # @param [Object] queued_count Value to be assigned
479
+ def queued_count=(queued_count)
480
+ if queued_count.nil?
481
+ fail ArgumentError, 'queued_count cannot be nil'
482
+ end
483
+
484
+ @queued_count = queued_count
485
+ end
486
+
487
+ # Custom attribute writer method with validation
488
+ # @param [Object] workflow_id Value to be assigned
489
+ def workflow_id=(workflow_id)
490
+ if workflow_id.nil?
491
+ fail ArgumentError, 'workflow_id cannot be nil'
492
+ end
493
+
494
+ if workflow_id.to_s.length > 36
495
+ fail ArgumentError, 'invalid value for "workflow_id", the character length must be smaller than or equal to 36.'
496
+ end
497
+
498
+ if workflow_id.to_s.length < 36
499
+ fail ArgumentError, 'invalid value for "workflow_id", the character length must be greater than or equal to 36.'
500
+ end
501
+
502
+ @workflow_id = workflow_id
503
+ end
504
+
505
+ # Custom attribute writer method with validation
506
+ # @param [Object] workflow_version_id Value to be assigned
507
+ def workflow_version_id=(workflow_version_id)
508
+ if workflow_version_id.nil?
509
+ fail ArgumentError, 'workflow_version_id cannot be nil'
510
+ end
511
+
512
+ if workflow_version_id.to_s.length > 36
513
+ fail ArgumentError, 'invalid value for "workflow_version_id", the character length must be smaller than or equal to 36.'
514
+ end
515
+
516
+ if workflow_version_id.to_s.length < 36
517
+ fail ArgumentError, 'invalid value for "workflow_version_id", the character length must be greater than or equal to 36.'
518
+ end
519
+
520
+ @workflow_version_id = workflow_version_id
521
+ end
522
+
523
+ # Checks equality by comparing each attribute.
524
+ # @param [Object] Object to be compared
525
+ def ==(o)
526
+ return true if self.equal?(o)
527
+ self.class == o.class &&
528
+ id == o.id &&
529
+ scope == o.scope &&
530
+ name == o.name &&
531
+ is_draining == o.is_draining &&
532
+ expression == o.expression &&
533
+ limit_strategy == o.limit_strategy &&
534
+ max_runs == o.max_runs &&
535
+ key_count == o.key_count &&
536
+ queued_key_count == o.queued_key_count &&
537
+ running_count == o.running_count &&
538
+ queued_count == o.queued_count &&
539
+ workflow_id == o.workflow_id &&
540
+ workflow_name == o.workflow_name &&
541
+ workflow_version_id == o.workflow_version_id &&
542
+ workflow_version == o.workflow_version &&
543
+ task_name == o.task_name &&
544
+ used_by == o.used_by &&
545
+ max_runs_expression == o.max_runs_expression &&
546
+ oldest_queued_at == o.oldest_queued_at &&
547
+ oldest_queued_key == o.oldest_queued_key
548
+ end
549
+
550
+ # @see the `==` method
551
+ # @param [Object] Object to be compared
552
+ def eql?(o)
553
+ self == o
554
+ end
555
+
556
+ # Calculates hash code according to all attributes.
557
+ # @return [Integer] Hash code
558
+ def hash
559
+ [id, scope, name, is_draining, expression, limit_strategy, max_runs, key_count, queued_key_count, running_count, queued_count, workflow_id, workflow_name, workflow_version_id, workflow_version, task_name, used_by, max_runs_expression, oldest_queued_at, oldest_queued_key].hash
560
+ end
561
+
562
+ # Builds the object from hash
563
+ # @param [Hash] attributes Model attributes in the form of hash
564
+ # @return [Object] Returns the model itself
565
+ def self.build_from_hash(attributes)
566
+ return nil unless attributes.is_a?(Hash)
567
+ attributes = attributes.transform_keys(&:to_sym)
568
+ transformed_hash = {}
569
+ openapi_types.each_pair do |key, type|
570
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
571
+ transformed_hash["#{key}"] = nil
572
+ elsif type =~ /\AArray<(.*)>/i
573
+ # check to ensure the input is an array given that the attribute
574
+ # is documented as an array but the input is not
575
+ if attributes[attribute_map[key]].is_a?(Array)
576
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
577
+ end
578
+ elsif !attributes[attribute_map[key]].nil?
579
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
580
+ end
581
+ end
582
+ new(transformed_hash)
583
+ end
584
+
585
+ # Deserializes the data based on type
586
+ # @param string type Data type
587
+ # @param string value Value to be deserialized
588
+ # @return [Object] Deserialized data
589
+ def self._deserialize(type, value)
590
+ case type.to_sym
591
+ when :Time
592
+ Time.parse(value)
593
+ when :Date
594
+ Date.parse(value)
595
+ when :String
596
+ value.to_s
597
+ when :Integer
598
+ value.to_i
599
+ when :Float
600
+ value.to_f
601
+ when :Boolean
602
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
603
+ true
604
+ else
605
+ false
606
+ end
607
+ when :Object
608
+ # generic object (usually a Hash), return directly
609
+ value
610
+ when /\AArray<(?<inner_type>.+)>\z/
611
+ inner_type = Regexp.last_match[:inner_type]
612
+ value.map { |v| _deserialize(inner_type, v) }
613
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
614
+ k_type = Regexp.last_match[:k_type]
615
+ v_type = Regexp.last_match[:v_type]
616
+ {}.tap do |hash|
617
+ value.each do |k, v|
618
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
619
+ end
620
+ end
621
+ else # model
622
+ # models (e.g. Pet) or oneOf
623
+ klass = HatchetSdkRest.const_get(type)
624
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
625
+ end
626
+ end
627
+
628
+ # Returns the string representation of the object
629
+ # @return [String] String presentation of the object
630
+ def to_s
631
+ to_hash.to_s
632
+ end
633
+
634
+ # to_body is an alias to to_hash (backward compatibility)
635
+ # @return [Hash] Returns the object in the form of hash
636
+ def to_body
637
+ to_hash
638
+ end
639
+
640
+ # Returns the object in the form of hash
641
+ # @return [Hash] Returns the object in the form of hash
642
+ def to_hash
643
+ hash = {}
644
+ self.class.attribute_map.each_pair do |attr, param|
645
+ value = self.send(attr)
646
+ if value.nil?
647
+ is_nullable = self.class.openapi_nullable.include?(attr)
648
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
649
+ end
650
+
651
+ hash[param] = _to_hash(value)
652
+ end
653
+ hash
654
+ end
655
+
656
+ # Outputs non-array value in the form of hash
657
+ # For object, use to_hash. Otherwise, just return the value
658
+ # @param [Object] value Any valid value
659
+ # @return [Hash] Returns the value in the form of hash
660
+ def _to_hash(value)
661
+ if value.is_a?(Array)
662
+ value.compact.map { |v| _to_hash(v) }
663
+ elsif value.is_a?(Hash)
664
+ {}.tap do |hash|
665
+ value.each { |k, v| hash[k] = _to_hash(v) }
666
+ end
667
+ elsif value.respond_to? :to_hash
668
+ value.to_hash
669
+ else
670
+ value
671
+ end
672
+ end
673
+
674
+ end
675
+
676
+ end