Module: Scorpio::Response

Defined in:
lib/scorpio/response.rb

Overview

Scorpio::Response is a JSI schema module describing the same instances as ::Ur::Response. It relies on methods of that module.

Constant Summary collapse

SUPPORTED_MEDIA_TYPES =

media types for which Scorpio has implemented parsing #body_object from Response#body

%w(
  application/json
).map(&:freeze).freeze

Instance Method Summary collapse

Instance Method Details

#body_object(mutable: false) ⇒ Object

the body (String) is parsed according to the response media type, if supported (see SUPPORTED_MEDIA_TYPES), and instantiated as a JSI instance of #response_schema if that is defined.

Parameters:

  • mutable (Boolean) (defaults to: false)

    instantiate the response body object as mutable?



25
26
27
28
# File 'lib/scorpio/response.rb', line 25

def body_object(mutable: false)
  k = [:body_object, mutable]
  @memos.fetch(k) { @memos[k] = compute_body_object(mutable: mutable) }
end

#response_schema::JSI::Schema

the schema for this response according to its OpenAPI doc

Returns:

  • (::JSI::Schema)


11
12
13
# File 'lib/scorpio/response.rb', line 11

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