insights-approval-api-client 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +9 -0
  3. data/README.md +142 -0
  4. data/Rakefile +10 -0
  5. data/client-meta.json +9 -0
  6. data/docs/Action.md +27 -0
  7. data/docs/ActionApi.md +172 -0
  8. data/docs/ActionCollection.md +21 -0
  9. data/docs/CollectionLinks.md +23 -0
  10. data/docs/CollectionMetadata.md +21 -0
  11. data/docs/GraphqlApi.md +62 -0
  12. data/docs/GraphqlIn.md +21 -0
  13. data/docs/GraphqlOut.md +19 -0
  14. data/docs/GroupRef.md +19 -0
  15. data/docs/HttpApiError.md +19 -0
  16. data/docs/HttpApiErrorCollection.md +17 -0
  17. data/docs/Request.md +49 -0
  18. data/docs/RequestApi.md +292 -0
  19. data/docs/RequestCollection.md +21 -0
  20. data/docs/RequestIn.md +23 -0
  21. data/docs/ResourceObject.md +21 -0
  22. data/docs/Tag.md +17 -0
  23. data/docs/TagResource.md +21 -0
  24. data/docs/Template.md +23 -0
  25. data/docs/TemplateApi.md +124 -0
  26. data/docs/TemplateCollection.md +21 -0
  27. data/docs/Workflow.md +29 -0
  28. data/docs/WorkflowApi.md +469 -0
  29. data/docs/WorkflowCollection.md +21 -0
  30. data/generate.sh +9 -0
  31. data/git_push.sh +58 -0
  32. data/insights-approval-api-client.gemspec +39 -0
  33. data/lib/insights-approval-api-client.rb +63 -0
  34. data/lib/insights-approval-api-client/api/action_api.rb +231 -0
  35. data/lib/insights-approval-api-client/api/graphql_api.rb +86 -0
  36. data/lib/insights-approval-api-client/api/request_api.rb +381 -0
  37. data/lib/insights-approval-api-client/api/template_api.rb +169 -0
  38. data/lib/insights-approval-api-client/api/workflow_api.rb +630 -0
  39. data/lib/insights-approval-api-client/api_client.rb +386 -0
  40. data/lib/insights-approval-api-client/api_error.rb +57 -0
  41. data/lib/insights-approval-api-client/configuration.rb +268 -0
  42. data/lib/insights-approval-api-client/models/action.rb +293 -0
  43. data/lib/insights-approval-api-client/models/action_collection.rb +226 -0
  44. data/lib/insights-approval-api-client/models/collection_links.rb +237 -0
  45. data/lib/insights-approval-api-client/models/collection_metadata.rb +227 -0
  46. data/lib/insights-approval-api-client/models/graphql_in.rb +237 -0
  47. data/lib/insights-approval-api-client/models/graphql_out.rb +219 -0
  48. data/lib/insights-approval-api-client/models/group_ref.rb +223 -0
  49. data/lib/insights-approval-api-client/models/http_api_error.rb +218 -0
  50. data/lib/insights-approval-api-client/models/http_api_error_collection.rb +210 -0
  51. data/lib/insights-approval-api-client/models/request.rb +417 -0
  52. data/lib/insights-approval-api-client/models/request_collection.rb +226 -0
  53. data/lib/insights-approval-api-client/models/request_in.rb +255 -0
  54. data/lib/insights-approval-api-client/models/resource_object.rb +243 -0
  55. data/lib/insights-approval-api-client/models/tag.rb +207 -0
  56. data/lib/insights-approval-api-client/models/tag_resource.rb +242 -0
  57. data/lib/insights-approval-api-client/models/template.rb +235 -0
  58. data/lib/insights-approval-api-client/models/template_collection.rb +226 -0
  59. data/lib/insights-approval-api-client/models/workflow.rb +283 -0
  60. data/lib/insights-approval-api-client/models/workflow_collection.rb +226 -0
  61. data/lib/insights-approval-api-client/version.rb +15 -0
  62. data/openapi.json +1540 -0
  63. data/spec/api/action_api_spec.rb +72 -0
  64. data/spec/api/graphql_api_spec.rb +47 -0
  65. data/spec/api/request_api_spec.rb +100 -0
  66. data/spec/api/template_api_spec.rb +62 -0
  67. data/spec/api/workflow_api_spec.rb +145 -0
  68. data/spec/api_client_spec.rb +226 -0
  69. data/spec/configuration_spec.rb +42 -0
  70. data/spec/models/action_collection_spec.rb +53 -0
  71. data/spec/models/action_spec.rb +75 -0
  72. data/spec/models/collection_links_spec.rb +59 -0
  73. data/spec/models/collection_metadata_spec.rb +53 -0
  74. data/spec/models/graphql_in_spec.rb +53 -0
  75. data/spec/models/graphql_out_spec.rb +47 -0
  76. data/spec/models/group_ref_spec.rb +47 -0
  77. data/spec/models/http_api_error_collection_spec.rb +41 -0
  78. data/spec/models/http_api_error_spec.rb +47 -0
  79. data/spec/models/request_collection_spec.rb +53 -0
  80. data/spec/models/request_in_spec.rb +59 -0
  81. data/spec/models/request_spec.rb +145 -0
  82. data/spec/models/resource_object_spec.rb +53 -0
  83. data/spec/models/tag_resource_spec.rb +53 -0
  84. data/spec/models/tag_spec.rb +41 -0
  85. data/spec/models/template_collection_spec.rb +53 -0
  86. data/spec/models/template_spec.rb +59 -0
  87. data/spec/models/workflow_collection_spec.rb +53 -0
  88. data/spec/models/workflow_spec.rb +77 -0
  89. data/spec/spec_helper.rb +111 -0
  90. metadata +218 -0
