hatchet-sdk 0.9.0 → 0.11.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 (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +12 -0
  3. data/lib/hatchet/clients/grpc/admin.rb +20 -0
  4. data/lib/hatchet/clients/grpc/dispatcher.rb +6 -2
  5. data/lib/hatchet/clients/rest/.openapi-generator/FILES +13 -0
  6. data/lib/hatchet/clients/rest/README.md +21 -0
  7. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/serverless_api.rb +405 -0
  8. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/streams_api.rb +263 -0
  9. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/tenant_api.rb +71 -0
  10. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/workflow_runs_api.rb +142 -0
  11. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/rate_limit.rb +14 -4
  12. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_entitlements.rb +367 -0
  13. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_create_serverless_endpoint_request.rb +411 -0
  14. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint.rb +556 -0
  15. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_kind.rb +40 -0
  16. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_list.rb +231 -0
  17. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_serverless_endpoint_status.rb +271 -0
  18. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_stream_payload_ref.rb +238 -0
  19. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_stream_topic.rb +343 -0
  20. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_stream_topic_list.rb +292 -0
  21. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_update_serverless_endpoint_request.rb +354 -0
  22. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_workflow_run_count.rb +238 -0
  23. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/workflow.rb +14 -4
  24. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest.rb +13 -0
  25. data/lib/hatchet/context.rb +13 -0
  26. data/lib/hatchet/contracts/dispatcher/dispatcher_pb.rb +1 -1
  27. data/lib/hatchet/contracts/workflows/workflows_pb.rb +3 -1
  28. data/lib/hatchet/contracts/workflows/workflows_services_pb.rb +1 -0
  29. data/lib/hatchet/engine_version.rb +1 -0
  30. data/lib/hatchet/exceptions.rb +18 -0
  31. data/lib/hatchet/features/rate_limits.rb +13 -0
  32. data/lib/hatchet/version.rb +1 -1
  33. data/lib/hatchet/worker/runner.rb +24 -2
  34. data/sig/hatchet/clients/grpc/admin.rbs +1 -0
  35. data/sig/hatchet/context.rbs +1 -0
  36. data/sig/hatchet/features/rate_limits.rbs +1 -0
  37. metadata +15 -2
@@ -0,0 +1,292 @@
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 V1StreamTopicList
18
+ attr_accessor :pagination
19
+
20
+ # How long messages are kept, and how long a topic is kept after its last publish
21
+ attr_accessor :retention_hours
22
+
23
+ attr_accessor :rows
24
+
25
+ # Attribute mapping from ruby-style variable name to JSON key.
26
+ def self.attribute_map
27
+ {
28
+ :'pagination' => :'pagination',
29
+ :'retention_hours' => :'retentionHours',
30
+ :'rows' => :'rows'
31
+ }
32
+ end
33
+
34
+ # Returns attribute mapping this model knows about
35
+ def self.acceptable_attribute_map
36
+ attribute_map
37
+ end
38
+
39
+ # Returns all the JSON keys this model knows about
40
+ def self.acceptable_attributes
41
+ acceptable_attribute_map.values
42
+ end
43
+
44
+ # Attribute type mapping.
45
+ def self.openapi_types
46
+ {
47
+ :'pagination' => :'PaginationResponse',
48
+ :'retention_hours' => :'Integer',
49
+ :'rows' => :'Array<V1StreamTopic>'
50
+ }
51
+ end
52
+
53
+ # List of attributes with nullable: true
54
+ def self.openapi_nullable
55
+ Set.new([
56
+ ])
57
+ end
58
+
59
+ # Initializes the object
60
+ # @param [Hash] attributes Model attributes in the form of hash
61
+ def initialize(attributes = {})
62
+ if (!attributes.is_a?(Hash))
63
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1StreamTopicList` initialize method"
64
+ end
65
+
66
+ # check to see if the attribute exists and convert string to symbol for hash key
67
+ acceptable_attribute_map = self.class.acceptable_attribute_map
68
+ attributes = attributes.each_with_object({}) { |(k, v), h|
69
+ if (!acceptable_attribute_map.key?(k.to_sym))
70
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1StreamTopicList`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
71
+ end
72
+ h[k.to_sym] = v
73
+ }
74
+
75
+ if attributes.key?(:'pagination')
76
+ self.pagination = attributes[:'pagination']
77
+ else
78
+ self.pagination = nil
79
+ end
80
+
81
+ if attributes.key?(:'retention_hours')
82
+ self.retention_hours = attributes[:'retention_hours']
83
+ else
84
+ self.retention_hours = nil
85
+ end
86
+
87
+ if attributes.key?(:'rows')
88
+ if (value = attributes[:'rows']).is_a?(Array)
89
+ self.rows = value
90
+ end
91
+ else
92
+ self.rows = nil
93
+ end
94
+ end
95
+
96
+ # Show invalid properties with the reasons. Usually used together with valid?
97
+ # @return Array for valid properties with the reasons
98
+ def list_invalid_properties
99
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
100
+ invalid_properties = Array.new
101
+ if @pagination.nil?
102
+ invalid_properties.push('invalid value for "pagination", pagination cannot be nil.')
103
+ end
104
+
105
+ if @retention_hours.nil?
106
+ invalid_properties.push('invalid value for "retention_hours", retention_hours cannot be nil.')
107
+ end
108
+
109
+ if @rows.nil?
110
+ invalid_properties.push('invalid value for "rows", rows cannot be nil.')
111
+ end
112
+
113
+ invalid_properties
114
+ end
115
+
116
+ # Check to see if the all the properties in the model are valid
117
+ # @return true if the model is valid
118
+ def valid?
119
+ warn '[DEPRECATED] the `valid?` method is obsolete'
120
+ return false if @pagination.nil?
121
+ return false if @retention_hours.nil?
122
+ return false if @rows.nil?
123
+ true
124
+ end
125
+
126
+ # Custom attribute writer method with validation
127
+ # @param [Object] pagination Value to be assigned
128
+ def pagination=(pagination)
129
+ if pagination.nil?
130
+ fail ArgumentError, 'pagination cannot be nil'
131
+ end
132
+
133
+ @pagination = pagination
134
+ end
135
+
136
+ # Custom attribute writer method with validation
137
+ # @param [Object] retention_hours Value to be assigned
138
+ def retention_hours=(retention_hours)
139
+ if retention_hours.nil?
140
+ fail ArgumentError, 'retention_hours cannot be nil'
141
+ end
142
+
143
+ @retention_hours = retention_hours
144
+ end
145
+
146
+ # Custom attribute writer method with validation
147
+ # @param [Object] rows Value to be assigned
148
+ def rows=(rows)
149
+ if rows.nil?
150
+ fail ArgumentError, 'rows cannot be nil'
151
+ end
152
+
153
+ @rows = rows
154
+ end
155
+
156
+ # Checks equality by comparing each attribute.
157
+ # @param [Object] Object to be compared
158
+ def ==(o)
159
+ return true if self.equal?(o)
160
+ self.class == o.class &&
161
+ pagination == o.pagination &&
162
+ retention_hours == o.retention_hours &&
163
+ rows == o.rows
164
+ end
165
+
166
+ # @see the `==` method
167
+ # @param [Object] Object to be compared
168
+ def eql?(o)
169
+ self == o
170
+ end
171
+
172
+ # Calculates hash code according to all attributes.
173
+ # @return [Integer] Hash code
174
+ def hash
175
+ [pagination, retention_hours, rows].hash
176
+ end
177
+
178
+ # Builds the object from hash
179
+ # @param [Hash] attributes Model attributes in the form of hash
180
+ # @return [Object] Returns the model itself
181
+ def self.build_from_hash(attributes)
182
+ return nil unless attributes.is_a?(Hash)
183
+ attributes = attributes.transform_keys(&:to_sym)
184
+ transformed_hash = {}
185
+ openapi_types.each_pair do |key, type|
186
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
187
+ transformed_hash["#{key}"] = nil
188
+ elsif type =~ /\AArray<(.*)>/i
189
+ # check to ensure the input is an array given that the attribute
190
+ # is documented as an array but the input is not
191
+ if attributes[attribute_map[key]].is_a?(Array)
192
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
193
+ end
194
+ elsif !attributes[attribute_map[key]].nil?
195
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
196
+ end
197
+ end
198
+ new(transformed_hash)
199
+ end
200
+
201
+ # Deserializes the data based on type
202
+ # @param string type Data type
203
+ # @param string value Value to be deserialized
204
+ # @return [Object] Deserialized data
205
+ def self._deserialize(type, value)
206
+ case type.to_sym
207
+ when :Time
208
+ Time.parse(value)
209
+ when :Date
210
+ Date.parse(value)
211
+ when :String
212
+ value.to_s
213
+ when :Integer
214
+ value.to_i
215
+ when :Float
216
+ value.to_f
217
+ when :Boolean
218
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
219
+ true
220
+ else
221
+ false
222
+ end
223
+ when :Object
224
+ # generic object (usually a Hash), return directly
225
+ value
226
+ when /\AArray<(?<inner_type>.+)>\z/
227
+ inner_type = Regexp.last_match[:inner_type]
228
+ value.map { |v| _deserialize(inner_type, v) }
229
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
230
+ k_type = Regexp.last_match[:k_type]
231
+ v_type = Regexp.last_match[:v_type]
232
+ {}.tap do |hash|
233
+ value.each do |k, v|
234
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
235
+ end
236
+ end
237
+ else # model
238
+ # models (e.g. Pet) or oneOf
239
+ klass = HatchetSdkRest.const_get(type)
240
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
241
+ end
242
+ end
243
+
244
+ # Returns the string representation of the object
245
+ # @return [String] String presentation of the object
246
+ def to_s
247
+ to_hash.to_s
248
+ end
249
+
250
+ # to_body is an alias to to_hash (backward compatibility)
251
+ # @return [Hash] Returns the object in the form of hash
252
+ def to_body
253
+ to_hash
254
+ end
255
+
256
+ # Returns the object in the form of hash
257
+ # @return [Hash] Returns the object in the form of hash
258
+ def to_hash
259
+ hash = {}
260
+ self.class.attribute_map.each_pair do |attr, param|
261
+ value = self.send(attr)
262
+ if value.nil?
263
+ is_nullable = self.class.openapi_nullable.include?(attr)
264
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
265
+ end
266
+
267
+ hash[param] = _to_hash(value)
268
+ end
269
+ hash
270
+ end
271
+
272
+ # Outputs non-array value in the form of hash
273
+ # For object, use to_hash. Otherwise, just return the value
274
+ # @param [Object] value Any valid value
275
+ # @return [Hash] Returns the value in the form of hash
276
+ def _to_hash(value)
277
+ if value.is_a?(Array)
278
+ value.compact.map { |v| _to_hash(v) }
279
+ elsif value.is_a?(Hash)
280
+ {}.tap do |hash|
281
+ value.each { |k, v| hash[k] = _to_hash(v) }
282
+ end
283
+ elsif value.respond_to? :to_hash
284
+ value.to_hash
285
+ else
286
+ value
287
+ end
288
+ end
289
+
290
+ end
291
+
292
+ end
@@ -0,0 +1,354 @@
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
+ # Fields to update on a serverless endpoint. Omitted fields are left unchanged.
18
+ class V1UpdateServerlessEndpointRequest
19
+ # The name of the endpoint. Unique within the tenant.
20
+ attr_accessor :name
21
+
22
+ attr_accessor :kind
23
+
24
+ # The HTTPS URL (port 443) polled periodically to discover the workflows this endpoint serves.
25
+ attr_accessor :healthcheck_url
26
+
27
+ # The HTTPS URL (port 443) that assigned tasks are delivered to.
28
+ attr_accessor :trigger_url
29
+
30
+ # A new secret used to HMAC-sign requests delivered to the endpoint. At least 32 characters. Provide a value to rotate the secret; it is never returned in responses.
31
+ attr_accessor :signing_secret
32
+
33
+ # The per-request timeout backstop for trigger requests, in seconds.
34
+ attr_accessor :request_timeout_seconds
35
+
36
+ # How often the healthcheck URL is polled, in seconds.
37
+ attr_accessor :poll_interval_seconds
38
+
39
+ # The inline wait budget for durable results, in milliseconds.
40
+ attr_accessor :inline_wait_budget_ms
41
+
42
+ # Worker labels applied to the worker the operator creates for this endpoint. Replaces the existing labels.
43
+ attr_accessor :labels
44
+
45
+ # Whether the operator polls and dispatches to this endpoint.
46
+ attr_accessor :enabled
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
+ :'name' => :'name',
74
+ :'kind' => :'kind',
75
+ :'healthcheck_url' => :'healthcheckUrl',
76
+ :'trigger_url' => :'triggerUrl',
77
+ :'signing_secret' => :'signingSecret',
78
+ :'request_timeout_seconds' => :'requestTimeoutSeconds',
79
+ :'poll_interval_seconds' => :'pollIntervalSeconds',
80
+ :'inline_wait_budget_ms' => :'inlineWaitBudgetMs',
81
+ :'labels' => :'labels',
82
+ :'enabled' => :'enabled'
83
+ }
84
+ end
85
+
86
+ # Returns attribute mapping this model knows about
87
+ def self.acceptable_attribute_map
88
+ attribute_map
89
+ end
90
+
91
+ # Returns all the JSON keys this model knows about
92
+ def self.acceptable_attributes
93
+ acceptable_attribute_map.values
94
+ end
95
+
96
+ # Attribute type mapping.
97
+ def self.openapi_types
98
+ {
99
+ :'name' => :'String',
100
+ :'kind' => :'V1ServerlessEndpointKind',
101
+ :'healthcheck_url' => :'String',
102
+ :'trigger_url' => :'String',
103
+ :'signing_secret' => :'String',
104
+ :'request_timeout_seconds' => :'Integer',
105
+ :'poll_interval_seconds' => :'Integer',
106
+ :'inline_wait_budget_ms' => :'Integer',
107
+ :'labels' => :'Hash<String, Object>',
108
+ :'enabled' => :'Boolean'
109
+ }
110
+ end
111
+
112
+ # List of attributes with nullable: true
113
+ def self.openapi_nullable
114
+ Set.new([
115
+ ])
116
+ end
117
+
118
+ # Initializes the object
119
+ # @param [Hash] attributes Model attributes in the form of hash
120
+ def initialize(attributes = {})
121
+ if (!attributes.is_a?(Hash))
122
+ fail ArgumentError, "The input argument (attributes) must be a hash in `HatchetSdkRest::V1UpdateServerlessEndpointRequest` initialize method"
123
+ end
124
+
125
+ # check to see if the attribute exists and convert string to symbol for hash key
126
+ acceptable_attribute_map = self.class.acceptable_attribute_map
127
+ attributes = attributes.each_with_object({}) { |(k, v), h|
128
+ if (!acceptable_attribute_map.key?(k.to_sym))
129
+ fail ArgumentError, "`#{k}` is not a valid attribute in `HatchetSdkRest::V1UpdateServerlessEndpointRequest`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
130
+ end
131
+ h[k.to_sym] = v
132
+ }
133
+
134
+ if attributes.key?(:'name')
135
+ self.name = attributes[:'name']
136
+ end
137
+
138
+ if attributes.key?(:'kind')
139
+ self.kind = attributes[:'kind']
140
+ end
141
+
142
+ if attributes.key?(:'healthcheck_url')
143
+ self.healthcheck_url = attributes[:'healthcheck_url']
144
+ end
145
+
146
+ if attributes.key?(:'trigger_url')
147
+ self.trigger_url = attributes[:'trigger_url']
148
+ end
149
+
150
+ if attributes.key?(:'signing_secret')
151
+ self.signing_secret = attributes[:'signing_secret']
152
+ end
153
+
154
+ if attributes.key?(:'request_timeout_seconds')
155
+ self.request_timeout_seconds = attributes[:'request_timeout_seconds']
156
+ end
157
+
158
+ if attributes.key?(:'poll_interval_seconds')
159
+ self.poll_interval_seconds = attributes[:'poll_interval_seconds']
160
+ end
161
+
162
+ if attributes.key?(:'inline_wait_budget_ms')
163
+ self.inline_wait_budget_ms = attributes[:'inline_wait_budget_ms']
164
+ end
165
+
166
+ if attributes.key?(:'labels')
167
+ if (value = attributes[:'labels']).is_a?(Hash)
168
+ self.labels = value
169
+ end
170
+ end
171
+
172
+ if attributes.key?(:'enabled')
173
+ self.enabled = attributes[:'enabled']
174
+ end
175
+ end
176
+
177
+ # Show invalid properties with the reasons. Usually used together with valid?
178
+ # @return Array for valid properties with the reasons
179
+ def list_invalid_properties
180
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
181
+ invalid_properties = Array.new
182
+ if !@signing_secret.nil? && @signing_secret.to_s.length < 32
183
+ invalid_properties.push('invalid value for "signing_secret", the character length must be greater than or equal to 32.')
184
+ end
185
+
186
+ invalid_properties
187
+ end
188
+
189
+ # Check to see if the all the properties in the model are valid
190
+ # @return true if the model is valid
191
+ def valid?
192
+ warn '[DEPRECATED] the `valid?` method is obsolete'
193
+ return false if !@signing_secret.nil? && @signing_secret.to_s.length < 32
194
+ true
195
+ end
196
+
197
+ # Custom attribute writer method with validation
198
+ # @param [Object] signing_secret Value to be assigned
199
+ def signing_secret=(signing_secret)
200
+ if signing_secret.nil?
201
+ fail ArgumentError, 'signing_secret cannot be nil'
202
+ end
203
+
204
+ if signing_secret.to_s.length < 32
205
+ fail ArgumentError, 'invalid value for "signing_secret", the character length must be greater than or equal to 32.'
206
+ end
207
+
208
+ @signing_secret = signing_secret
209
+ end
210
+
211
+ # Checks equality by comparing each attribute.
212
+ # @param [Object] Object to be compared
213
+ def ==(o)
214
+ return true if self.equal?(o)
215
+ self.class == o.class &&
216
+ name == o.name &&
217
+ kind == o.kind &&
218
+ healthcheck_url == o.healthcheck_url &&
219
+ trigger_url == o.trigger_url &&
220
+ signing_secret == o.signing_secret &&
221
+ request_timeout_seconds == o.request_timeout_seconds &&
222
+ poll_interval_seconds == o.poll_interval_seconds &&
223
+ inline_wait_budget_ms == o.inline_wait_budget_ms &&
224
+ labels == o.labels &&
225
+ enabled == o.enabled
226
+ end
227
+
228
+ # @see the `==` method
229
+ # @param [Object] Object to be compared
230
+ def eql?(o)
231
+ self == o
232
+ end
233
+
234
+ # Calculates hash code according to all attributes.
235
+ # @return [Integer] Hash code
236
+ def hash
237
+ [name, kind, healthcheck_url, trigger_url, signing_secret, request_timeout_seconds, poll_interval_seconds, inline_wait_budget_ms, labels, enabled].hash
238
+ end
239
+
240
+ # Builds the object from hash
241
+ # @param [Hash] attributes Model attributes in the form of hash
242
+ # @return [Object] Returns the model itself
243
+ def self.build_from_hash(attributes)
244
+ return nil unless attributes.is_a?(Hash)
245
+ attributes = attributes.transform_keys(&:to_sym)
246
+ transformed_hash = {}
247
+ openapi_types.each_pair do |key, type|
248
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
249
+ transformed_hash["#{key}"] = nil
250
+ elsif type =~ /\AArray<(.*)>/i
251
+ # check to ensure the input is an array given that the attribute
252
+ # is documented as an array but the input is not
253
+ if attributes[attribute_map[key]].is_a?(Array)
254
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
255
+ end
256
+ elsif !attributes[attribute_map[key]].nil?
257
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
258
+ end
259
+ end
260
+ new(transformed_hash)
261
+ end
262
+
263
+ # Deserializes the data based on type
264
+ # @param string type Data type
265
+ # @param string value Value to be deserialized
266
+ # @return [Object] Deserialized data
267
+ def self._deserialize(type, value)
268
+ case type.to_sym
269
+ when :Time
270
+ Time.parse(value)
271
+ when :Date
272
+ Date.parse(value)
273
+ when :String
274
+ value.to_s
275
+ when :Integer
276
+ value.to_i
277
+ when :Float
278
+ value.to_f
279
+ when :Boolean
280
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
281
+ true
282
+ else
283
+ false
284
+ end
285
+ when :Object
286
+ # generic object (usually a Hash), return directly
287
+ value
288
+ when /\AArray<(?<inner_type>.+)>\z/
289
+ inner_type = Regexp.last_match[:inner_type]
290
+ value.map { |v| _deserialize(inner_type, v) }
291
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
292
+ k_type = Regexp.last_match[:k_type]
293
+ v_type = Regexp.last_match[:v_type]
294
+ {}.tap do |hash|
295
+ value.each do |k, v|
296
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
297
+ end
298
+ end
299
+ else # model
300
+ # models (e.g. Pet) or oneOf
301
+ klass = HatchetSdkRest.const_get(type)
302
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
303
+ end
304
+ end
305
+
306
+ # Returns the string representation of the object
307
+ # @return [String] String presentation of the object
308
+ def to_s
309
+ to_hash.to_s
310
+ end
311
+
312
+ # to_body is an alias to to_hash (backward compatibility)
313
+ # @return [Hash] Returns the object in the form of hash
314
+ def to_body
315
+ to_hash
316
+ end
317
+
318
+ # Returns the object in the form of hash
319
+ # @return [Hash] Returns the object in the form of hash
320
+ def to_hash
321
+ hash = {}
322
+ self.class.attribute_map.each_pair do |attr, param|
323
+ value = self.send(attr)
324
+ if value.nil?
325
+ is_nullable = self.class.openapi_nullable.include?(attr)
326
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
327
+ end
328
+
329
+ hash[param] = _to_hash(value)
330
+ end
331
+ hash
332
+ end
333
+
334
+ # Outputs non-array value in the form of hash
335
+ # For object, use to_hash. Otherwise, just return the value
336
+ # @param [Object] value Any valid value
337
+ # @return [Hash] Returns the value in the form of hash
338
+ def _to_hash(value)
339
+ if value.is_a?(Array)
340
+ value.compact.map { |v| _to_hash(v) }
341
+ elsif value.is_a?(Hash)
342
+ {}.tap do |hash|
343
+ value.each { |k, v| hash[k] = _to_hash(v) }
344
+ end
345
+ elsif value.respond_to? :to_hash
346
+ value.to_hash
347
+ else
348
+ value
349
+ end
350
+ end
351
+
352
+ end
353
+
354
+ end