Class: OpenapiFirst::ResponseParser

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/response_parser.rb

Overview

Parse a response

Instance Method Summary collapse

Constructor Details

#initialize(headers:, content_type:) ⇒ ResponseParser

Returns a new instance of ResponseParser.



10
11
12
13
# File 'lib/openapi_first/response_parser.rb', line 10

def initialize(headers:, content_type:)
  @headers_parser = build_headers_parser(headers)
  @body_parser = ResponseBodyParsers[content_type]
end

Instance Method Details

#parse(rack_response) ⇒ Object



15
16
17
18
19
20
# File 'lib/openapi_first/response_parser.rb', line 15

def parse(rack_response)
  ParsedResponse.new(
    body: @body_parser.call(read_body(rack_response)),
    headers: @headers_parser&.call(rack_response.headers) || {}
  )
end