Class: OpenapiContracts::Doc::Operation

Inherits:
Object
  • Object
show all
Includes:
WithParameters
Defined in:
lib/openapi_contracts/doc/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from WithParameters

#parameters

Constructor Details

#initialize(path, spec) ⇒ Operation

Returns a new instance of Operation.



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

def initialize(path, spec)
  @path = path
  @spec = spec
  @responses = spec.navigate('responses').each.to_h do |status, subspec|
    [status, Doc::Response.new(self, status, subspec)]
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/openapi_contracts/doc/operation.rb', line 5

def path
  @path
end

Instance Method Details

#request_bodyObject



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

def request_body
  return @request_body if instance_variable_defined?(:@request_body)

  @request_body = @spec.navigate('requestBody').presence&.then { |s| Doc::Request.new(s) }
end

#response_for_status(status) ⇒ Object



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

def response_for_status(status)
  @responses[status.to_s]
end

#responsesObject



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

def responses
  @responses.each_value
end

#verbObject



15
16
17
# File 'lib/openapi_contracts/doc/operation.rb', line 15

def verb
  @spec.pointer[2]
end