Class: OAPI::OpenAPI::V30::Serializers::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/oapi/open_api/v30/serializers/serializer.rb

Direct Known Subclasses

JSON, Ruby

Constant Summary collapse

FUNCTIONS =

order matters

{ # order matters
  OAPI::Ref => "serialize_ref",
  OAPI::Schema => "serialize_schema",
  OAPI::OpenAPI::V30::Definition => "serialize_definition",
  OAPI::Types::Map => "serialize_map",
  OAPI::Types::Array => "serialize_array",
  OAPI::Types::Object => "serialize_object"
}.freeze

Class Method Summary collapse

Class Method Details

.serialize(node) ⇒ Object



14
# File 'lib/oapi/open_api/v30/serializers/serializer.rb', line 14

def serialize(node) = new.send(serializer(node), node)

.serialize_if_supported(node) ⇒ Object



17
# File 'lib/oapi/open_api/v30/serializers/serializer.rb', line 17

def serialize_if_supported(node) = supported?(node) ? serialize(node) : node

.serializer(node) ⇒ Object



15
# File 'lib/oapi/open_api/v30/serializers/serializer.rb', line 15

def serializer(node) = FUNCTIONS.find { |k, _| node.is_a?(k) }&.at(1)

.supported?(node) ⇒ Boolean

Returns:

  • (Boolean)


16
# File 'lib/oapi/open_api/v30/serializers/serializer.rb', line 16

def supported?(node) = !serializer(node).nil?