Class: GrapeSwagger::DocMethods::OperationId

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

Class Method Summary collapse

Class Method Details

.build(route, path = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/grape-swagger/doc_methods/operation_id.rb', line 5

def build(route, path = nil)
  if route.options[:nickname]
    operation_id = route.options[:nickname]
  else
    verb = route.request_method.to_s.downcase

    operation = manipulate(path) unless path.nil?

    operation_id = "#{verb}#{operation}"
  end

  operation_id
end

.manipulate(path) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/grape-swagger/doc_methods/operation_id.rb', line 19

def manipulate(path)
  operation = path.split('/').map(&:capitalize).join
  operation.gsub!(/\-(\w)/, &:upcase).delete!('-') if operation.include?('-')
  operation.gsub!(/\_(\w)/, &:upcase).delete!('_') if operation.include?('_')
  if path.include?('{')
    operation.gsub!(/\{(\w)/, &:upcase)
    operation.delete!('{').delete!('}')
  end

  operation
end