Class: Grape::API

Inherits:
Object
  • Object
show all
Defined in:
lib/grape-swagger.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.combined_namespacesObject (readonly)

Returns the value of attribute combined_namespaces.



10
11
12
# File 'lib/grape-swagger.rb', line 10

def combined_namespaces
  @combined_namespaces
end

.combined_routesObject (readonly)

Returns the value of attribute combined_routes.



10
11
12
# File 'lib/grape-swagger.rb', line 10

def combined_routes
  @combined_routes
end

Class Method Details

.add_swagger_documentation(options = {}) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/grape-swagger.rb', line 12

def add_swagger_documentation(options = {})
  documentation_class = create_documentation_class

  documentation_class.setup({ target_class: self }.merge(options))
  mount(documentation_class)

  @combined_routes = {}
  routes.each do |route|
    route_path = route.route_path
    route_match = route_path.split(/^.*?#{route.route_prefix.to_s}/).last
    next unless route_match
    route_match = route_match.match('\/([\w|-]*?)[\.\/\(]') || route_match.match('\/([\w|-]*)')
    next unless route_match
    resource = route_match.captures.first
    next if resource.empty?
    resource.downcase!
    @combined_routes[resource] ||= []
    next if documentation_class.hide_documentation_path && route.route_path.include?(documentation_class.mount_path)
    @combined_routes[resource] << route
  end

  @combined_namespaces = {}
  combine_namespaces(self)
  documentation_class
end