Module: OasRails::Extractors::OasRouteExtractor

Included in:
Builders::OperationBuilder
Defined in:
lib/oas_rails/extractors/oas_route_extractor.rb

Instance Method Summary collapse

Instance Method Details

#default_tags(oas_route:) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/oas_rails/extractors/oas_route_extractor.rb', line 21

def default_tags(oas_route:)
  tags = []
  if OasRails.config.default_tags_from == :namespace
    tag = oas_route.path.split('/').reject(&:empty?).first.try(:titleize)
    tags << tag unless tag.nil?
  else
    tags << oas_route.controller.gsub("/", " ").titleize
  end
  tags
end

#extract_operation_id(oas_route:) ⇒ Object



8
9
10
# File 'lib/oas_rails/extractors/oas_route_extractor.rb', line 8

def extract_operation_id(oas_route:)
  "#{oas_route.method}#{oas_route.path.gsub('/', '_').gsub(/[{}]/, '')}"
end

#extract_security(oas_route:) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/oas_rails/extractors/oas_route_extractor.rb', line 32

def extract_security(oas_route:)
  return [] if oas_route.docstring.tags(:no_auth).any?

  if (methods = oas_route.docstring.tags(:auth).first)
    OasRails.config.security_schemas.keys.map { |key| { key => [] } }.select do |schema|
      methods.types.include?(schema.keys.first.to_s)
    end
  elsif OasRails.config.authenticate_all_routes_by_default
    OasRails.config.security_schemas.keys.map { |key| { key => [] } }
  else
    []
  end
end

#extract_summary(oas_route:) ⇒ Object



4
5
6
# File 'lib/oas_rails/extractors/oas_route_extractor.rb', line 4

def extract_summary(oas_route:)
  oas_route.docstring.tags(:summary).first.try(:text) || generate_crud_name(oas_route.method, oas_route.controller.downcase) || "#{oas_route.verb} #{oas_route.path}"
end

#extract_tags(oas_route:) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/oas_rails/extractors/oas_route_extractor.rb', line 12

def extract_tags(oas_route:)
  tags = oas_route.docstring.tags(:tags).first
  if tags.nil?
    default_tags(oas_route:)
  else
    tags.text.split(",").map(&:strip).map(&:titleize)
  end
end