Class: AppMap::Swagger::MarkdownDescriptions

Inherits:
Object
  • Object
show all
Defined in:
lib/appmap/swagger/markdown_descriptions.rb

Overview

Transform description fields into Markdown.

Instance Method Summary collapse

Constructor Details

#initialize(swagger_yaml) ⇒ MarkdownDescriptions

Returns a new instance of MarkdownDescriptions.



8
9
10
# File 'lib/appmap/swagger/markdown_descriptions.rb', line 8

def initialize(swagger_yaml)
  @swagger_yaml = swagger_yaml
end

Instance Method Details

#converterObject



12
13
14
# File 'lib/appmap/swagger/markdown_descriptions.rb', line 12

def converter
  method(:rdoc_to_markdown)
end

#performObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/appmap/swagger/markdown_descriptions.rb', line 16

def perform
  to_markdown = lambda do |obj|
    next obj.each(&to_markdown) if obj.is_a?(Array)
    next unless obj.is_a?(Hash)

    description = obj['description']
    obj['description'] = converter.(description) if description

    obj.reject { |k,v| k == 'properties' }.each_value(&to_markdown)

    obj
  end

  to_markdown.(Util.deep_dup(@swagger_yaml))
end