Class: Eazypi::Responses

Inherits:
Object
  • Object
show all
Defined in:
lib/eazypi/responses.rb

Overview

OpenAPI spec ResponsesObject

Instance Method Summary collapse

Constructor Details

#initializeResponses

Returns a new instance of Responses.



6
7
8
# File 'lib/eazypi/responses.rb', line 6

def initialize
  @responses = {}
end

Instance Method Details

#add_response(status_code, &block) ⇒ Object



10
11
12
13
14
15
# File 'lib/eazypi/responses.rb', line 10

def add_response(status_code, &block)
  response = Response.new
  response.load(&block)

  @responses[status_code.to_s] = response
end

#collect_components(**kwargs) ⇒ Object



22
23
24
25
26
# File 'lib/eazypi/responses.rb', line 22

def collect_components(**kwargs)
  @responses.each_value do |response|
    response.collect_components(**kwargs)
  end
end

#response_for_response_code(response_code) ⇒ Object



17
18
19
20
# File 'lib/eazypi/responses.rb', line 17

def response_for_response_code(response_code)
  # Future improvement could be partial match
  @responses[response_code.to_s]
end

#to_openapi_specObject



28
29
30
# File 'lib/eazypi/responses.rb', line 28

def to_openapi_spec
  @responses.transform_values(&:to_openapi_spec)
end