late-sdk 0.0.572 → 0.0.574

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 (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +10 -0
  3. data/docs/AdAccountsApi.md +1 -1
  4. data/docs/CreateLeadFormRequest.md +13 -11
  5. data/docs/CreateLeadFormRequestPlatformSpecificData.md +49 -0
  6. data/docs/LeadGenApi.md +25 -21
  7. data/docs/LinkedInLeadFormPlatformData.md +30 -0
  8. data/docs/LinkedInLeadFormPlatformDataConsentsInner.md +20 -0
  9. data/docs/LinkedInLeadFormPlatformDataLocale.md +20 -0
  10. data/docs/LinkedInLeadFormPlatformDataQuestionsInner.md +49 -0
  11. data/docs/LinkedInLeadFormPlatformDataQuestionsInnerOneOf.md +28 -0
  12. data/docs/LinkedInLeadFormPlatformDataQuestionsInnerOneOf1.md +28 -0
  13. data/docs/LinkedInLeadFormPlatformDataQuestionsInnerOneOf1ChoicesInner.md +20 -0
  14. data/docs/MetaLeadFormPlatformData.md +46 -0
  15. data/docs/MetaLeadFormPlatformDataContextCard.md +26 -0
  16. data/lib/zernio-sdk/api/ad_accounts_api.rb +2 -2
  17. data/lib/zernio-sdk/api/lead_gen_api.rb +30 -24
  18. data/lib/zernio-sdk/models/create_lead_form_request.rb +25 -13
  19. data/lib/zernio-sdk/models/create_lead_form_request_platform_specific_data.rb +105 -0
  20. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data.rb +336 -0
  21. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_consents_inner.rb +176 -0
  22. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_locale.rb +156 -0
  23. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_questions_inner.rb +104 -0
  24. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_questions_inner_one_of.rb +268 -0
  25. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_questions_inner_one_of1.rb +295 -0
  26. data/lib/zernio-sdk/models/linked_in_lead_form_platform_data_questions_inner_one_of1_choices_inner.rb +190 -0
  27. data/lib/zernio-sdk/models/meta_lead_form_platform_data.rb +354 -0
  28. data/lib/zernio-sdk/models/meta_lead_form_platform_data_context_card.rb +219 -0
  29. data/lib/zernio-sdk/version.rb +1 -1
  30. data/lib/zernio-sdk.rb +10 -0
  31. data/openapi.yaml +146 -32
  32. data/spec/api/ad_accounts_api_spec.rb +1 -1
  33. data/spec/api/lead_gen_api_spec.rb +14 -12
  34. data/spec/models/create_lead_form_request_platform_specific_data_spec.rb +32 -0
  35. data/spec/models/create_lead_form_request_spec.rb +6 -0
  36. data/spec/models/linked_in_lead_form_platform_data_consents_inner_spec.rb +42 -0
  37. data/spec/models/linked_in_lead_form_platform_data_locale_spec.rb +42 -0
  38. data/spec/models/linked_in_lead_form_platform_data_questions_inner_one_of1_choices_inner_spec.rb +42 -0
  39. data/spec/models/linked_in_lead_form_platform_data_questions_inner_one_of1_spec.rb +70 -0
  40. data/spec/models/linked_in_lead_form_platform_data_questions_inner_one_of_spec.rb +70 -0
  41. data/spec/models/linked_in_lead_form_platform_data_questions_inner_spec.rb +32 -0
  42. data/spec/models/linked_in_lead_form_platform_data_spec.rb +76 -0
  43. data/spec/models/meta_lead_form_platform_data_context_card_spec.rb +64 -0
  44. data/spec/models/meta_lead_form_platform_data_spec.rb +124 -0
  45. data/zernio-sdk-0.0.574.gem +0 -0
  46. metadata +42 -2
  47. data/zernio-sdk-0.0.572.gem +0 -0
@@ -20,9 +20,9 @@ module Zernio
20
20
  @api_client = api_client
21
21
  end
22
22
  # Archive a lead form
23
- # Meta has no hard delete for forms; this archives the form (status=ARCHIVED).
24
- # @param form_id [String]
25
- # @param account_id [String]
23
+ # Neither platform hard-deletes a form; this archives it (Meta status=ARCHIVED; LinkedIn state=ARCHIVED via PARTIAL_UPDATE).
24
+ # @param form_id [String] Numeric form id (Meta leadgen_form id or LinkedIn leadForm id).
25
+ # @param account_id [String] Connected facebook or linkedin ads account id (selects the platform).
26
26
  # @param [Hash] opts the optional parameters
27
27
  # @return [ArchiveLeadForm200Response]
28
28
  def archive_lead_form(form_id, account_id, opts = {})
@@ -31,9 +31,9 @@ module Zernio
31
31
  end
32
32
 
33
33
  # Archive a lead form
34
- # Meta has no hard delete for forms; this archives the form (status=ARCHIVED).
35
- # @param form_id [String]
36
- # @param account_id [String]
34
+ # Neither platform hard-deletes a form; this archives it (Meta status=ARCHIVED; LinkedIn state=ARCHIVED via PARTIAL_UPDATE).
35
+ # @param form_id [String] Numeric form id (Meta leadgen_form id or LinkedIn leadForm id).
36
+ # @param account_id [String] Connected facebook or linkedin ads account id (selects the platform).
37
37
  # @param [Hash] opts the optional parameters
38
38
  # @return [Array<(ArchiveLeadForm200Response, Integer, Hash)>] ArchiveLeadForm200Response data, response status code and response headers
39
39
  def archive_lead_form_with_http_info(form_id, account_id, opts = {})
@@ -90,7 +90,7 @@ module Zernio
90
90
  end
91
91
 
92
92
  # Create a lead form
93
- # Creates a Lead Gen form on the connected Facebook Page (POST /{page-id}/leadgen_forms). NOT idempotent — a retry creates a second form. Prefilled question types (EMAIL, PHONE, FULL_NAME, …) must omit label/key; CUSTOM questions require both. Requires the Ads add-on.
93
+ # Creates a Lead Gen form. The form content goes inside `platformSpecificData` for both platforms (the shape is selected by the accountId's platform). Meta: created on the connected Facebook Page (POST /{page-id}/leadgen_forms); the old top-level Meta fields (questions, thankYou*, contextCard, …) are DEPRECATED but still accepted while platformSpecificData is absent — mixing both shapes is a 400. LinkedIn: created on the ad account's Company Page. NOT idempotent — a retry creates a second form. Meta prefilled question types (EMAIL, PHONE, FULL_NAME, …) must omit label/key; CUSTOM questions require both. LinkedIn exposes only free-text and multiple-choice questions via API (prefilled-from-profile fields are Campaign Manager UI-only). Requires the Ads add-on.
94
94
  # @param create_lead_form_request [CreateLeadFormRequest]
95
95
  # @param [Hash] opts the optional parameters
96
96
  # @return [CreateLeadForm200Response]
@@ -100,7 +100,7 @@ module Zernio
100
100
  end
101
101
 
102
102
  # Create a lead form
103
- # Creates a Lead Gen form on the connected Facebook Page (POST /{page-id}/leadgen_forms). NOT idempotent — a retry creates a second form. Prefilled question types (EMAIL, PHONE, FULL_NAME, …) must omit label/key; CUSTOM questions require both. Requires the Ads add-on.
103
+ # Creates a Lead Gen form. The form content goes inside &#x60;platformSpecificData&#x60; for both platforms (the shape is selected by the accountId&#39;s platform). Meta: created on the connected Facebook Page (POST /{page-id}/leadgen_forms); the old top-level Meta fields (questions, thankYou*, contextCard, …) are DEPRECATED but still accepted while platformSpecificData is absent — mixing both shapes is a 400. LinkedIn: created on the ad account&#39;s Company Page. NOT idempotent — a retry creates a second form. Meta prefilled question types (EMAIL, PHONE, FULL_NAME, …) must omit label/key; CUSTOM questions require both. LinkedIn exposes only free-text and multiple-choice questions via API (prefilled-from-profile fields are Campaign Manager UI-only). Requires the Ads add-on.
104
104
  # @param create_lead_form_request [CreateLeadFormRequest]
105
105
  # @param [Hash] opts the optional parameters
106
106
  # @return [Array<(CreateLeadForm200Response, Integer, Hash)>] CreateLeadForm200Response data, response status code and response headers
@@ -232,8 +232,8 @@ module Zernio
232
232
  end
233
233
 
234
234
  # Get a lead form
235
- # @param form_id [String]
236
- # @param account_id [String]
235
+ # @param form_id [String] Numeric form id (Meta leadgen_form id or LinkedIn leadForm id).
236
+ # @param account_id [String] Connected facebook or linkedin ads account id (selects the platform).
237
237
  # @param [Hash] opts the optional parameters
238
238
  # @return [GetLeadForm200Response]
239
239
  def get_lead_form(form_id, account_id, opts = {})
@@ -242,8 +242,8 @@ module Zernio
242
242
  end
243
243
 
244
244
  # Get a lead form
245
- # @param form_id [String]
246
- # @param account_id [String]
245
+ # @param form_id [String] Numeric form id (Meta leadgen_form id or LinkedIn leadForm id).
246
+ # @param account_id [String] Connected facebook or linkedin ads account id (selects the platform).
247
247
  # @param [Hash] opts the optional parameters
248
248
  # @return [Array<(GetLeadForm200Response, Integer, Hash)>] GetLeadForm200Response data, response status code and response headers
249
249
  def get_lead_form_with_http_info(form_id, account_id, opts = {})
@@ -387,9 +387,10 @@ module Zernio
387
387
  end
388
388
 
389
389
  # List lead forms
390
- # Lists the Lead Gen forms owned by the connected Facebook Page. Requires the Ads add-on.
391
- # @param account_id [String] Connected facebook account id.
390
+ # Lists the Lead Gen forms owned by the account. Meta: forms on the connected Facebook Page. LinkedIn: forms owned by the ad account's Company Page — pass `adAccountId` (LinkedIn forms are org-owned). Requires the Ads add-on.
391
+ # @param account_id [String] Connected facebook or linkedin ads account id.
392
392
  # @param [Hash] opts the optional parameters
393
+ # @option opts [String] :ad_account_id LinkedIn only: the LinkedIn ad account id (used to resolve the owning organization). Required for LinkedIn.
393
394
  # @option opts [Integer] :limit (default to 25)
394
395
  # @option opts [String] :cursor
395
396
  # @return [ListLeadForms200Response]
@@ -399,9 +400,10 @@ module Zernio
399
400
  end
400
401
 
401
402
  # List lead forms
402
- # Lists the Lead Gen forms owned by the connected Facebook Page. Requires the Ads add-on.
403
- # @param account_id [String] Connected facebook account id.
403
+ # Lists the Lead Gen forms owned by the account. Meta: forms on the connected Facebook Page. LinkedIn: forms owned by the ad account&#39;s Company Page — pass &#x60;adAccountId&#x60; (LinkedIn forms are org-owned). Requires the Ads add-on.
404
+ # @param account_id [String] Connected facebook or linkedin ads account id.
404
405
  # @param [Hash] opts the optional parameters
406
+ # @option opts [String] :ad_account_id LinkedIn only: the LinkedIn ad account id (used to resolve the owning organization). Required for LinkedIn.
405
407
  # @option opts [Integer] :limit (default to 25)
406
408
  # @option opts [String] :cursor
407
409
  # @return [Array<(ListLeadForms200Response, Integer, Hash)>] ListLeadForms200Response data, response status code and response headers
@@ -427,6 +429,7 @@ module Zernio
427
429
  # query parameters
428
430
  query_params = opts[:query_params] || {}
429
431
  query_params[:'accountId'] = account_id
432
+ query_params[:'adAccountId'] = opts[:'ad_account_id'] if !opts[:'ad_account_id'].nil?
430
433
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
431
434
  query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
432
435
 
@@ -465,13 +468,14 @@ module Zernio
465
468
  end
466
469
 
467
470
  # List submitted leads
468
- # Returns persisted Meta Lead Gen leads for your team, newest-first, with keyset pagination on `cursor`. Leads are ingested in real time from the `leadgen` webhook. Requires the Ads add-on.
471
+ # Returns submitted Lead Gen leads for your team, newest-first, with keyset pagination on `cursor`. For Meta (default) leads are served from the persisted cache, ingested in real time from the `leadgen` webhook. When `accountId` is a LinkedIn ads account, leads are fetched live from LinkedIn's `leadFormResponses` (LinkedIn has no webhook and enforces 90-day retention, so nothing is persisted) and `adAccountId` is required. Reading LinkedIn responses needs the `r_marketing_leadgen_automation` permission; accounts connected before it was added must reconnect. Requires the Ads add-on.
469
472
  # @param [Hash] opts the optional parameters
470
473
  # @option opts [String] :form_id Filter to a single lead form.
471
- # @option opts [String] :account_id Filter to a single connected account.
474
+ # @option opts [String] :account_id Filter to a single connected account. LinkedIn ads accounts switch to the live fetch.
475
+ # @option opts [String] :ad_account_id LinkedIn only: the LinkedIn ad account id whose responses to read (owner-scoped finder).
472
476
  # @option opts [Integer] :limit (default to 25)
473
- # @option opts [Integer] :since Unix seconds; only leads created at/after this Meta timestamp.
474
- # @option opts [String] :cursor Keyset cursor from a previous response&#39;s pagination.cursor.
477
+ # @option opts [Integer] :since Unix seconds; only leads created at/after this timestamp.
478
+ # @option opts [String] :cursor Keyset cursor from a previous response&#39;s pagination.cursor (Meta: AdLead id; LinkedIn: numeric start offset).
475
479
  # @return [ListLeads200Response]
476
480
  def list_leads(opts = {})
477
481
  data, _status_code, _headers = list_leads_with_http_info(opts)
@@ -479,13 +483,14 @@ module Zernio
479
483
  end
480
484
 
481
485
  # List submitted leads
482
- # Returns persisted Meta Lead Gen leads for your team, newest-first, with keyset pagination on &#x60;cursor&#x60;. Leads are ingested in real time from the &#x60;leadgen&#x60; webhook. Requires the Ads add-on.
486
+ # Returns submitted Lead Gen leads for your team, newest-first, with keyset pagination on &#x60;cursor&#x60;. For Meta (default) leads are served from the persisted cache, ingested in real time from the &#x60;leadgen&#x60; webhook. When &#x60;accountId&#x60; is a LinkedIn ads account, leads are fetched live from LinkedIn&#39;s &#x60;leadFormResponses&#x60; (LinkedIn has no webhook and enforces 90-day retention, so nothing is persisted) and &#x60;adAccountId&#x60; is required. Reading LinkedIn responses needs the &#x60;r_marketing_leadgen_automation&#x60; permission; accounts connected before it was added must reconnect. Requires the Ads add-on.
483
487
  # @param [Hash] opts the optional parameters
484
488
  # @option opts [String] :form_id Filter to a single lead form.
485
- # @option opts [String] :account_id Filter to a single connected account.
489
+ # @option opts [String] :account_id Filter to a single connected account. LinkedIn ads accounts switch to the live fetch.
490
+ # @option opts [String] :ad_account_id LinkedIn only: the LinkedIn ad account id whose responses to read (owner-scoped finder).
486
491
  # @option opts [Integer] :limit (default to 25)
487
- # @option opts [Integer] :since Unix seconds; only leads created at/after this Meta timestamp.
488
- # @option opts [String] :cursor Keyset cursor from a previous response&#39;s pagination.cursor.
492
+ # @option opts [Integer] :since Unix seconds; only leads created at/after this timestamp.
493
+ # @option opts [String] :cursor Keyset cursor from a previous response&#39;s pagination.cursor (Meta: AdLead id; LinkedIn: numeric start offset).
489
494
  # @return [Array<(ListLeads200Response, Integer, Hash)>] ListLeads200Response data, response status code and response headers
490
495
  def list_leads_with_http_info(opts = {})
491
496
  if @api_client.config.debugging
@@ -506,6 +511,7 @@ module Zernio
506
511
  query_params = opts[:query_params] || {}
507
512
  query_params[:'formId'] = opts[:'form_id'] if !opts[:'form_id'].nil?
508
513
  query_params[:'accountId'] = opts[:'account_id'] if !opts[:'account_id'].nil?
514
+ query_params[:'adAccountId'] = opts[:'ad_account_id'] if !opts[:'ad_account_id'].nil?
509
515
  query_params[:'limit'] = opts[:'limit'] if !opts[:'limit'].nil?
510
516
  query_params[:'since'] = opts[:'since'] if !opts[:'since'].nil?
511
517
  query_params[:'cursor'] = opts[:'cursor'] if !opts[:'cursor'].nil?
@@ -19,28 +19,40 @@ module Zernio
19
19
 
20
20
  attr_accessor :name
21
21
 
22
+ # Deprecated (Meta legacy shape): use platformSpecificData.questions.
22
23
  attr_accessor :questions
23
24
 
24
25
  attr_accessor :privacy_policy_url
25
26
 
27
+ # Deprecated: use platformSpecificData.privacyPolicyLinkText.
26
28
  attr_accessor :privacy_policy_link_text
27
29
 
30
+ # Deprecated: use platformSpecificData.followUpActionUrl.
28
31
  attr_accessor :follow_up_action_url
29
32
 
33
+ # Deprecated: use platformSpecificData.locale.
30
34
  attr_accessor :locale
31
35
 
36
+ # Deprecated: use platformSpecificData.thankYouTitle.
32
37
  attr_accessor :thank_you_title
33
38
 
39
+ # Deprecated: use platformSpecificData.thankYouBody.
34
40
  attr_accessor :thank_you_body
35
41
 
42
+ # Deprecated: use platformSpecificData.thankYouButtonText.
36
43
  attr_accessor :thank_you_button_text
37
44
 
45
+ # Deprecated: use platformSpecificData.thankYouButtonType.
38
46
  attr_accessor :thank_you_button_type
39
47
 
48
+ # Deprecated: use platformSpecificData.thankYouWebsiteUrl.
40
49
  attr_accessor :thank_you_website_url
41
50
 
51
+ # Deprecated: use platformSpecificData.isOptimizedForQuality.
42
52
  attr_accessor :is_optimized_for_quality
43
53
 
54
+ attr_accessor :platform_specific_data
55
+
44
56
  # Attribute mapping from ruby-style variable name to JSON key.
45
57
  def self.attribute_map
46
58
  {
@@ -56,7 +68,8 @@ module Zernio
56
68
  :'thank_you_button_text' => :'thankYouButtonText',
57
69
  :'thank_you_button_type' => :'thankYouButtonType',
58
70
  :'thank_you_website_url' => :'thankYouWebsiteUrl',
59
- :'is_optimized_for_quality' => :'isOptimizedForQuality'
71
+ :'is_optimized_for_quality' => :'isOptimizedForQuality',
72
+ :'platform_specific_data' => :'platformSpecificData'
60
73
  }
61
74
  end
62
75
 
@@ -85,7 +98,8 @@ module Zernio
85
98
  :'thank_you_button_text' => :'String',
86
99
  :'thank_you_button_type' => :'String',
87
100
  :'thank_you_website_url' => :'String',
88
- :'is_optimized_for_quality' => :'Boolean'
101
+ :'is_optimized_for_quality' => :'Boolean',
102
+ :'platform_specific_data' => :'CreateLeadFormRequestPlatformSpecificData'
89
103
  }
