Module: Scorpio::Response

Defined in:
lib/scorpio/response.rb

Instance Method Summary collapse

Instance Method Details

#body_objectObject

Returns the body (String) is parsed according to the response media type and if supported (only application/json is currently supported) instantiated according to

response_schema.

Returns:

  • (Object)

    the body (String) is parsed according to the response media type and if supported (only application/json is currently supported) instantiated according to

    response_schema



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/scorpio/response.rb', line 13

def body_object
  if json?
    if body.empty?
      # an empty body isn't valid json, of course, but we'll just return nil for it.
      body_object = nil
    else
      begin
        body_object = ::JSON.parse(body)
      #rescue ::JSON::ParserError
        # TODO
      end
    end

    if response_schema && (body_object.respond_to?(:to_hash) || body_object.respond_to?(:to_ary))
      body_object = response_schema.new_jsi(body_object)
    end

    body_object
  elsif content_type && content_type.type_text? && content_type.subtype?('plain')
    body
  else
    # we will return the body if we do not have a supported parsing. for now.
    body
  end
end

#response_schema::JSI::Schema

Returns the schema for this response according to its OpenAPI doc.

Returns:

  • (::JSI::Schema)

    the schema for this response according to its OpenAPI doc



6
7
8
# File 'lib/scorpio/response.rb', line 6

def response_schema
  ur.scorpio_request.operation.response_schema(status: status, media_type: media_type)
end