late-sdk 0.0.93 → 0.0.94

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d23b35d7dbf978a5d370f91f581010551c6c56cbd5daf4d974dec712d13be92
4
- data.tar.gz: 0c28393acbfdbbf8220d3ae624de8a9d7fcea396c1e24222b6ccde5856f2be64
3
+ metadata.gz: df932c23e88e3e6675ca38fcaefff7052a4da59d3eb923526297e4d9a2c1e3a6
4
+ data.tar.gz: 4a7c1e5fb67076512e24cc667f13cbbe49e13872c615b0cb76ba63079d7ab1f7
5
5
  SHA512:
6
- metadata.gz: 0cc37e3b98a08a8737973ff80ab89faf1f074546fd1a7c31e2a3e6fa22e8b78550b16deb26dcdf10736b564165c4a75670756f8c87108fc81f1a1175080b8dcc
7
- data.tar.gz: 60576597ac554438a6b2f5d7fa599d7d40bc53eeecaa1b085cafdc34b8c3c79354bdea9cc888f402fa3b8d4507dc8032a579ce41032ee6c18e1c42ae5fb69316
6
+ metadata.gz: fdf054f2ab97d4977f16f783c266969c59ff7d9fdc182570760ff43d744bf950c4bc3b6b8b702a6f094452bd01ae0a9b2d93c1fc0a9aeb17a9b4d01fc789efa1
7
+ data.tar.gz: 6cae037881482b4b672c25c987e3cd271202787d32745fc9b17c7c1d7dd6191a609a278cbfb0e04fbe8cfd734c684ef8d12d922733e530fc232d16028308b902
@@ -21,38 +21,6 @@ Late::WhatsAppTemplateComponent.openapi_one_of
21
21
  # ]
