Class: GrapeOAS::ApiModel::Path

Inherits:
Node
  • Object
show all
Defined in:
lib/grape_oas/api_model/path.rb

Overview

Represents an API path (endpoint) in the DTO model for OpenAPI v2/v3. Contains a list of operations (HTTP methods) for the path. Used to build the ‘paths’ object in both OpenAPIv2 and OpenAPIv3 documents.

Constant Summary

Constants inherited from Node

Node::BUCKET_NAMES

Instance Attribute Summary collapse

Attributes inherited from Node

#id

Instance Method Summary collapse

Methods inherited from Node

bucket, #ref

Constructor Details

#initialize(template:) ⇒ Path

Returns a new instance of Path.



14
15
16
17
18
# File 'lib/grape_oas/api_model/path.rb', line 14

def initialize(template:)
  super()
  @template   = template
  @operations = []
end

Instance Attribute Details

#operationsObject

Returns the value of attribute operations.



12
13
14
# File 'lib/grape_oas/api_model/path.rb', line 12

def operations
  @operations
end

#templateObject

Returns the value of attribute template.



12
13
14
# File 'lib/grape_oas/api_model/path.rb', line 12

def template
  @template
end

Instance Method Details

#[](method_sym) ⇒ Object



24
25
26
# File 'lib/grape_oas/api_model/path.rb', line 24

def [](method_sym)
  @operations.find { |op| op.http_method.to_sym == method_sym.to_sym }
end

#add_operation(operation) ⇒ Object



20
21
22
# File 'lib/grape_oas/api_model/path.rb', line 20

def add_operation(operation)
  @operations << operation
end