imgwire 0.1.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 (59) hide show
  1. checksums.yaml +7 -0
  2. data/AGENTS.md +8 -0
  3. data/CODEGEN_VERSION +1 -0
  4. data/LICENSE +21 -0
  5. data/README.md +159 -0
  6. data/generated/lib/imgwire-generated/api/cors_origins_api.rb +355 -0
  7. data/generated/lib/imgwire-generated/api/custom_domain_api.rb +253 -0
  8. data/generated/lib/imgwire-generated/api/images_api.rb +534 -0
  9. data/generated/lib/imgwire-generated/api/metrics_api.rb +156 -0
  10. data/generated/lib/imgwire-generated/api_client.rb +392 -0
  11. data/generated/lib/imgwire-generated/api_error.rb +58 -0
  12. data/generated/lib/imgwire-generated/configuration.rb +301 -0
  13. data/generated/lib/imgwire-generated/models/bulk_delete_images_schema.rb +248 -0
  14. data/generated/lib/imgwire-generated/models/cache_hit_ratio_dataset_point_schema.rb +263 -0
  15. data/generated/lib/imgwire-generated/models/cors_origin_create_schema.rb +246 -0
  16. data/generated/lib/imgwire-generated/models/cors_origin_schema.rb +341 -0
  17. data/generated/lib/imgwire-generated/models/cors_origin_update_schema.rb +246 -0
  18. data/generated/lib/imgwire-generated/models/custom_domain_certificate_status.rb +41 -0
  19. data/generated/lib/imgwire-generated/models/custom_domain_create_schema.rb +237 -0
  20. data/generated/lib/imgwire-generated/models/custom_domain_schema.rb +531 -0
  21. data/generated/lib/imgwire-generated/models/custom_domain_status.rb +41 -0
  22. data/generated/lib/imgwire-generated/models/custom_metadata_value.rb +106 -0
  23. data/generated/lib/imgwire-generated/models/http_validation_error.rb +222 -0
  24. data/generated/lib/imgwire-generated/models/image_download_job_create_schema.rb +248 -0
  25. data/generated/lib/imgwire-generated/models/image_download_job_schema.rb +389 -0
  26. data/generated/lib/imgwire-generated/models/image_download_status.rb +42 -0
  27. data/generated/lib/imgwire-generated/models/image_schema.rb +659 -0
  28. data/generated/lib/imgwire-generated/models/image_status.rb +42 -0
  29. data/generated/lib/imgwire-generated/models/location_inner.rb +104 -0
  30. data/generated/lib/imgwire-generated/models/metrics_dataset_interval.rb +42 -0
  31. data/generated/lib/imgwire-generated/models/metrics_datasets_schema.rb +379 -0
  32. data/generated/lib/imgwire-generated/models/metrics_stat_value_schema.rb +275 -0
  33. data/generated/lib/imgwire-generated/models/metrics_stats_schema.rb +367 -0
  34. data/generated/lib/imgwire-generated/models/requests_dataset_point_schema.rb +263 -0
  35. data/generated/lib/imgwire-generated/models/standard_upload_create_schema.rb +415 -0
  36. data/generated/lib/imgwire-generated/models/standard_upload_response_schema.rb +263 -0
  37. data/generated/lib/imgwire-generated/models/storage_bytes_dataset_point_schema.rb +289 -0
  38. data/generated/lib/imgwire-generated/models/supported_mime_type.rb +43 -0
  39. data/generated/lib/imgwire-generated/models/transfer_bytes_dataset_point_schema.rb +263 -0
  40. data/generated/lib/imgwire-generated/models/transformations_dataset_point_schema.rb +263 -0
  41. data/generated/lib/imgwire-generated/models/upload_token_create_response_schema.rb +379 -0
  42. data/generated/lib/imgwire-generated/models/uploads_dataset_point_schema.rb +263 -0
  43. data/generated/lib/imgwire-generated/models/validation_error.rb +291 -0
  44. data/generated/lib/imgwire-generated/version.rb +15 -0
  45. data/generated/lib/imgwire-generated.rb +74 -0
  46. data/lib/imgwire/client.rb +52 -0
  47. data/lib/imgwire/client_options.rb +14 -0
  48. data/lib/imgwire/http/upload_client.rb +53 -0
  49. data/lib/imgwire/image.rb +137 -0
  50. data/lib/imgwire/pagination.rb +82 -0
  51. data/lib/imgwire/resources/base_resource.rb +29 -0
  52. data/lib/imgwire/resources/cors_origins_resource.rb +47 -0
  53. data/lib/imgwire/resources/custom_domain_resource.rb +30 -0
  54. data/lib/imgwire/resources/images_resource.rb +106 -0
  55. data/lib/imgwire/resources/metrics_resource.rb +24 -0
  56. data/lib/imgwire/uploads.rb +78 -0
  57. data/lib/imgwire/version.rb +5 -0
  58. data/lib/imgwire.rb +18 -0
  59. metadata +158 -0