90
104
  end
91
105
 
@@ -127,8 +141,6 @@ module Zernio
127
141
  if (value = attributes[:'questions']).is_a?(Array)
128
142
  self.questions = value
129
143
  end
130
- else
131
- self.questions = nil
132
144
  end
133
145
 
134
146
  if attributes.key?(:'privacy_policy_url')
@@ -172,6 +184,10 @@ module Zernio
172
184
  if attributes.key?(:'is_optimized_for_quality')
173
185
  self.is_optimized_for_quality = attributes[:'is_optimized_for_quality']
174
186
  end
187
+
188
+ if attributes.key?(:'platform_specific_data')
189
+ self.platform_specific_data = attributes[:'platform_specific_data']
190
+ end
175
191
  end
176
192
 
177
193
  # Show invalid properties with the reasons. Usually used together with valid?
@@ -191,11 +207,7 @@ module Zernio
191
207
  invalid_properties.push('invalid value for "name", the character length must be smaller than or equal to 200.')
192
208
  end
193
209
 
194
- if @questions.nil?
195
- invalid_properties.push('invalid value for "questions", questions cannot be nil.')
196
- end
197
-
198
- if @questions.length < 1
210
+ if !@questions.nil? && @questions.length < 1
199
211
  invalid_properties.push('invalid value for "questions", number of items must be greater than or equal to 1.')
