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
# File 'lib/openapi_contracts/doc/response.rb', line 13

def headers
  @headers ||= Array.wrap(
    @schema.navigate('headers')&.each&.map { |key, schema| Doc::Header.new(key, schema.to_h) }
  )
end

#no_content?Boolean

Returns:

  • (Boolean)


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

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

#schema_for(media_type) ⇒ Object



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

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)


29
30
31
# File 'lib/openapi_contracts/doc/response.rb', line 29

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