kinde_sdk 1.6.6 → 1.7.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 (52) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/kinde_sdk/auth_controller.rb +96 -13
  3. data/kinde_api/lib/kinde_api/api/frontend/billing_api.rb +148 -0
  4. data/kinde_api/lib/kinde_api/api/frontend/feature_flags_api.rb +85 -0
  5. data/kinde_api/lib/kinde_api/api/frontend/o_auth_api.rb +241 -0
  6. data/kinde_api/lib/kinde_api/api/frontend/permissions_api.rb +85 -0
  7. data/kinde_api/lib/kinde_api/api/frontend/properties_api.rb +85 -0
  8. data/kinde_api/lib/kinde_api/api/frontend/roles_api.rb +85 -0
  9. data/kinde_api/lib/kinde_api/api/frontend/self_serve_portal_api.rb +89 -0
  10. data/kinde_api/lib/kinde_api/models/frontend/error.rb +230 -0
  11. data/kinde_api/lib/kinde_api/models/frontend/error_response.rb +221 -0
  12. data/kinde_api/lib/kinde_api/models/frontend/get_entitlement_response.rb +228 -0
  13. data/kinde_api/lib/kinde_api/models/frontend/get_entitlement_response_data.rb +229 -0
  14. data/kinde_api/lib/kinde_api/models/frontend/get_entitlement_response_data_entitlement.rb +295 -0
  15. data/kinde_api/lib/kinde_api/models/frontend/get_entitlements_response.rb +228 -0
  16. data/kinde_api/lib/kinde_api/models/frontend/get_entitlements_response_data.rb +244 -0
  17. data/kinde_api/lib/kinde_api/models/frontend/get_entitlements_response_data_entitlements_inner.rb +294 -0
  18. data/kinde_api/lib/kinde_api/models/frontend/get_entitlements_response_data_plans_inner.rb +240 -0
  19. data/kinde_api/lib/kinde_api/models/frontend/get_entitlements_response_metadata.rb +230 -0
  20. data/kinde_api/lib/kinde_api/models/frontend/get_feature_flags_response.rb +219 -0
  21. data/kinde_api/lib/kinde_api/models/frontend/get_feature_flags_response_data.rb +222 -0
  22. data/kinde_api/lib/kinde_api/models/frontend/get_feature_flags_response_data_feature_flags_inner.rb +259 -0
  23. data/kinde_api/lib/kinde_api/models/frontend/get_feature_flags_response_data_feature_flags_inner_value.rb +108 -0
  24. data/kinde_api/lib/kinde_api/models/frontend/get_user_permissions_response.rb +228 -0
  25. data/kinde_api/lib/kinde_api/models/frontend/get_user_permissions_response_data.rb +232 -0
  26. data/kinde_api/lib/kinde_api/models/frontend/get_user_permissions_response_data_permissions_inner.rb +240 -0
  27. data/kinde_api/lib/kinde_api/models/frontend/get_user_permissions_response_metadata.rb +230 -0
  28. data/kinde_api/lib/kinde_api/models/frontend/get_user_properties_response.rb +228 -0
  29. data/kinde_api/lib/kinde_api/models/frontend/get_user_properties_response_data.rb +222 -0
  30. data/kinde_api/lib/kinde_api/models/frontend/get_user_properties_response_data_properties_inner.rb +249 -0
  31. data/kinde_api/lib/kinde_api/models/frontend/get_user_properties_response_data_properties_inner_value.rb +107 -0
  32. data/kinde_api/lib/kinde_api/models/frontend/get_user_properties_response_metadata.rb +230 -0
  33. data/kinde_api/lib/kinde_api/models/frontend/get_user_roles_response.rb +228 -0
  34. data/kinde_api/lib/kinde_api/models/frontend/get_user_roles_response_data.rb +232 -0
  35. data/kinde_api/lib/kinde_api/models/frontend/get_user_roles_response_data_roles_inner.rb +240 -0
  36. data/kinde_api/lib/kinde_api/models/frontend/get_user_roles_response_metadata.rb +230 -0
  37. data/kinde_api/lib/kinde_api/models/frontend/portal_link.rb +220 -0
  38. data/kinde_api/lib/kinde_api/models/frontend/token_error_response.rb +230 -0
  39. data/kinde_api/lib/kinde_api/models/frontend/token_introspect.rb +262 -0
  40. data/kinde_api/lib/kinde_api/models/frontend/user_profile_v2.rb +323 -0
  41. data/kinde_api/lib/kinde_api.rb +28 -0
  42. data/lib/kinde_sdk/client/entitlements.rb +86 -0
  43. data/lib/kinde_sdk/client/feature_flags.rb +246 -10
  44. data/lib/kinde_sdk/client/permissions.rb +197 -6
  45. data/lib/kinde_sdk/client/roles.rb +218 -0
  46. data/lib/kinde_sdk/client.rb +242 -3
  47. data/lib/kinde_sdk/configuration.rb +2 -0
  48. data/lib/kinde_sdk/errors.rb +7 -0
  49. data/lib/kinde_sdk/internal/frontend_client.rb +111 -0
  50. data/lib/kinde_sdk/version.rb +1 -1
  51. data/lib/kinde_sdk.rb +9 -2
  52. metadata +54 -12
