Module: Brainstem::ApiDocs::Formatters::OpenApiSpecification::Helper

Instance Method Summary collapse

Instance Method Details

#format_description(description) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 21

def format_description(description)
  return '' if description.blank?

  desc = description.to_s.strip.tap { |desc| desc[0] = desc[0].upcase }
  desc += "." unless desc =~ /\.\s*\z/
  desc
end

#format_http_method(endpoint) ⇒ Object



11
12
13
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 11

def format_http_method(endpoint)
  endpoint.http_methods.first.downcase
end

#format_tag_name(name) ⇒ Object



15
16
17
18
19
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 15

def format_tag_name(name)
  return name if name.blank?

  name.underscore.titleize.strip
end

#presenter_title(presenter) ⇒ Object



6
7
8
9
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 6

def presenter_title(presenter)
  presenter.contextual_documentation(:title).presence ||
      presenter.target_class.underscore.singularize.titleize.strip
end

#type_and_format(type, item_type = nil) ⇒ Object

TODO: multi nested



36
37
38
39
40
41
42
43
44
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 36

def type_and_format(type, item_type = nil)
  result = case type.to_s.downcase
    when 'array'
      { 'type' => 'array', 'items' => { 'type' => item_type.presence || 'string' } }
    else
      TYPE_INFO[type.to_s]
  end
  result ? result.with_indifferent_access : nil
end

#uncapitalize(description) ⇒ Object



29
30
31
32
33
# File 'lib/brainstem/api_docs/formatters/open_api_specification/helper.rb', line 29

def uncapitalize(description)
  return '' if description.blank?

  description.strip.tap { |desc| desc[0] = desc[0].downcase }
end