Class: GrapeOpenapi3::Builders::OperationBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/grape_openapi3/builders/operation_builder.rb

Overview

Builds an OpenAPI 3.0 operation object for one route. Delegates parameter building to ParameterBuilder and registers any Grape::Entity response classes with the EntityReader.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route_data, entity_reader, global_security: false) ⇒ OperationBuilder

Returns a new instance of OperationBuilder.



13
14
15
16
17
# File 'lib/grape_openapi3/builders/operation_builder.rb', line 13

def initialize(route_data, entity_reader, global_security: false)
  @route           = route_data
  @entity_reader   = entity_reader
  @global_security = global_security
end

Class Method Details

.call(route_data, entity_reader, global_security: false) ⇒ Object



9
10
11
# File 'lib/grape_openapi3/builders/operation_builder.rb', line 9

def self.call(route_data, entity_reader, global_security: false)
  new(route_data, entity_reader, global_security: global_security).call
end

Instance Method Details

#callObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/grape_openapi3/builders/operation_builder.rb', line 19

def call
  param_result = ParameterBuilder.call(@route)

  operation = {}
  operation["operationId"] = OperationIdBuilder.call(@route[:http_method], @route[:path])
  operation["summary"]     = @route[:summary]                    if @route[:summary]
  operation["description"] = @route[:detail]                     if @route[:detail]
  operation["tags"]        = @route[:tags]                       unless @route[:tags].empty?
  operation["deprecated"]  = true                                if @route[:deprecated]
  operation["security"]    = @route[:security]                   if @route[:security]
  operation["parameters"]  = param_result[:parameters]          unless param_result[:parameters].empty?
  operation["requestBody"] = param_result[:request_body]         if param_result[:request_body]
  operation["responses"]   = build_responses

  operation
end