@@ -0,0 +1,222 @@
1
+ =begin
2
+ #Kinde Account API
3
+
4
+ # Provides endpoints to operate on an authenticated user. ## Intro ## How to use 1. Get a user access token - this can be obtained when a user signs in via the methods you've setup in Kinde (e.g. Google, passwordless, etc). 2. Call one of the endpoints below using the user access token in the Authorization header as a Bearer token. Typically, you can use the `getToken` command in the relevant SDK.
5
+
6
+ The version of the OpenAPI document: 1
7
+ Contact: support@kinde.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module KindeApi::Frontend
17
+ class GetFeatureFlagsResponseData
18
+ # A list of feature flags
19
+ attr_accessor :feature_flags
20
+
21
+ # Attribute mapping from ruby-style variable name to JSON key.
22
+ def self.attribute_map
23
+ {
24
+ :'feature_flags' => :'feature_flags'
25
+ }
26
+ end
27
+
28
+ # Returns all the JSON keys this model knows about
29
+ def self.acceptable_attributes
30
+ attribute_map.values
31
+ end
32
+
33
+ # Attribute type mapping.
34
+ def self.openapi_types
35
+ {
36
+ :'feature_flags' => :'Array<GetFeatureFlagsResponseDataFeatureFlagsInner>'
37
+ }
38
+ end
39
+
40
+ # List of attributes with nullable: true
41
+ def self.openapi_nullable
42
+ Set.new([
43
+ ])
44
+ end
45
+
46
+ # Initializes the object
47
+ # @param [Hash] attributes Model attributes in the form of hash
48
+ def initialize(attributes = {})
49
+ if (!attributes.is_a?(Hash))
50
+ fail ArgumentError, "The input argument (attributes) must be a hash in `KindeApi::Frontend::GetFeatureFlagsResponseData` initialize method"
51
+ end
52
+
53
+ # check to see if the attribute exists and convert string to symbol for hash key
54
+ attributes = attributes.each_with_object({}) { |(k, v), h|
55
+ if (!self.class.attribute_map.key?(k.to_sym))
56
+ fail ArgumentError, "`#{k}` is not a valid attribute in `KindeApi::Frontend::GetFeatureFlagsResponseData`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
57
+ end
58
+ h[k.to_sym] = v
59
+ }
60
+
61
+ if attributes.key?(:'feature_flags')
62
+ if (value = attributes[:'feature_flags']).is_a?(Array)
63
+ self.feature_flags = value
64
+ end
65
+ end
66
+ end
67
+
68
+ # Show invalid properties with the reasons. Usually used together with valid?
69
+ # @return Array for valid properties with the reasons
70
+ def list_invalid_properties
71
+ invalid_properties = Array.new
72
+ invalid_properties
73
+ end
74
+
75
+ # Check to see if the all the properties in the model are valid
76
+ # @return true if the model is valid
77
+ def valid?
78
+ true
79
+ end
80
+
81
+ # Checks equality by comparing each attribute.
82
+ # @param [Object] Object to be compared
83
+ def ==(o)
84
+ return true if self.equal?(o)
85
+ self.class == o.class &&
86
+ feature_flags == o.feature_flags
87
+ end
88
+
89
+ # @see the `==` method
90
+ # @param [Object] Object to be compared
91
+ def eql?(o)
92
+ self == o
93
+ end
94
+
95
+ # Calculates hash code according to all attributes.
96
+ # @return [Integer] Hash code
97
+ def hash
98
+ [feature_flags].hash
99
+ end
100
+
101
+ # Builds the object from hash
102
+ # @param [Hash] attributes Model attributes in the form of hash
103
+ # @return [Object] Returns the model itself
104
+ def self.build_from_hash(attributes)
105
+ new.build_from_hash(attributes)
106
+ end
107
+
108
+ # Builds the object from hash
109
+ # @param [Hash] attributes Model attributes in the form of hash
110
+ # @return [Object] Returns the model itself
111
+ def build_from_hash(attributes)
112
+ return nil unless attributes.is_a?(Hash)
113
+ attributes = attributes.transform_keys(&:to_sym)
114
+ self.class.openapi_types.each_pair do |key, type|
115
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
116
+ self.send("#{key}=", nil)
117
+ elsif type =~ /\AArray<(.*)>/i
118
+ # check to ensure the input is an array given that the attribute
119
+ # is documented as an array but the input is not
120
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
121
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
122
+ end
123
+ elsif !attributes[self.class.attribute_map[key]].nil?
124
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
125
+ end
126
+ end
127
+
128
+ self
129
+ end
130
+
131
+ # Deserializes the data based on type
132
+ # @param string type Data type
133
+ # @param string value Value to be deserialized
134
+ # @return [Object] Deserialized data
135
+ def _deserialize(type, value)
136
+ case type.to_sym
137
+ when :Time
138
+ Time.parse(value)
139
+ when :Date
140
+ Date.parse(value)
141
+ when :String
142
+ value.to_s
143
+ when :Integer
144
+ value.to_i
145
+ when :Float
146
+ value.to_f
147
+ when :Boolean
148
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
149
+ true
150
+ else
151
+ false
152
+ end
153
+ when :Object
154
+ # generic object (usually a Hash), return directly
155
+ value
156
+ when /\AArray<(?<inner_type>.+)>\z/
157
+ inner_type = Regexp.last_match[:inner_type]
158
+ value.map { |v| _deserialize(inner_type, v) }
159
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
160
+ k_type = Regexp.last_match[:k_type]
161
+ v_type = Regexp.last_match[:v_type]
162
+ {}.tap do |hash|
163
+ value.each do |k, v|
164
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
165
+ end
166
+ end
167
+ else # model
168
+ # models (e.g. Pet) or oneOf
169
+ klass = KindeFrontendApi.const_get(type)
170
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
171
+ end
172
+ end
173
+
174
+ # Returns the string representation of the object
175
+ # @return [String] String presentation of the object
176
+ def to_s
177
+ to_hash.to_s
178
+ end
179
+
180
+ # to_body is an alias to to_hash (backward compatibility)
181
+ # @return [Hash] Returns the object in the form of hash
182
+ def to_body
183
+ to_hash
184
+ end
185
+
186
+ # Returns the object in the form of hash
187
+ # @return [Hash] Returns the object in the form of hash
188
+ def to_hash
189
+ hash = {}
190
+ self.class.attribute_map.each_pair do |attr, param|
191
+ value = self.send(attr)
192
+ if value.nil?
193
+ is_nullable = self.class.openapi_nullable.include?(attr)
194
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
195
+ end
196
+
197
+ hash[param] = _to_hash(value)
198
+ end
199
+ hash
200
+ end
201
+
202
+ # Outputs non-array value in the form of hash
203
+ # For object, use to_hash. Otherwise, just return the value
204
+ # @param [Object] value Any valid value
205
+ # @return [Hash] Returns the value in the form of hash
206
+ def _to_hash(value)
207
+ if value.is_a?(Array)
208
+ value.compact.map { |v| _to_hash(v) }
209
+ elsif value.is_a?(Hash)
210
+ {}.tap do |hash|
211
+ value.each { |k, v| hash[k] = _to_hash(v) }
212
+ end
213
+ elsif value.respond_to? :to_hash
214
+ value.to_hash
215
+ else
216
+ value
217
+ end
218
+ end
219
+
220
+ end
221
+
222
+ end
@@ -0,0 +1,259 @@
1
+ =begin
2
+ #Kinde Account API
3
+
4
+ # Provides endpoints to operate on an authenticated user. ## Intro ## How to use 1. Get a user access token - this can be obtained when a user signs in via the methods you've setup in Kinde (e.g. Google, passwordless, etc). 2. Call one of the endpoints below using the user access token in the Authorization header as a Bearer token. Typically, you can use the `getToken` command in the relevant SDK.
5
+
6
+ The version of the OpenAPI document: 1
7
+ Contact: support@kinde.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module KindeApi::Frontend
17
+ class GetFeatureFlagsResponseDataFeatureFlagsInner
18
+ # The friendly ID of an flag
19
+ attr_accessor :id
20
+
21
+ # The name of the flag
22
+ attr_accessor :name
23
+
24
+ # The key of the flag
25
+ attr_accessor :key
26
+
27
+ # The type of the flag
28
+ attr_accessor :type
29
+
30
+ attr_accessor :value
31
+
32
+ # Attribute mapping from ruby-style variable name to JSON key.
33
+ def self.attribute_map
34
+ {
35
+ :'id' => :'id',
36
+ :'name' => :'name',
37
+ :'key' => :'key',
38
+ :'type' => :'type',
39
+ :'value' => :'value'
40
+ }
41
+ end
42
+
43
+ # Returns all the JSON keys this model knows about
44
+ def self.acceptable_attributes
45
+ attribute_map.values
46
+ end
47
+
48
+ # Attribute type mapping.
49
+ def self.openapi_types
50
+ {
51
+ :'id' => :'String',
52
+ :'name' => :'String',
53
+ :'key' => :'String',
54
+ :'type' => :'String',
55
+ :'value' => :'GetFeatureFlagsResponseDataFeatureFlagsInnerValue'
56
+ }
57
+ end
58
+
59
+ # List of attributes with nullable: true
60
+ def self.openapi_nullable
61
+ Set.new([
62
+ ])
63
+ end
64
+
65
+ # Initializes the object
66
+ # @param [Hash] attributes Model attributes in the form of hash
67
+ def initialize(attributes = {})
68
+ if (!attributes.is_a?(Hash))
69
+ fail ArgumentError, "The input argument (attributes) must be a hash in `KindeApi::Frontend::GetFeatureFlagsResponseDataFeatureFlagsInner` initialize method"
70
+ end
71
+
72
+ # check to see if the attribute exists and convert string to symbol for hash key
73
+ attributes = attributes.each_with_object({}) { |(k, v), h|
74
+ if (!self.class.attribute_map.key?(k.to_sym))
75
+ fail ArgumentError, "`#{k}` is not a valid attribute in `KindeApi::Frontend::GetFeatureFlagsResponseDataFeatureFlagsInner`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
76
+ end
77
+ h[k.to_sym] = v
78
+ }
79
+
80
+ if attributes.key?(:'id')
81
+ self.id = attributes[:'id']
82
+ end
83
+
84
+ if attributes.key?(:'name')
85
+ self.name = attributes[:'name']
86
+ end
87
+
88
+ if attributes.key?(:'key')
89
+ self.key = attributes[:'key']
90
+ end
91
+
92
+ if attributes.key?(:'type')
93
+ self.type = attributes[:'type']
94
+ end
95
+
96
+ if attributes.key?(:'value')
97
+ self.value = attributes[:'value']
98
+ end
99
+ end
100
+
101
+ # Show invalid properties with the reasons. Usually used together with valid?
102
+ # @return Array for valid properties with the reasons
103
+ def list_invalid_properties
104
+ invalid_properties = Array.new
105
+ invalid_properties
106
+ end
107
+
108
+ # Check to see if the all the properties in the model are valid
109
+ # @return true if the model is valid
110
+ def valid?
111
+ true
112
+ end
113
+
114
+ # Checks equality by comparing each attribute.
115
+ # @param [Object] Object to be compared
116
+ def ==(o)
117
+ return true if self.equal?(o)
118
+ self.class == o.class &&
119
+ id == o.id &&
120
+ name == o.name &&
121
+ key == o.key &&
122
+ type == o.type &&
123
+ value == o.value
124
+ end
125
+
126
+ # @see the `==` method
127
+ # @param [Object] Object to be compared
128
+ def eql?(o)
129
+ self == o
130
+ end
131
+
132
+ # Calculates hash code according to all attributes.
133
+ # @return [Integer] Hash code
134
+ def hash
135
+ [id, name, key, type, value].hash
136
+ end
137
+
138
+ # Builds the object from hash
139
+ # @param [Hash] attributes Model attributes in the form of hash
140
+ # @return [Object] Returns the model itself
141
+ def self.build_from_hash(attributes)
142
+ new.build_from_hash(attributes)
143
+ end
144
+
145
+ # Builds the object from hash
146
+ # @param [Hash] attributes Model attributes in the form of hash
147
+ # @return [Object] Returns the model itself
148
+ def build_from_hash(attributes)
149
+ return nil unless attributes.is_a?(Hash)
150
+ attributes = attributes.transform_keys(&:to_sym)
151
+ self.class.openapi_types.each_pair do |key, type|
152
+ if attributes[self.class.attribute_map[key]].nil? && self.class.openapi_nullable.include?(key)
153
+ self.send("#{key}=", nil)
154
+ elsif type =~ /\AArray<(.*)>/i
155
+ # check to ensure the input is an array given that the attribute
156
+ # is documented as an array but the input is not
157
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
158
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
159
+ end
160
+ elsif !attributes[self.class.attribute_map[key]].nil?
161
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
162
+ end
163
+ end
164
+
165
+ self
166
+ end
167
+
168
+ # Deserializes the data based on type
169
+ # @param string type Data type
170
+ # @param string value Value to be deserialized
171
+ # @return [Object] Deserialized data
172
+ def _deserialize(type, value)
173
+ case type.to_sym
174
+ when :Time
175
+ Time.parse(value)
176
+ when :Date
177
+ Date.parse(value)
178
+ when :String
179
+ value.to_s
180
+ when :Integer
181
+ value.to_i
182
+ when :Float
183
+ value.to_f
184
+ when :Boolean
185
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
186
+ true
187
+ else
188
+ false
189
+ end
190
+ when :Object
191
+ # generic object (usually a Hash), return directly
192
+ value
193
+ when /\AArray<(?<inner_type>.+)>\z/
194
+ inner_type = Regexp.last_match[:inner_type]
195
+ value.map { |v| _deserialize(inner_type, v) }
196
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
197
+ k_type = Regexp.last_match[:k_type]
198
+ v_type = Regexp.last_match[:v_type]
199
+ {}.tap do |hash|
200
+ value.each do |k, v|
201
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
202
+ end
203
+ end
204
+ else # model
205
+ # models (e.g. Pet) or oneOf
206
+ klass = KindeFrontendApi.const_get(type)
207
+ klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
208
+ end
209
+ end
210
+
211
+ # Returns the string representation of the object
212
+ # @return [String] String presentation of the object
213
+ def to_s
214
+ to_hash.to_s
215
+ end
216
+
217
+ # to_body is an alias to to_hash (backward compatibility)
218
+ # @return [Hash] Returns the object in the form of hash
219
+ def to_body
220
+ to_hash
221
+ end
222
+
223
+ # Returns the object in the form of hash
224
+ # @return [Hash] Returns the object in the form of hash
225
+ def to_hash
226
+ hash = {}
227
+ self.class.attribute_map.each_pair do |attr, param|
228
+ value = self.send(attr)
229
+ if value.nil?
230
+ is_nullable = self.class.openapi_nullable.include?(attr)
231
+ next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}"))
232
+ end
233
+
234
+ hash[param] = _to_hash(value)
235
+ end
236
+ hash
237
+ end
238
+
239
+ # Outputs non-array value in the form of hash
240
+ # For object, use to_hash. Otherwise, just return the value
241
+ # @param [Object] value Any valid value
242
+ # @return [Hash] Returns the value in the form of hash
243
+ def _to_hash(value)
244
+ if value.is_a?(Array)
245
+ value.compact.map { |v| _to_hash(v) }
246
+ elsif value.is_a?(Hash)
247
+ {}.tap do |hash|
248
+ value.each { |k, v| hash[k] = _to_hash(v) }
249
+ end
250
+ elsif value.respond_to? :to_hash
251
+ value.to_hash
252
+ else
253
+ value
254
+ end
255
+ end
256
+
257
+ end
258
+
259
+ end
@@ -0,0 +1,108 @@
1
+ =begin
2
+ #Kinde Account API
3
+
4
+ # Provides endpoints to operate on an authenticated user. ## Intro ## How to use 1. Get a user access token - this can be obtained when a user signs in via the methods you've setup in Kinde (e.g. Google, passwordless, etc). 2. Call one of the endpoints below using the user access token in the Authorization header as a Bearer token. Typically, you can use the `getToken` command in the relevant SDK.
5
+
6
+ The version of the OpenAPI document: 1
7
+ Contact: support@kinde.com
8
+ Generated by: https://openapi-generator.tech
9
+ OpenAPI Generator version: 6.4.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module KindeApi::Frontend
17
+ # The value of the flag
18
+ module GetFeatureFlagsResponseDataFeatureFlagsInnerValue
19
+ class << self
20
+ # List of class defined in oneOf (OpenAPI v3)
21
+ def openapi_one_of
22
+ [
23
+ :'Boolean',
24
+ :'Integer',
25
+ :'Object',
26
+ :'String'
27
+ ]
28
+ end
29
+
30
+ # Builds the object
31
+ # @param [Mixed] Data to be matched against the list of oneOf items
32
+ # @return [Object] Returns the model or the data itself
33
+ def build(data)
34
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
35
+ # Note:
36
+ # - We do not attempt to check whether exactly one item matches.
37
+ # - No advanced validation of types in some cases (e.g. "x: { type: string }" will happily match { x: 123 })
38
+ # due to the way the deserialization is made in the base_object template (it just casts without verifying).
39
+ # - TODO: scalar values are de facto behaving as if they were nullable.
40
+ # - TODO: logging when debugging is set.
41
+ openapi_one_of.each do |klass|
42
+ begin
43
+ next if klass == :AnyType # "nullable: true"
44
+ typed_data = find_and_cast_into_type(klass, data)
45
+ return typed_data if typed_data
46
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
47
+ end
48
+ end
49
+
50
+ openapi_one_of.include?(:AnyType) ? data : nil
51
+ end
52
+
53
+ private
54
+
55
+ SchemaMismatchError = Class.new(StandardError)
56
+
57
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
58
+ def find_and_cast_into_type(klass, data)
59
+ return if data.nil?
60
+
61
+ case klass.to_s
62
+ when 'Boolean'
63
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
64
+ when 'Float'
65
+ return data if data.instance_of?(Float)
66
+ when 'Integer'
67
+ return data if data.instance_of?(Integer)
68
+ when 'Time'
69
+ return Time.parse(data)
70
+ when 'Date'
71
+ return Date.parse(data)
72
+ when 'String'
73
+ return data if data.instance_of?(String)
74
+ when 'Object' # "type: object"
75
+ return data if data.instance_of?(Hash)
76
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
77
+ if data.instance_of?(Array)
78
+ sub_type = Regexp.last_match[:sub_type]
79
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
80
+ end
81
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
82
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
83
+ sub_type = Regexp.last_match[:sub_type]
84
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
85
+ end
86
+ else # model
87
+ const = KindeFrontendApi.const_get(klass)
88
+ if const
89
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
90
+ model = const.build(data)
91
+ return model if model
92
+ else
93
+ # raise if data contains keys that are not known to the model
94
+ raise unless (data.keys - const.acceptable_attributes).empty?
95
+ model = const.build_from_hash(data)
96
+ return model if model && model.valid?
97
+ end
98
+ end
99
+ end
100
+
101
+ raise # if no match by now, raise
102
+ rescue
103
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
104
+ end
105
+ end
106
+ end
107
+
108
+ end