Class: DryOpenApi::Response

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

Overview

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Class Method Details

.load(hash) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/dry_open_api/response.rb', line 42

def self.load(hash)
  return unless hash

  indi_hash = hash.with_indifferent_access

  new(
    description: indi_hash['description'],
    headers: indi_hash['headers']&.map { |k, v| [k, Header.load(v)] }&.to_h,
    content: indi_hash['content']&.map { |k, v| [k, MediaType.load(v)] }&.to_h,
    links: indi_hash['links']&.map { |k, v| [k, Reference.load(v) || Link.load(v)] }&.to_h
  )
end

Instance Method Details

#serializable_hashObject

rubocop:enable Style/Lambda



33
34
35
36
37
38
39
40
# File 'lib/dry_open_api/response.rb', line 33

def serializable_hash
  {
    'description' => description,
    'headers' => headers&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
    'content' => content&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h,
    'links' => links&.map { |k, v| [k.to_s, v.serializable_hash] }&.to_h
  }.compact
end