Class: Gitlab::GrapeOpenapi::Converters::PathConverter

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

Defined Under Namespace

Classes: PathVariant

Constant Summary collapse

RESPONSE_DECLARATIONS =

Grape stores response-entity declarations under :entity (when declared via entity: on the route) and :success (when declared via the success DSL inside a desc block, in any of its forms). EntityConverter.register handles all three shapes (Class, Hash with :model, Array of those).

%i[entity success].freeze
OPTIONAL_SEGMENT =

A Grape optional path segment: a parenthesised group, e.g. (/:id).

/\(([^()]*)\)/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(routes, schema_registry, request_body_registry) ⇒ PathConverter

Returns a new instance of PathConverter.



23
24
25
26
27
28
29
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 23

def initialize(routes, schema_registry, request_body_registry)
  @routes = routes
  @schema_registry = schema_registry
  @request_body_registry = request_body_registry
  @config = Gitlab::GrapeOpenapi.configuration
  @inherited_path_params = {}
end

Class Method Details

.convert(routes, schema_registry, request_body_registry) ⇒ Object



19
20
21
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 19

def self.convert(routes, schema_registry, request_body_registry)
  new(routes, schema_registry, request_body_registry).convert
end

Instance Method Details

#convertObject



31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/gitlab/grape_openapi/converters/path_converter.rb', line 31

def convert
  register_inherited_path_params

  paths = {}
  grouped_routes.each do |path_key, routes_for_path|
    path_variants(path_key, routes_for_path.first).each do |variant|
      paths[variant.key] ||= {}
      paths[variant.key].merge!(build_path_item(routes_for_path, variant))
    end
  end

  paths.reject { |_path, operations| operations.empty? }
end