Class: OasRails::Builders::OperationBuilder

Inherits:
Object
  • Object
show all
Includes:
Extractors::OasRouteExtractor
Defined in:
lib/oas_rails/builders/operation_builder.rb

Instance Method Summary collapse

Methods included from Extractors::OasRouteExtractor

#default_tags, #extract_operation_id, #extract_security, #extract_summary, #extract_tags

Constructor Details

#initialize(specification) ⇒ OperationBuilder

Returns a new instance of OperationBuilder.



6
7
8
9
# File 'lib/oas_rails/builders/operation_builder.rb', line 6

def initialize(specification)
  @specification = specification
  @operation = Spec::Operation.new(specification)
end

Instance Method Details

#buildObject



27
28
29
# File 'lib/oas_rails/builders/operation_builder.rb', line 27

def build
  @operation
end

#from_oas_route(oas_route) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oas_rails/builders/operation_builder.rb', line 11

def from_oas_route(oas_route)
  @operation.summary = extract_summary(oas_route:)
  @operation.operation_id = extract_operation_id(oas_route:)
  @operation.description = oas_route.docstring
  @operation.tags = extract_tags(oas_route:)
  @operation.security = extract_security(oas_route:)
  @operation.parameters = ParametersBuilder.new(@specification).from_oas_route(oas_route).build
  @operation.request_body = RequestBodyBuilder.new(@specification).from_oas_route(oas_route).reference
  @operation.responses = ResponsesBuilder.new(@specification)
                                         .from_oas_route(oas_route)
                                         .add_autodiscovered_responses(oas_route)
                                         .add_default_responses(oas_route, !@operation.security.empty?).build

  self
end