22
22
  ```
23
23
 
24
- ### `openapi_discriminator_name`
25
-
26
- Returns the discriminator's property name.
27
-
28
- #### Example
29
-
30
- ```ruby
31
- require 'late-sdk'
32
-
33
- Late::WhatsAppTemplateComponent.openapi_discriminator_name
34
- # => :'type'
35
- ```
36
-
37
- ### `openapi_discriminator_name`
38
-
39
- Returns the discriminator's mapping.
40
-
41
- #### Example
42
-
43
- ```ruby
44
- require 'late-sdk'
45
-
46
- Late::WhatsAppTemplateComponent.openapi_discriminator_mapping
47
- # =>
48
- # {
49
- # :'BODY' => :'WhatsAppBodyComponent',
50
- # :'BUTTONS' => :'WhatsAppButtonsComponent',
51
- # :'FOOTER' => :'WhatsAppFooterComponent',
52
- # :'HEADER' => :'WhatsAppHeaderComponent'
53
- # }
54
- ```
55
-
56
24
  ### build
57
25
 
58
26
  Find the appropriate object from the `openapi_one_of` list and casts the data into it.
@@ -125,11 +125,6 @@ module Late
125
125
  ])
126
126
  end
127
127
 
128
- # discriminator's property name in OpenAPI v3
129
- def self.openapi_discriminator_name
130
- :'type'
131
- end
132
-
133
128
  # Initializes the object
134
129
  # @param [Hash] attributes Model attributes in the form of hash
135
130
  def initialize(attributes = {})
@@ -26,32 +26,79 @@ module Late
26
26
  ]
27
27
  end
28
28
 
29
- # Discriminator's property name (OpenAPI v3)
30
- def openapi_discriminator_name
31
- :'type'
32
- end
33
-
34
- # Discriminator's mapping (OpenAPI v3)
35
- def openapi_discriminator_mapping
36
- {
37
- :'BODY' => :'WhatsAppBodyComponent',
38
- :'BUTTONS' => :'WhatsAppButtonsComponent',
39
- :'FOOTER' => :'WhatsAppFooterComponent',
40
- :'HEADER' => :'WhatsAppHeaderComponent'
41
- }
42
- end
43
-
44
29
  # Builds the object
45
30
  # @param [Mixed] Data to be matched against the list of oneOf items
46
31
  # @return [Object] Returns the model or the data itself
47
32
  def build(data)
48
- discriminator_value = data[openapi_discriminator_name]
49
- return nil if discriminator_value.nil?
33
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
34
+ # Note:
35
+ # - We do not attempt to check whether exactly one item matches.
36
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
37
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
38
+ # - TODO: scalar values are de facto behaving as if they were nullable.
39
+ # - TODO: logging when debugging is set.
40
+ openapi_one_of.each do |klass|
41
+ begin
42
+ next if klass == :AnyType # "nullable: true"
43
+ return find_and_cast_into_type(klass, data)
44
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
45
+ end
46
+ end
47
+
48
+ openapi_one_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?
50
58
 
51
- klass = openapi_discriminator_mapping[discriminator_value.to_s.to_sym]
52
- return nil unless klass
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 = Late.const_get(klass)
86
+ if const
87
+ if const.respond_to?(:openapi_one_of) # nested oneOf 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
53
98
 
54
- Late.const_get(klass).build_from_hash(data)
99
+ raise # if no match by now, raise
100
+ rescue
101
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
55
102
  end
56
103
  end
57
104
  end
@@ -11,5 +11,5 @@ Generator version: 7.19.0
11
11
  =end
12
12
 
13
13
  module Late
14
- VERSION = '0.0.93'
14
+ VERSION = '0.0.94'
15
15
  end
data/openapi.yaml CHANGED
@@ -349,21 +349,12 @@ components:
349
349
  type: string
350
350
  navigate_screen:
351
351
  type: string
352
- discriminator:
353
- propertyName: type
354
352
  WhatsAppTemplateComponent:
355
353
  oneOf:
356
354
  - $ref: '#/components/schemas/WhatsAppHeaderComponent'
357
355
  - $ref: '#/components/schemas/WhatsAppBodyComponent'
358
356
  - $ref: '#/components/schemas/WhatsAppFooterComponent'
359
357
  - $ref: '#/components/schemas/WhatsAppButtonsComponent'
360
- discriminator:
361
- propertyName: type
362
- mapping:
363
- HEADER: '#/components/schemas/WhatsAppHeaderComponent'
364
- BODY: '#/components/schemas/WhatsAppBodyComponent'
365
- FOOTER: '#/components/schemas/WhatsAppFooterComponent'
366
- BUTTONS: '#/components/schemas/WhatsAppButtonsComponent'
367
358
  WhatsAppHeaderComponent:
368
359
  type: object
369
360
  required: [type, format]
@@ -24,18 +24,6 @@ describe Late::WhatsAppTemplateComponent do
24
24
  end
25
25
  end
26
26
 
27
- describe '.openapi_discriminator_name' do
28
- it 'returns the value of the "discriminator" property' do
29
- expect(described_class.openapi_discriminator_name).to_not be_empty
30
- end
31
- end
32
-
33
- describe '.openapi_discriminator_mapping' do
34
- it 'returns the key/values of the "mapping" property' do
35
- expect(described_class.openapi_discriminator_mapping.values.sort).to eq(described_class.openapi_one_of.sort)
36
- end
37
- end
38
-
39
27
  describe '.build' do
40
28
  it 'returns the correct model' do
41
29
  # assertion here. ref: https://rspec.info/features/3-12/rspec-expectations/built-in-matchers/
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: late-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.93
4
+ version: 0.0.94
5
5
  platform: ruby
6
6
  authors:
7
7
  - OpenAPI-Generator
@@ -2247,7 +2247,7 @@ files:
2247
2247
  - spec/models/you_tube_scope_missing_response_scope_status_spec.rb
2248
2248
  - spec/models/you_tube_scope_missing_response_spec.rb
2249
2249
  - spec/spec_helper.rb
2250
- - zernio-sdk-0.0.93.gem
2250
+ - zernio-sdk-0.0.94.gem
2251
2251
  homepage: https://openapi-generator.tech
2252
2252
  licenses:
2253
2253
  - Unlicense
Binary file