Class: OpenapiContracts::Doc::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_contracts/doc/response.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema) ⇒ Response



3
4
5
# File 'lib/openapi_contracts/doc/response.rb', line 3

def initialize(schema)
  @schema = schema.follow_refs
end

Instance Method Details

#headersObject



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

def headers
  return @headers if instance_variable_defined? :@headers

  @headers = @schema.fetch('headers', {}).map do |(key, val)|
    Doc::Header.new(key, val)
  end
end

#no_content?Boolean



21
22
23
# File 'lib/openapi_contracts/doc/response.rb', line 21

def no_content?
  !@schema.key? 'content'
end

#schema_for(content_type) ⇒ Object



15
16
17
18
19
# File 'lib/openapi_contracts/doc/response.rb', line 15

def schema_for(content_type)
  return unless supports_content_type?(content_type)

  @schema.navigate('content', content_type, 'schema')
end

#supports_content_type?(content_type) ⇒ Boolean



25
26
27
# File 'lib/openapi_contracts/doc/response.rb', line 25

def supports_content_type?(content_type)
  @schema.dig('content', content_type).present?
end