Class: Scorpio::OpenAPI::OperationsScope

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/scorpio/openapi/operations_scope.rb

Overview

OperationsScope acts as an Enumerable of the Operations for an openapi_document, and offers subscripting by operationId.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(openapi_document) ⇒ OperationsScope

Returns a new instance of OperationsScope.

Parameters:



9
10
11
12
13
14
15
16
17
18
# File 'lib/scorpio/openapi/operations_scope.rb', line 9

def initialize(openapi_document)
  @openapi_document = openapi_document
  @operations_by_id = Hash.new do |h, operationId|
    op = detect { |operation| operation.operationId == operationId }
    unless op
      raise(::KeyError, "operationId not found: #{operationId.inspect}")
    end
    h[operationId] = op
  end
end

Instance Attribute Details

#openapi_documentObject (readonly)

Returns the value of attribute openapi_document.



19
20
21
# File 'lib/scorpio/openapi/operations_scope.rb', line 19

def openapi_document
  @openapi_document
end

Instance Method Details

#[](operationId) ⇒ Scorpio::OpenAPI::Operation

finds an operation with the given operationId

Parameters:

  • operationId (String)

    the operationId of the operation to find

Returns:

Raises:

  • (::KeyError)

    if the given operationId does not exist



37
38
39
# File 'lib/scorpio/openapi/operations_scope.rb', line 37

def [](operationId)
  @operations_by_id[operationId]
end

#each {|Scorpio::OpenAPI::Operation| ... } ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/scorpio/openapi/operations_scope.rb', line 22

def each
  openapi_document.paths.each do |path, path_item|
    path_item.each do |http_method, operation|
      if operation.is_a?(Scorpio::OpenAPI::Operation)
        yield operation
      end
    end
  end
end