Class: Gitlab::GrapeOpenapi::Converters::OperationConverter

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/converters/operation_converter.rb

Constant Summary collapse

DASH_SEGMENT =
'Dash'

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, schema_registry, request_body_registry, inherited_path_params: {}, path_override: nil, removed_params: []) ⇒ OperationConverter

Returns a new instance of OperationConverter.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/gitlab/grape_openapi/converters/operation_converter.rb', line 24

def initialize(
  route, schema_registry, request_body_registry, inherited_path_params: {},
  path_override: nil, removed_params: [])
  @route = route
  @schema_registry = schema_registry
  @request_body_registry = request_body_registry
  @inherited_path_params = inherited_path_params
  # @path_override and @removed_params are set together when optional-path-segment variants exist
  @path_override = path_override
  @removed_params = removed_params
  @config = Gitlab::GrapeOpenapi.configuration
  @options = route.options
  @pattern = route.pattern
  @endpoint = route.app
end

Class Method Details

.convert(route, schema_registry, request_body_registry, inherited_path_params: {}, path_override: nil, removed_params: []) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/gitlab/grape_openapi/converters/operation_converter.rb', line 11

def self.convert(
  route, schema_registry, request_body_registry, inherited_path_params: {},
  path_override: nil, removed_params: [])
  new(
    route,
    schema_registry,
    request_body_registry,
    inherited_path_params: inherited_path_params,
    path_override: path_override,
    removed_params: removed_params
  ).convert
end

Instance Method Details

#convertObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/gitlab/grape_openapi/converters/operation_converter.rb', line 40

def convert
  Models::Operation.new.tap do |operation|
    operation.operation_id = operation_id
    operation.summary = extract_description
    operation.description = extract_detail
    operation.tags = extract_tags
    operation.deprecated = extract_deprecated
    operation.hidden = extract_hidden
    operation.parameters = extract_parameters
    operation.responses = ResponseConverter.new(@route, @schema_registry).convert
    operation.request_body = extract_request_body || {}
    operation.annotations = extract_annotations
  end
end