@@ -0,0 +1,531 @@
1
+ =begin
2
+ #imgwire.dev Backend API development
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 0.1.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 ImgwireGenerated
17
+ class CustomDomainSchema
18
+ attr_accessor :certificate_status
19
+
20
+ attr_accessor :cname_record
21
+
22
+ attr_accessor :cname_value
23
+
24
+ attr_accessor :created_at
25
+
26
+ attr_accessor :dcv_cname_record
27
+
28
+ attr_accessor :dcv_cname_value
29
+
30
+ attr_accessor :environment_id
31
+
32
+ attr_accessor :hostname
33
+
34
+ attr_accessor :id
35
+
36
+ attr_accessor :last_verified_at
37
+
38
+ attr_accessor :status
39
+
40
+ attr_accessor :updated_at
41
+
42
+ class EnumAttributeValidator
43
+ attr_reader :datatype
44
+ attr_reader :allowable_values
45
+
46
+ def initialize(datatype, allowable_values)
47
+ @allowable_values = allowable_values.map do |value|
48
+ case datatype.to_s
49
+ when /Integer/i
50
+ value.to_i
51
+ when /Float/i
52
+ value.to_f
53
+ else
54
+ value
55
+ end
56
+ end
57
+ end
58
+
59
+ def valid?(value)
60
+ !value || allowable_values.include?(value)
61
+ end
62
+ end
63
+
64
+ # Attribute mapping from ruby-style variable name to JSON key.
65
+ def self.attribute_map
66
+ {
67
+ :'certificate_status' => :'certificate_status',
68
+ :'cname_record' => :'cname_record',
69
+ :'cname_value' => :'cname_value',
70
+ :'created_at' => :'created_at',
71
+ :'dcv_cname_record' => :'dcv_cname_record',
72
+ :'dcv_cname_value' => :'dcv_cname_value',
73
+ :'environment_id' => :'environment_id',
74
+ :'hostname' => :'hostname',
75
+ :'id' => :'id',
76
+ :'last_verified_at' => :'last_verified_at',
77
+ :'status' => :'status',
78
+ :'updated_at' => :'updated_at'
79
+ }
80
+ end
81
+
82
+ # Returns attribute mapping this model knows about
83
+ def self.acceptable_attribute_map
84
+ attribute_map
85
+ end
86
+
87
+ # Returns all the JSON keys this model knows about
88
+ def self.acceptable_attributes
89
+ acceptable_attribute_map.values
90
+ end
91
+
92
+ # Attribute type mapping.
93
+ def self.openapi_types
94
+ {
95
+ :'certificate_status' => :'CustomDomainCertificateStatus',
96
+ :'cname_record' => :'String',
97
+ :'cname_value' => :'String',
98
+ :'created_at' => :'Time',
99
+ :'dcv_cname_record' => :'String',
100
+ :'dcv_cname_value' => :'String',
101
+ :'environment_id' => :'String',
102
+ :'hostname' => :'String',
103
+ :'id' => :'String',
104
+ :'last_verified_at' => :'Time',
105
+ :'status' => :'CustomDomainStatus',
106
+ :'updated_at' => :'Time'
107
+ }
108
+ end
109
+
110
+ # List of attributes with nullable: true
111
+ def self.openapi_nullable
112
+ Set.new([
113
+ :'last_verified_at',
114
+ ])
115
+ end
116
+
117
+ # Initializes the object
118
+ # @param [Hash] attributes Model attributes in the form of hash
119
+ def initialize(attributes = {})
120
+ if (!attributes.is_a?(Hash))
121
+ fail ArgumentError, "The input argument (attributes) must be a hash in `ImgwireGenerated::CustomDomainSchema` initialize method"
122
+ end
123
+
124
+ # check to see if the attribute exists and convert string to symbol for hash key
125
+ acceptable_attribute_map = self.class.acceptable_attribute_map
126
+ attributes = attributes.each_with_object({}) { |(k, v), h|
127
+ if (!acceptable_attribute_map.key?(k.to_sym))
128
+ fail ArgumentError, "`#{k}` is not a valid attribute in `ImgwireGenerated::CustomDomainSchema`. Please check the name to make sure it's valid. List of attributes: " + acceptable_attribute_map.keys.inspect
129
+ end
130
+ h[k.to_sym] = v
131
+ }
132
+
133
+ if attributes.key?(:'certificate_status')
134
+ self.certificate_status = attributes[:'certificate_status']
135
+ else
136
+ self.certificate_status = nil
137
+ end
138
+
139
+ if attributes.key?(:'cname_record')
140
+ self.cname_record = attributes[:'cname_record']
141
+ else
142
+ self.cname_record = nil
143
+ end
144
+
145
+ if attributes.key?(:'cname_value')
146
+ self.cname_value = attributes[:'cname_value']
147
+ else
148
+ self.cname_value = nil
149
+ end
150
+
151
+ if attributes.key?(:'created_at')
152
+ self.created_at = attributes[:'created_at']
153
+ else
154
+ self.created_at = nil
155
+ end
156
+
157
+ if attributes.key?(:'dcv_cname_record')
158
+ self.dcv_cname_record = attributes[:'dcv_cname_record']
159
+ else
160
+ self.dcv_cname_record = nil
161
+ end
162
+
163
+ if attributes.key?(:'dcv_cname_value')
164
+ self.dcv_cname_value = attributes[:'dcv_cname_value']
165
+ else
166
+ self.dcv_cname_value = nil
167
+ end
168
+
169
+ if attributes.key?(:'environment_id')
170
+ self.environment_id = attributes[:'environment_id']
171
+ else
172
+ self.environment_id = nil
173
+ end
174
+
175
+ if attributes.key?(:'hostname')
176
+ self.hostname = attributes[:'hostname']
177
+ else
178
+ self.hostname = nil
179
+ end
180
+
181
+ if attributes.key?(:'id')
182
+ self.id = attributes[:'id']
183
+ else
184
+ self.id = nil
185
+ end
186
+
187
+ if attributes.key?(:'last_verified_at')
188
+ self.last_verified_at = attributes[:'last_verified_at']
189
+ else
190
+ self.last_verified_at = nil
191
+ end
192
+
193
+ if attributes.key?(:'status')
194
+ self.status = attributes[:'status']
195
+ else
196
+ self.status = nil
197
+ end
198
+
199
+ if attributes.key?(:'updated_at')
200
+ self.updated_at = attributes[:'updated_at']
201
+ else
202
+ self.updated_at = nil
203
+ end
204
+ end
205
+
206
+ # Show invalid properties with the reasons. Usually used together with valid?
207
+ # @return Array for valid properties with the reasons
208
+ def list_invalid_properties
209
+ warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
210
+ invalid_properties = Array.new
211
+ if @certificate_status.nil?
212
+ invalid_properties.push('invalid value for "certificate_status", certificate_status cannot be nil.')
213
+ end
214
+
215
+ if @cname_record.nil?
216
+ invalid_properties.push('invalid value for "cname_record", cname_record cannot be nil.')
217
+ end
218
+
219
+ if @cname_value.nil?
220
+ invalid_properties.push('invalid value for "cname_value", cname_value cannot be nil.')
221
+ end
222
+
223
+ if @created_at.nil?
224
+ invalid_properties.push('invalid value for "created_at", created_at cannot be nil.')
225
+ end
226
+
227
+ if @dcv_cname_record.nil?
228
+ invalid_properties.push('invalid value for "dcv_cname_record", dcv_cname_record cannot be nil.')
229
+ end
230
+
231
+ if @dcv_cname_value.nil?
232
+ invalid_properties.push('invalid value for "dcv_cname_value", dcv_cname_value cannot be nil.')
233
+ end
234
+
235
+ if @environment_id.nil?
236
+ invalid_properties.push('invalid value for "environment_id", environment_id cannot be nil.')
237
+ end
238
+
239
+ if @hostname.nil?
240
+ invalid_properties.push('invalid value for "hostname", hostname cannot be nil.')
241
+ end
242
+
243
+ if @id.nil?
244
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
245
+ end
246
+
247
+ if @status.nil?
248
+ invalid_properties.push('invalid value for "status", status cannot be nil.')
249
+ end
250
+
251
+ if @updated_at.nil?
252
+ invalid_properties.push('invalid value for "updated_at", updated_at cannot be nil.')
253
+ end
254
+
255
+ invalid_properties
256
+ end
257
+
258
+ # Check to see if the all the properties in the model are valid
259
+ # @return true if the model is valid
260
+ def valid?
261
+ warn '[DEPRECATED] the `valid?` method is obsolete'
262
+ return false if @certificate_status.nil?
263
+ return false if @cname_record.nil?
264
+ return false if @cname_value.nil?
265
+ return false if @created_at.nil?
266
+ return false if @dcv_cname_record.nil?
267
+ return false if @dcv_cname_value.nil?
268
+ return false if @environment_id.nil?
269
+ return false if @hostname.nil?
270
+ return false if @id.nil?
271
+ return false if @status.nil?
272
+ return false if @updated_at.nil?
273
+ true
274
+ end
275
+
276
+ # Custom attribute writer method with validation
277
+ # @param [Object] certificate_status Value to be assigned
278
+ def certificate_status=(certificate_status)
279
+ if certificate_status.nil?
280
+ fail ArgumentError, 'certificate_status cannot be nil'
281
+ end
282
+
283
+ @certificate_status = certificate_status
284
+ end
285
+
286
+ # Custom attribute writer method with validation
287
+ # @param [Object] cname_record Value to be assigned
288
+ def cname_record=(cname_record)
289
+ if cname_record.nil?
290
+ fail ArgumentError, 'cname_record cannot be nil'
291
+ end
292
+
293
+ @cname_record = cname_record
294
+ end
295
+
296
+ # Custom attribute writer method with validation
297
+ # @param [Object] cname_value Value to be assigned
298
+ def cname_value=(cname_value)
299
+ if cname_value.nil?
300
+ fail ArgumentError, 'cname_value cannot be nil'
301
+ end
302
+
303
+ @cname_value = cname_value
304
+ end
305
+
306
+ # Custom attribute writer method with validation
307
+ # @param [Object] created_at Value to be assigned
308
+ def created_at=(created_at)
309
+ if created_at.nil?
310
+ fail ArgumentError, 'created_at cannot be nil'
311
+ end
312
+
313
+ @created_at = created_at
314
+ end
315
+
316
+ # Custom attribute writer method with validation
317
+ # @param [Object] dcv_cname_record Value to be assigned
318
+ def dcv_cname_record=(dcv_cname_record)
319
+ if dcv_cname_record.nil?
320
+ fail ArgumentError, 'dcv_cname_record cannot be nil'
321
+ end
322
+
323
+ @dcv_cname_record = dcv_cname_record
324
+ end
325
+
326
+ # Custom attribute writer method with validation
327
+ # @param [Object] dcv_cname_value Value to be assigned
328
+ def dcv_cname_value=(dcv_cname_value)
329
+ if dcv_cname_value.nil?
330
+ fail ArgumentError, 'dcv_cname_value cannot be nil'
331
+ end
332
+
333
+ @dcv_cname_value = dcv_cname_value
334
+ end
335
+
336
+ # Custom attribute writer method with validation
337
+ # @param [Object] environment_id Value to be assigned
338
+ def environment_id=(environment_id)
339
+ if environment_id.nil?
340
+ fail ArgumentError, 'environment_id cannot be nil'
341
+ end
342
+
343
+ @environment_id = environment_id
344
+ end
345
+
346
+ # Custom attribute writer method with validation
347
+ # @param [Object] hostname Value to be assigned
348
+ def hostname=(hostname)
349
+ if hostname.nil?
350
+ fail ArgumentError, 'hostname cannot be nil'
351
+ end
352
+
353
+ @hostname = hostname
354
+ end
355
+
356
+ # Custom attribute writer method with validation
357
+ # @param [Object] id Value to be assigned
358
+ def id=(id)
359
+ if id.nil?
360
+ fail ArgumentError, 'id cannot be nil'
361
+ end
362
+
363
+ @id = id
364
+ end
365
+
366
+ # Custom attribute writer method with validation
367
+ # @param [Object] status Value to be assigned
368
+ def status=(status)
369
+ if status.nil?
370
+ fail ArgumentError, 'status cannot be nil'
371
+ end
372
+
373
+ @status = status
374
+ end
375
+
376
+ # Custom attribute writer method with validation
377
+ # @param [Object] updated_at Value to be assigned
378
+ def updated_at=(updated_at)
379
+ if updated_at.nil?
380
+ fail ArgumentError, 'updated_at cannot be nil'
381
+ end
382
+
383
+ @updated_at = updated_at
384
+ end
385
+
386
+ # Checks equality by comparing each attribute.
387
+ # @param [Object] Object to be compared
388
+ def ==(o)
389
+ return true if self.equal?(o)
390
+ self.class == o.class &&
391
+ certificate_status == o.certificate_status &&
392
+ cname_record == o.cname_record &&
393
+ cname_value == o.cname_value &&
394
+ created_at == o.created_at &&
395
+ dcv_cname_record == o.dcv_cname_record &&
396
+ dcv_cname_value == o.dcv_cname_value &&
397
+ environment_id == o.environment_id &&
398
+ hostname == o.hostname &&
399
+ id == o.id &&
400
+ last_verified_at == o.last_verified_at &&
401
+ status == o.status &&
402
+ updated_at == o.updated_at
403
+ end
404
+
405
+ # @see the `==` method
406
+ # @param [Object] Object to be compared
407
+ def eql?(o)
408
+ self == o
409
+ end
410
+
411
+ # Calculates hash code according to all attributes.
412
+ # @return [Integer] Hash code
413
+ def hash
414
+ [certificate_status, cname_record, cname_value, created_at, dcv_cname_record, dcv_cname_value, environment_id, hostname, id, last_verified_at, status, updated_at].hash
415
+ end
416
+
417
+ # Builds the object from hash
418
+ # @param [Hash] attributes Model attributes in the form of hash
419
+ # @return [Object] Returns the model itself
420
+ def self.build_from_hash(attributes)
421
+ return nil unless attributes.is_a?(Hash)
422
+ attributes = attributes.transform_keys(&:to_sym)
423
+ transformed_hash = {}
424
+ openapi_types.each_pair do |key, type|
425
+ if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
426
+ transformed_hash["#{key}"] = nil
427
+ elsif type =~ /\AArray<(.*)>/i
428
+ # check to ensure the input is an array given that the attribute
429
+ # is documented as an array but the input is not
430
+ if attributes[attribute_map[key]].is_a?(Array)
431
+ transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
432
+ end
433
+ elsif !attributes[attribute_map[key]].nil?
434
+ transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
435
+ end
436
+ end
437
+ new(transformed_hash)
438
+ end
439
+
440
+ # Deserializes the data based on type
441
+ # @param string type Data type
442
+ # @param string value Value to be deserialized
443
+ # @return [Object] Deserialized data
444
+ def self._deserialize(type, value)
445
+ case type.to_sym
446
+ when :Time
447
+ Time.parse(value)
448
+ when :Date
449
+ Date.parse(value)
450
+ when :String
451
+ value.to_s
452
+ when :Integer
453
+ value.to_i
454
+ when :Float
455
+ value.to_f
456
+ when :Boolean
457
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
458
+ true
459
+ else
460
+ false
461
+ end
462
+ when :Object
463
+ # generic object (usually a Hash), return directly
464
+ value
465
+ when /\AArray<(?<inner_type>.+)>\z/
466
+ inner_type = Regexp.last_match[:inner_type]
467
+ value.map { |v| _deserialize(inner_type, v) }
468
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
469
+ k_type = Regexp.last_match[:k_type]
470
+ v_type = Regexp.last_match[:v_type]
471
+ {}.tap do |hash|
472
+ value.each do |k, v|
473
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
474
+ end
475
+ end
476
+ else # model
477
+ # models (e.g. Pet) or oneOf
478
+ klass = ImgwireGenerated.const_get(type)
479
+ klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
480
+ end
481
+ end
482
+
483
+ # Returns the string representation of the object
484
+ # @return [String] String presentation of the object
485
+ def to_s
486
+ to_hash.to_s
487
+ end
488
+
489
+ # to_body is an alias to to_hash (backward compatibility)
490
+ # @return [Hash] Returns the object in the form of hash
491
+ def to_body
492
+ to_hash
493
+ end
494
+
495
+ # Returns the object in the form of hash
496
+ # @return [Hash] Returns the object in the form of hash
497
+ def to_hash
498
+ hash = {}
499
+ self.class.attribute_map.each_pair do |attr, param|
500
+ value = self.send(attr)
501
+ if value.nil?
502
+ is_nullable = self.class.openapi_nullable.include?(attr)
503
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
504
+ end
505
+
506
+ hash[param] = _to_hash(value)
507
+ end
508
+ hash
509
+ end
510
+
511
+ # Outputs non-array value in the form of hash
512
+ # For object, use to_hash. Otherwise, just return the value
513
+ # @param [Object] value Any valid value
514
+ # @return [Hash] Returns the value in the form of hash
515
+ def _to_hash(value)
516
+ if value.is_a?(Array)
517
+ value.compact.map { |v| _to_hash(v) }
518
+ elsif value.is_a?(Hash)
519
+ {}.tap do |hash|
520
+ value.each { |k, v| hash[k] = _to_hash(v) }
521
+ end
522
+ elsif value.respond_to? :to_hash
523
+ value.to_hash
524
+ else
525
+ value
526
+ end
527
+ end
528
+
529
+ end
530
+
531
+ end
@@ -0,0 +1,41 @@
1
+ =begin
2
+ #imgwire.dev Backend API development
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 0.1.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 ImgwireGenerated
17
+ class CustomDomainStatus
18
+ PENDING = "PENDING".freeze
19
+ CONNECTED = "CONNECTED".freeze
20
+ FAILED = "FAILED".freeze
21
+
22
+ def self.all_vars
23
+ @all_vars ||= [PENDING, CONNECTED, FAILED].freeze
24
+ end
25
+
26
+ # Builds the enum from string
27
+ # @param [String] The enum value in the form of the string
28
+ # @return [String] The enum value
29
+ def self.build_from_hash(value)
30
+ new.build_from_hash(value)
31
+ end
32
+
33
+ # Builds the enum from string
34
+ # @param [String] The enum value in the form of the string
35
+ # @return [String] The enum value
36
+ def build_from_hash(value)
37
+ return value if CustomDomainStatus.all_vars.include?(value)
38
+ raise "Invalid ENUM value #{value} for class #CustomDomainStatus"
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,106 @@
1
+ =begin
2
+ #imgwire.dev Backend API development
3
+
4
+ #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5
+
6
+ The version of the OpenAPI document: 0.1.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 ImgwireGenerated
17
+ module CustomMetadataValue
18
+ class << self
19
+ # List of class defined in anyOf (OpenAPI v3)
20
+ def openapi_any_of
21
+ [
22
+ :'Boolean',
23
+ :'Float',
24
+ :'Integer',
25
+ :'String'
26
+ ]
27
+ end
28
+
29
+ # Builds the object
30
+ # @param [Mixed] Data to be matched against the list of anyOf items
31
+ # @return [Object] Returns the model or the data itself
32
+ def build(data)
33
+ # Go through the list of anyOf items and attempt to identify the appropriate one.
34
+ # Note:
35
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
36
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
37
+ # - TODO: scalar values are de facto behaving as if they were nullable.
38
+ # - TODO: logging when debugging is set.
39
+ openapi_any_of.each do |klass|
40
+ begin
41
+ next if klass == :AnyType # "nullable: true"
42
+ typed_data = find_and_cast_into_type(klass, data)
43
+ return typed_data if typed_data
44
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
45
+ end
46
+ end
47
+
48
+ openapi_any_of.include?(:AnyType) ? data : nil
49
+ end
50
+
51
+ private
52
+
53
+ SchemaMismatchError = Class.new(StandardError)
54
+
55
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
56
+ def find_and_cast_into_type(klass, data)
57
+ return if data.nil?
58
+
59
+ case klass.to_s
60
+ when 'Boolean'
61
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
62
+ when 'Float'
63
+ return data if data.instance_of?(Float)
64
+ when 'Integer'
65
+ return data if data.instance_of?(Integer)
66
+ when 'Time'
67
+ return Time.parse(data)
68
+ when 'Date'
69
+ return Date.iso8601(data)
70
+ when 'String'
71
+ return data if data.instance_of?(String)
72
+ when 'Object' # "type: object"
73
+ return data if data.instance_of?(Hash)
74
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
75
+ if data.instance_of?(Array)
76
+ sub_type = Regexp.last_match[:sub_type]
77
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
78
+ end
79
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
80
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
81
+ sub_type = Regexp.last_match[:sub_type]
82
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
83
+ end
84
+ else # model
85
+ const = ImgwireGenerated.const_get(klass)
86
+ if const
87
+ if const.respond_to?(:openapi_any_of) # nested anyOf model
88
+ model = const.build(data)
89
+ return model if model
90
+ else
91
+ # raise if data contains keys that are not known to the model
92
+ raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
93
+ model = const.build_from_hash(data)
94
+ return model if model
95
+ end
96
+ end
97
+ end
98
+
99
+ raise # if no match by now, raise
100
+ rescue
101
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
102
+ end
103
+ end
104
+ end
105
+
106
+ end