Class: OpenApi::Response

Inherits:
Object
  • Object
show all
Includes:
EquatableAsContent
Defined in:
lib/open_api/response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from EquatableAsContent

#==

Constructor Details

#initialize(description:, headers: nil, content: nil, links: nil) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
# File 'lib/open_api/response.rb', line 7

def initialize(description:, headers: nil, content: nil, links: nil)
  self.description = description
  self.headers = headers&.with_indifferent_access
  self.content = content&.with_indifferent_access
  self.links = links&.with_indifferent_access
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



5
6
7
# File 'lib/open_api/response.rb', line 5

def content
  @content
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/open_api/response.rb', line 5

def description
  @description
end

#headersObject

Returns the value of attribute headers.



5
6
7
# File 'lib/open_api/response.rb', line 5

def headers
  @headers
end

Returns the value of attribute links.



5
6
7
# File 'lib/open_api/response.rb', line 5

def links
  @links
end

Class Method Details

.load(hash) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/open_api/response.rb', line 23

def self.load(hash)
  return unless hash

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

Instance Method Details

#serializable_hashObject



14
15
16
17
18
19
20
21
# File 'lib/open_api/response.rb', line 14

def serializable_hash
  {
    "description" => description.to_s,
    "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