200
212
  end
201
213
 
@@ -217,8 +229,7 @@ module Zernio
217
229
  return false if @account_id.nil?
218
230
  return false if @name.nil?
219
231
  return false if @name.to_s.length > 200
220
- return false if @questions.nil?
221
- return false if @questions.length < 1
232
+ return false if !@questions.nil? && @questions.length < 1
222
233
  return false if @privacy_policy_url.nil?
223
234
  return false if !@privacy_policy_link_text.nil? && @privacy_policy_link_text.to_s.length > 70
224
235
  true
@@ -303,7 +314,8 @@ module Zernio
303
314
  thank_you_button_text == o.thank_you_button_text &&
304
315
  thank_you_button_type == o.thank_you_button_type &&
305
316
  thank_you_website_url == o.thank_you_website_url &&
306
- is_optimized_for_quality == o.is_optimized_for_quality
317
+ is_optimized_for_quality == o.is_optimized_for_quality &&
318
+ platform_specific_data == o.platform_specific_data
307
319
  end
308
320
 
309
321
  # @see the `==` method
@@ -315,7 +327,7 @@ module Zernio
315
327
  # Calculates hash code according to all attributes.
316
328
  # @return [Integer] Hash code
317
329
  def hash
318
- [account_id, name, questions, privacy_policy_url, privacy_policy_link_text, follow_up_action_url, locale, thank_you_title, thank_you_body, thank_you_button_text, thank_you_button_type, thank_you_website_url, is_optimized_for_quality].hash
330
+ [account_id, name, questions, privacy_policy_url, privacy_policy_link_text, follow_up_action_url, locale, thank_you_title, thank_you_body, thank_you_button_text, thank_you_button_type, thank_you_website_url, is_optimized_for_quality, platform_specific_data].hash
319
331
  end
