Class: SoberSwag::Nodes::OneOf

Inherits:
Array show all
Defined in:
lib/sober_swag/nodes/one_of.rb

Overview

OpenAPI v3 represents types that are a "choice" between multiple alternatives as an array. However, it is easier to model these as a sum type initially: if a type can be either an A, a B, or a C, we can model this as:

Sum.new(A, Sum.new(B, C)).

This means we only ever need to deal with two types at once. So, we initially serialize to a sum type, then later transform to this array type for further serialization.

Instance Attribute Summary

Attributes inherited from Array

#elements

Instance Method Summary collapse

Methods inherited from Array

#cata, #deconstruct, #initialize, #map

Methods inherited from Base

#<=>, #cata, #eql?, #hash, #map

Constructor Details

This class inherits a constructor from SoberSwag::Nodes::Array

Instance Method Details

#deconstruct_keys(_) ⇒ Hash{Symbol => SoberSwag::Nodes::Base}

Returns the alternatives, wrapped in an alternatives: key.

Returns:



15
16
17
# File 'lib/sober_swag/nodes/one_of.rb', line 15

def deconstruct_keys(_)
  { alternatives: @elements }
end