Class: OpenapiContracts::Doc::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation, status, schema) ⇒ Response

Returns a new instance of Response.



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

def initialize(operation, status, schema)
  @operation = operation
  @status = status
  @schema = schema.follow_refs
end

Instance Attribute Details

#coverageObject (readonly)

Returns the value of attribute coverage.



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

def coverage
  @coverage
end

#operationObject (readonly)

Returns the value of attribute operation.



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

def operation
  @operation
end

#schemaObject (readonly)

Returns the value of attribute schema.



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

def schema
  @schema
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#headersObject



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

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

Returns:

  • (Boolean)


27
28
29
# File 'lib/openapi_contracts/doc/response.rb', line 27

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

#schema_for(media_type) ⇒ Object



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

def schema_for(media_type)
  return unless supports_media_type?(media_type)

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

#supports_media_type?(media_type) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/openapi_contracts/doc/response.rb', line 31

def supports_media_type?(media_type)
  @schema.dig('content', media_type).present?
end