320
332
 
321
333
  # Builds the object from hash
@@ -0,0 +1,105 @@
1
+ =begin
2
+ #Zernio API
3
+
4
+ #API reference for Zernio. Authenticate with a Bearer API key. Base URL: https://zernio.com/api
5
+
6
+ The version of the OpenAPI document: 1.0.4
7
+ Contact: support@zernio.com
8
+ Generated by: https://openapi-generator.tech
9
+ Generator version: 7.19.0
10
+
11
+ =end
12
+
13
+ require 'date'
14
+ require 'time'
15
+
16
+ module Zernio
17
+ # Form content; the shape is selected by the accountId's platform. Unknown fields are a 400 (strict-parsed).
18
+ module CreateLeadFormRequestPlatformSpecificData
19
+ class << self
20
+ # List of class defined in oneOf (OpenAPI v3)
21
+ def openapi_one_of
22
+ [
23
+ :'LinkedInLeadFormPlatformData',
24
+ :'MetaLeadFormPlatformData'
25
+ ]
26
+ end
27
+
28
+ # Builds the object
29
+ # @param [Mixed] Data to be matched against the list of oneOf items
30
+ # @return [Object] Returns the model or the data itself
31
+ def build(data)
32
+ # Go through the list of oneOf items and attempt to identify the appropriate one.
33
+ # Note:
34
+ # - We do not attempt to check whether exactly one item matches.
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_one_of.each do |klass|
40
+ begin
41
+ next if klass == :AnyType # "nullable: true"
42
+ return find_and_cast_into_type(klass, data)
43
+ rescue # rescue all errors so we keep iterating even if the current item lookup raises
44
+ end
45
+ end
46
+
47
+ openapi_one_of.include?(:AnyType) ? data : nil
48
+ end
49
+
50
+ private
51
+
52
+ SchemaMismatchError = Class.new(StandardError)
53
+
54
+ # Note: 'File' is missing here because in the regular case we get the data _after_ a call to JSON.parse.
55
+ def find_and_cast_into_type(klass, data)
56
+ return if data.nil?
57
+
58
+ case klass.to_s
59
+ when 'Boolean'
60
+ return data if data.instance_of?(TrueClass) || data.instance_of?(FalseClass)
61
+ when 'Float'
62
+ return data if data.instance_of?(Float)
63
+ when 'Integer'
64
+ return data if data.instance_of?(Integer)
65
+ when 'Time'
66
+ return Time.parse(data)
67
+ when 'Date'
68
+ return Date.iso8601(data)
69
+ when 'String'
70
+ return data if data.instance_of?(String)
71
+ when 'Object' # "type: object"
72
+ return data if data.instance_of?(Hash)
73
+ when /\AArray<(?<sub_type>.+)>\z/ # "type: array"
74
+ if data.instance_of?(Array)
75
+ sub_type = Regexp.last_match[:sub_type]
76
+ return data.map { |item| find_and_cast_into_type(sub_type, item) }
77
+ end
78
+ when /\AHash<String, (?<sub_type>.+)>\z/ # "type: object" with "additionalProperties: { ... }"
79
+ if data.instance_of?(Hash) && data.keys.all? { |k| k.instance_of?(Symbol) || k.instance_of?(String) }
80
+ sub_type = Regexp.last_match[:sub_type]
81
+ return data.each_with_object({}) { |(k, v), hsh| hsh[k] = find_and_cast_into_type(sub_type, v) }
82
+ end
83
+ else # model
84
+ const = Zernio.const_get(klass)
85
+ if const
86
+ if const.respond_to?(:openapi_one_of) # nested oneOf model
87
+ model = const.build(data)
88
+ return model if model
89
+ else
90
+ # raise if data contains keys that are not known to the model
91
+ raise if const.respond_to?(:acceptable_attributes) && !(data.keys - const.acceptable_attributes).empty?
92
+ model = const.build_from_hash(data)
93
+ return model if model
94
+ end
95
+ end
96
+ end
97
+
98
+ raise # if no match by now, raise
99
+ rescue
100
+ raise SchemaMismatchError, "#{data} doesn't match the #{klass} type"
101
+ end
102
+ end
103
+ end
104
+
105
+ end