@@ -0,0 +1,417 @@
1
+ =begin
2
+ #Insights Service Approval APIs
3
+
4
+ #APIs to query approval service
5
+
6
+ The version of the OpenAPI document: 1.2.0
7
+ Contact: support@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.2
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module ApprovalApiClient
16
+ # Approval request. It may have child requests. Only a leaf node request can have workflow_id
17
+ class Request
18
+ attr_accessor :id
19
+
20
+ # The state of the request. Possible value: canceled, completed, failed, notified, skipped, or started
21
+ attr_accessor :state
22
+
23
+ # Approval decision. Possible value: undecided, approved, canceled, denied, or error
24
+ attr_accessor :decision
25
+
26
+ # Reason for the decision. Optional. Present normally when the decision is denied
27
+ attr_accessor :reason
28
+
29
+ # Associate workflow id. Available only if the request is a leaf node
30
+ attr_accessor :workflow_id
31
+
32
+ # Timestamp of creation
33
+ attr_accessor :created_at
34
+
35
+ # Timestamp of notification sent to approvers
36
+ attr_accessor :notified_at
37
+
38
+ # Timestamp of finishing (skipped, canceled, or completed)
39
+ attr_accessor :finished_at
40
+
41
+ # Number of child requests
42
+ attr_accessor :number_of_children
43
+
44
+ # Number of finished child requests
45
+ attr_accessor :number_of_finished_children
46
+
47
+ # Requester's id
48
+ attr_accessor :owner
49
+
50
+ # Requester's full name
51
+ attr_accessor :requester_name
52
+
53
+ # Request name
54
+ attr_accessor :name
55
+
56
+ # Request description
57
+ attr_accessor :description
58
+
59
+ # Name of approver group(s) assigned to approve this request
60
+ attr_accessor :group_name
61
+
62
+ # Parent request id
63
+ attr_accessor :parent_id
64
+
65
+ # JSON Metadata about the request
66
+ attr_accessor :metadata
67
+
68
+ class EnumAttributeValidator
69
+ attr_reader :datatype
70
+ attr_reader :allowable_values
71
+
72
+ def initialize(datatype, allowable_values)
73
+ @allowable_values = allowable_values.map do |value|
74
+ case datatype.to_s
75
+ when /Integer/i
76
+ value.to_i
77
+ when /Float/i
78
+ value.to_f
79
+ else
80
+ value
81
+ end
82
+ end
83
+ end
84
+
85
+ def valid?(value)
86
+ !value || allowable_values.include?(value)
87
+ end
88
+ end
89
+
90
+ # Attribute mapping from ruby-style variable name to JSON key.
91
+ def self.attribute_map
92
+ {
93
+ :'id' => :'id',
94
+ :'state' => :'state',
95
+ :'decision' => :'decision',
96
+ :'reason' => :'reason',
97
+ :'workflow_id' => :'workflow_id',
98
+ :'created_at' => :'created_at',
99
+ :'notified_at' => :'notified_at',
100
+ :'finished_at' => :'finished_at',
101
+ :'number_of_children' => :'number_of_children',
102
+ :'number_of_finished_children' => :'number_of_finished_children',
103
+ :'owner' => :'owner',
104
+ :'requester_name' => :'requester_name',
105
+ :'name' => :'name',
106
+ :'description' => :'description',
107
+ :'group_name' => :'group_name',
108
+ :'parent_id' => :'parent_id',
109
+ :'metadata' => :'metadata'
110
+ }
111
+ end
112
+
113
+ # Attribute type mapping.
114
+ def self.openapi_types
115
+ {
116
+ :'id' => :'String',
117
+ :'state' => :'String',
118
+ :'decision' => :'String',
119
+ :'reason' => :'String',
120
+ :'workflow_id' => :'String',
121
+ :'created_at' => :'DateTime',
122
+ :'notified_at' => :'DateTime',
123
+ :'finished_at' => :'DateTime',
124
+ :'number_of_children' => :'Integer',
125
+ :'number_of_finished_children' => :'Integer',
126
+ :'owner' => :'String',
127
+ :'requester_name' => :'String',
128
+ :'name' => :'String',
129
+ :'description' => :'String',
130
+ :'group_name' => :'String',
131
+ :'parent_id' => :'String',
132
+ :'metadata' => :'Object'
133
+ }
134
+ end
135
+
136
+ # List of attributes with nullable: true
137
+ def self.openapi_nullable
138
+ Set.new([
139
+ :'reason',
140
+ :'workflow_id',
141
+ :'notified_at',
142
+ :'finished_at',
143
+ ])
144
+ end
145
+
146
+ # Initializes the object
147
+ # @param [Hash] attributes Model attributes in the form of hash
148
+ def initialize(attributes = {})
149
+ if (!attributes.is_a?(Hash))
150
+ fail ArgumentError, "The input argument (attributes) must be a hash in `ApprovalApiClient::Request` initialize method"
151
+ end
152
+
153
+ # check to see if the attribute exists and convert string to symbol for hash key
154
+ attributes = attributes.each_with_object({}) { |(k, v), h|
155
+ if (!self.class.attribute_map.key?(k.to_sym))
156
+ fail ArgumentError, "`#{k}` is not a valid attribute in `ApprovalApiClient::Request`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
157
+ end
158
+ h[k.to_sym] = v
159
+ }
160
+
161
+ if attributes.key?(:'id')
162
+ self.id = attributes[:'id']
163
+ end
164
+
165
+ if attributes.key?(:'state')
166
+ self.state = attributes[:'state']
167
+ end
168
+
169
+ if attributes.key?(:'decision')
170
+ self.decision = attributes[:'decision']
171
+ end
172
+
173
+ if attributes.key?(:'reason')
174
+ self.reason = attributes[:'reason']
175
+ end
176
+
177
+ if attributes.key?(:'workflow_id')
178
+ self.workflow_id = attributes[:'workflow_id']
179
+ end
180
+
181
+ if attributes.key?(:'created_at')
182
+ self.created_at = attributes[:'created_at']
183
+ end
184
+
185
+ if attributes.key?(:'notified_at')
186
+ self.notified_at = attributes[:'notified_at']
187
+ end
188
+
189
+ if attributes.key?(:'finished_at')
190
+ self.finished_at = attributes[:'finished_at']
191
+ end
192
+
193
+ if attributes.key?(:'number_of_children')
194
+ self.number_of_children = attributes[:'number_of_children']
195
+ end
196
+
197
+ if attributes.key?(:'number_of_finished_children')
198
+ self.number_of_finished_children = attributes[:'number_of_finished_children']
199
+ end
200
+
201
+ if attributes.key?(:'owner')
202
+ self.owner = attributes[:'owner']
203
+ end
204
+
205
+ if attributes.key?(:'requester_name')
206
+ self.requester_name = attributes[:'requester_name']
207
+ end
208
+
209
+ if attributes.key?(:'name')
210
+ self.name = attributes[:'name']
211
+ end
212
+
213
+ if attributes.key?(:'description')
214
+ self.description = attributes[:'description']
215
+ end
216
+
217
+ if attributes.key?(:'group_name')
218
+ self.group_name = attributes[:'group_name']
219
+ end
220
+
221
+ if attributes.key?(:'parent_id')
222
+ self.parent_id = attributes[:'parent_id']
223
+ end
224
+
225
+ if attributes.key?(:'metadata')
226
+ self.metadata = attributes[:'metadata']
227
+ end
228
+ end
229
+
230
+ # Show invalid properties with the reasons. Usually used together with valid?
231
+ # @return Array for valid properties with the reasons
232
+ def list_invalid_properties
233
+ invalid_properties = Array.new
234
+ invalid_properties
235
+ end
236
+
237
+ # Check to see if the all the properties in the model are valid
238
+ # @return true if the model is valid
239
+ def valid?
240
+ state_validator = EnumAttributeValidator.new('String', ["canceled", "completed", "failed", "notified", "pending", "skipped", "started"])
241
+ return false unless state_validator.valid?(@state)
242
+ decision_validator = EnumAttributeValidator.new('String', ["undecided", "approved", "canceled", "denied", "error"])
243
+ return false unless decision_validator.valid?(@decision)
244
+ true
245
+ end
246
+
247
+ # Custom attribute writer method checking allowed values (enum).
248
+ # @param [Object] state Object to be assigned
249
+ def state=(state)
250
+ validator = EnumAttributeValidator.new('String', ["canceled", "completed", "failed", "notified", "pending", "skipped", "started"])
251
+ unless validator.valid?(state)
252
+ fail ArgumentError, "invalid value for \"state\", must be one of #{validator.allowable_values}."
253
+ end
254
+ @state = state
255
+ end
256
+
257
+ # Custom attribute writer method checking allowed values (enum).
258
+ # @param [Object] decision Object to be assigned
259
+ def decision=(decision)
260
+ validator = EnumAttributeValidator.new('String', ["undecided", "approved", "canceled", "denied", "error"])
261
+ unless validator.valid?(decision)
262
+ fail ArgumentError, "invalid value for \"decision\", must be one of #{validator.allowable_values}."
263
+ end
264
+ @decision = decision
265
+ end
266
+
267
+ # Checks equality by comparing each attribute.
268
+ # @param [Object] Object to be compared
269
+ def ==(o)
270
+ return true if self.equal?(o)
271
+ self.class == o.class &&
272
+ id == o.id &&
273
+ state == o.state &&
274
+ decision == o.decision &&
275
+ reason == o.reason &&
276
+ workflow_id == o.workflow_id &&
277
+ created_at == o.created_at &&
278
+ notified_at == o.notified_at &&
279
+ finished_at == o.finished_at &&
280
+ number_of_children == o.number_of_children &&
281
+ number_of_finished_children == o.number_of_finished_children &&
282
+ owner == o.owner &&
283
+ requester_name == o.requester_name &&
284
+ name == o.name &&
285
+ description == o.description &&
286
+ group_name == o.group_name &&
287
+ parent_id == o.parent_id &&
288
+ metadata == o.metadata
289
+ end
290
+
291
+ # @see the `==` method
292
+ # @param [Object] Object to be compared
293
+ def eql?(o)
294
+ self == o
295
+ end
296
+
297
+ # Calculates hash code according to all attributes.
298
+ # @return [Integer] Hash code
299
+ def hash
300
+ [id, state, decision, reason, workflow_id, created_at, notified_at, finished_at, number_of_children, number_of_finished_children, owner, requester_name, name, description, group_name, parent_id, metadata].hash
301
+ end
302
+
303
+ # Builds the object from hash
304
+ # @param [Hash] attributes Model attributes in the form of hash
305
+ # @return [Object] Returns the model itself
306
+ def self.build_from_hash(attributes)
307
+ new.build_from_hash(attributes)
308
+ end
309
+
310
+ # Builds the object from hash
311
+ # @param [Hash] attributes Model attributes in the form of hash
312
+ # @return [Object] Returns the model itself
313
+ def build_from_hash(attributes)
314
+ return nil unless attributes.is_a?(Hash)
315
+ self.class.openapi_types.each_pair do |key, type|
316
+ if type =~ /\AArray<(.*)>/i
317
+ # check to ensure the input is an array given that the attribute
318
+ # is documented as an array but the input is not
319
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
320
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
321
+ end
322
+ elsif !attributes[self.class.attribute_map[key]].nil?
323
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
324
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
325
+ end
326
+
327
+ self
328
+ end
329
+
330
+ # Deserializes the data based on type
331
+ # @param string type Data type
332
+ # @param string value Value to be deserialized
333
+ # @return [Object] Deserialized data
334
+ def _deserialize(type, value)
335
+ case type.to_sym
336
+ when :DateTime
337
+ DateTime.parse(value)
338
+ when :Date
339
+ Date.parse(value)
340
+ when :String
341
+ value.to_s
342
+ when :Integer
343
+ value.to_i
344
+ when :Float
345
+ value.to_f
346
+ when :Boolean
347
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
348
+ true
349
+ else
350
+ false
351
+ end
352
+ when :Object
353
+ # generic object (usually a Hash), return directly
354
+ value
355
+ when /\AArray<(?<inner_type>.+)>\z/
356
+ inner_type = Regexp.last_match[:inner_type]
357
+ value.map { |v| _deserialize(inner_type, v) }
358
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
359
+ k_type = Regexp.last_match[:k_type]
360
+ v_type = Regexp.last_match[:v_type]
361
+ {}.tap do |hash|
362
+ value.each do |k, v|
363
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
364
+ end
365
+ end
366
+ else # model
367
+ ApprovalApiClient.const_get(type).build_from_hash(value)
368
+ end
369
+ end
370
+
371
+ # Returns the string representation of the object
372
+ # @return [String] String presentation of the object
373
+ def to_s
374
+ to_hash.to_s
375
+ end
376
+
377
+ # to_body is an alias to to_hash (backward compatibility)
378
+ # @return [Hash] Returns the object in the form of hash
379
+ def to_body
380
+ to_hash
381
+ end
382
+
383
+ # Returns the object in the form of hash
384
+ # @return [Hash] Returns the object in the form of hash
385
+ def to_hash
386
+ hash = {}
387
+ self.class.attribute_map.each_pair do |attr, param|
388
+ value = self.send(attr)
389
+ if value.nil?
390
+ is_nullable = self.class.openapi_nullable.include?(attr)
391
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
392
+ end
393
+
394
+ hash[param] = _to_hash(value)
395
+ end
396
+ hash
397
+ end
398
+
399
+ # Outputs non-array value in the form of hash
400
+ # For object, use to_hash. Otherwise, just return the value
401
+ # @param [Object] value Any valid value
402
+ # @return [Hash] Returns the value in the form of hash
403
+ def _to_hash(value)
404
+ if value.is_a?(Array)
405
+ value.compact.map { |v| _to_hash(v) }
406
+ elsif value.is_a?(Hash)
407
+ {}.tap do |hash|
408
+ value.each { |k, v| hash[k] = _to_hash(v) }
409
+ end
410
+ elsif value.respond_to? :to_hash
411
+ value.to_hash
412
+ else
413
+ value
414
+ end
415
+ end
416
+ end
417
+ end
@@ -0,0 +1,226 @@
1
+ =begin
2
+ #Insights Service Approval APIs
3
+
4
+ #APIs to query approval service
5
+
6
+ The version of the OpenAPI document: 1.2.0
7
+ Contact: support@redhat.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 4.2.2
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module ApprovalApiClient
16
+ class RequestCollection
17
+ attr_accessor :meta
18
+
19
+ attr_accessor :links
20
+
21
+ attr_accessor :data
22
+
23
+ # Attribute mapping from ruby-style variable name to JSON key.
24
+ def self.attribute_map
25
+ {
26
+ :'meta' => :'meta',
27
+ :'links' => :'links',
28
+ :'data' => :'data'
29
+ }
30
+ end
31
+
32
+ # Attribute type mapping.
33
+ def self.openapi_types
34
+ {
35
+ :'meta' => :'CollectionMetadata',
36
+ :'links' => :'CollectionLinks',
37
+ :'data' => :'Array<Request>'
38
+ }
39
+ end
40
+
41
+ # List of attributes with nullable: true
42
+ def self.openapi_nullable
43
+ Set.new([
44
+ ])
45
+ end
46
+
47
+ # Initializes the object
48
+ # @param [Hash] attributes Model attributes in the form of hash
49
+ def initialize(attributes = {})
50
+ if (!attributes.is_a?(Hash))
51
+ fail ArgumentError, "The input argument (attributes) must be a hash in `ApprovalApiClient::RequestCollection` initialize method"
52
+ end
53
+
54
+ # check to see if the attribute exists and convert string to symbol for hash key
55
+ attributes = attributes.each_with_object({}) { |(k, v), h|
56
+ if (!self.class.attribute_map.key?(k.to_sym))
57
+ fail ArgumentError, "`#{k}` is not a valid attribute in `ApprovalApiClient::RequestCollection`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
58
+ end
59
+ h[k.to_sym] = v
60
+ }
61
+
62
+ if attributes.key?(:'meta')
63
+ self.meta = attributes[:'meta']
64
+ end
65
+
66
+ if attributes.key?(:'links')
67
+ self.links = attributes[:'links']
68
+ end
69
+
70
+ if attributes.key?(:'data')
71
+ if (value = attributes[:'data']).is_a?(Array)
72
+ self.data = value
73
+ end
74
+ end
75
+ end
76
+
77
+ # Show invalid properties with the reasons. Usually used together with valid?
78
+ # @return Array for valid properties with the reasons
79
+ def list_invalid_properties
80
+ invalid_properties = Array.new
81
+ invalid_properties
82
+ end
83
+
84
+ # Check to see if the all the properties in the model are valid
85
+ # @return true if the model is valid
86
+ def valid?
87
+ true
88
+ end
89
+
90
+ # Checks equality by comparing each attribute.
91
+ # @param [Object] Object to be compared
92
+ def ==(o)
93
+ return true if self.equal?(o)
94
+ self.class == o.class &&
95
+ meta == o.meta &&
96
+ links == o.links &&
97
+ data == o.data
98
+ end
99
+
100
+ # @see the `==` method
101
+ # @param [Object] Object to be compared
102
+ def eql?(o)
103
+ self == o
104
+ end
105
+
106
+ # Calculates hash code according to all attributes.
107
+ # @return [Integer] Hash code
108
+ def hash
109
+ [meta, links, data].hash
110
+ end
111
+
112
+ # Builds the object from hash
113
+ # @param [Hash] attributes Model attributes in the form of hash
114
+ # @return [Object] Returns the model itself
115
+ def self.build_from_hash(attributes)
116
+ new.build_from_hash(attributes)
117
+ end
118
+
119
+ # Builds the object from hash
120
+ # @param [Hash] attributes Model attributes in the form of hash
121
+ # @return [Object] Returns the model itself
122
+ def build_from_hash(attributes)
123
+ return nil unless attributes.is_a?(Hash)
124
+ self.class.openapi_types.each_pair do |key, type|
125
+ if type =~ /\AArray<(.*)>/i
126
+ # check to ensure the input is an array given that the attribute
127
+ # is documented as an array but the input is not
128
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
129
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
130
+ end
131
+ elsif !attributes[self.class.attribute_map[key]].nil?
132
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
133
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
134
+ end
135
+
136
+ self
137
+ end
138
+
139
+ # Deserializes the data based on type
140
+ # @param string type Data type
141
+ # @param string value Value to be deserialized
142
+ # @return [Object] Deserialized data
143
+ def _deserialize(type, value)
144
+ case type.to_sym
145
+ when :DateTime
146
+ DateTime.parse(value)
147
+ when :Date
148
+ Date.parse(value)
149
+ when :String
150
+ value.to_s
151
+ when :Integer
152
+ value.to_i
153
+ when :Float
154
+ value.to_f
155
+ when :Boolean
156
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
157
+ true
158
+ else
159
+ false
160
+ end
161
+ when :Object
162
+ # generic object (usually a Hash), return directly
163
+ value
164
+ when /\AArray<(?<inner_type>.+)>\z/
165
+ inner_type = Regexp.last_match[:inner_type]
166
+ value.map { |v| _deserialize(inner_type, v) }
167
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
168
+ k_type = Regexp.last_match[:k_type]
169
+ v_type = Regexp.last_match[:v_type]
170
+ {}.tap do |hash|
171
+ value.each do |k, v|
172
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
173
+ end
174
+ end
175
+ else # model
176
+ ApprovalApiClient.const_get(type).build_from_hash(value)
177
+ end
178
+ end
179
+
180
+ # Returns the string representation of the object
181
+ # @return [String] String presentation of the object
182
+ def to_s
183
+ to_hash.to_s
184
+ end
185
+
186
+ # to_body is an alias to to_hash (backward compatibility)
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_body
189
+ to_hash
190
+ end
191
+
192
+ # Returns the object in the form of hash
193
+ # @return [Hash] Returns the object in the form of hash
194
+ def to_hash
195
+ hash = {}
196
+ self.class.attribute_map.each_pair do |attr, param|
197
+ value = self.send(attr)
198
+ if value.nil?
199
+ is_nullable = self.class.openapi_nullable.include?(attr)
200
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
201
+ end
202
+
203
+ hash[param] = _to_hash(value)
204
+ end
205
+ hash
206
+ end
207
+
208
+ # Outputs non-array value in the form of hash
209
+ # For object, use to_hash. Otherwise, just return the value
210
+ # @param [Object] value Any valid value
211
+ # @return [Hash] Returns the value in the form of hash
212
+ def _to_hash(value)
213
+ if value.is_a?(Array)
214
+ value.compact.map { |v| _to_hash(v) }
215
+ elsif value.is_a?(Hash)
216
+ {}.tap do |hash|
217
+ value.each { |k, v| hash[k] = _to_hash(v) }
218
+ end
219
+ elsif value.respond_to? :to_hash
220
+ value.to_hash
221
+ else
222
+ value
223
+ end
224
+ end
225
+ end
226
+ end