Class: Apiwork::API::Union

Inherits:
Union
  • Object
show all
Defined in:
lib/apiwork/api/union.rb

Overview

Block context for defining reusable union types.

Accessed via ‘union :name do` in API or contract definitions. Use Union#variant to define possible types.

Examples:

instance_eval style

union :payment_method, discriminator: :type do
  variant tag: 'card' do
    object do
      string :last_four
    end
  end
  variant tag: 'bank' do
    object do
      string :account_number
    end
  end
end

yield style

union :payment_method, discriminator: :type do |union|
  union.variant tag: 'card' do |variant|
    variant.object do |object|
      object.string :last_four
    end
  end
  union.variant tag: 'bank' do |variant|
    variant.object do |object|
      object.string :account_number
    end
  end
end

See Also:

Instance Attribute Summary

Attributes inherited from Union

#discriminator, #variants

Method Summary

Methods inherited from Union

#initialize, #variant

Constructor Details

This class inherits a constructor from Apiwork::Union