class Apigen::OneofType
OneofType
represents a union type, aka “either or”.
Attributes
mapping[R]
Public Class Methods
new()
click to toggle source
# File lib/apigen/models/oneof_type.rb, line 16 def initialize @discriminator = nil @mapping = {} end
Public Instance Methods
discriminator()
click to toggle source
The discriminator tells us which property defines the type of the object.
Setting a discriminator is optional, but recommended.
# File lib/apigen/models/oneof_type.rb, line 13 attribute_setter_getter :discriminator
map(mapping)
click to toggle source
# File lib/apigen/models/oneof_type.rb, line 21 def map(mapping) @mapping = mapping end
validate(model_registry)
click to toggle source
# File lib/apigen/models/oneof_type.rb, line 25 def validate(model_registry) @mapping.each do |key, value| validate_mapping_item(model_registry, key, value) end end
Private Instance Methods
validate_mapping_item(model_registry, key, value)
click to toggle source
# File lib/apigen/models/oneof_type.rb, line 33 def validate_mapping_item(model_registry, key, value) error = if !(key.is_a? Symbol) 'Mapping keys must be model names (use symbols).' elsif !(value.is_a? String) 'Mapping values must be strings.' elsif !(model_registry.models.key? key) "No such model :#{key} for oneof mapping." end raise error unless error.nil? end