Class: DryOpenApi::MediaType

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Includes:
EquatableAsContent
Defined in:
lib/dry_open_api/media_type.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Class Method Details

.load(hash) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dry_open_api/media_type.rb', line 22

def self.load(hash)
  return unless hash

  indi_hash = hash.with_indifferent_access

  new(
    schema: Reference.load(indi_hash['schema']) || Schema.load(indi_hash['schema']),
    example: indi_hash['example'],
    examples: indi_hash['examples']&.map { |k, v| [k, Reference.load(v) || Example.load(v)] }&.to_h,
    encoding: indi_hash['encoding']&.map { |k, v| [k, Encoding.load(v)] }&.to_h
  )
end

Instance Method Details

#serializable_hashObject



13
14
15
16
17
18
19
20
# File 'lib/dry_open_api/media_type.rb', line 13

def serializable_hash
  {
    'schema' => schema&.serializable_hash,
    'example' => example,
    'examples' => examples&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
    'encoding' => encoding&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h
  }.compact
end