Module: OpenObserve::Api::Models::UpdatePayload

Defined in:
lib/openobserve-api/models/update_payload.rb

Overview

oneOf wrapper. Builds the matching member from the discriminator when present, else tries each candidate type in order.

Constant Summary collapse

CANDIDATES =
[
  'UpdatePayloadOneOf',
  'UpdatePayloadOneOf1',
  'UpdatePayloadOneOf2',
].freeze

Class Method Summary collapse

Class Method Details

.build(data) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/openobserve-api/models/update_payload.rb', line 20

def self.build(data)
  # oneOf semantics: exactly one candidate must match. Collect every match so an
  # ambiguous payload (satisfying more than one schema) is surfaced rather than
  # silently resolved to whichever candidate happens to be listed first. (A match
  # can legitimately be `false`, so reject only nil -- never use compact/filter_map.)
  matches = []
  CANDIDATES.each do |type_name|
    next if type_name == 'AnyType'

    result = OpenObserve::Api::Polymorphism.cast(type_name, data)
    matches << result unless result.nil?
  end
  raise ArgumentError, "ambiguous oneOf for #{name}: #{matches.size} candidates matched" if matches.size > 1
  return matches.first unless matches.empty?
  return data if CANDIDATES.include?('AnyType')

  raise ArgumentError, "oneOf for #{name}: no candidate matched #{CANDIDATES.inspect}"
end