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.



10
11
12
# File 'lib/appmap/swagger/markdown_descriptions.rb', line 10

def initialize(swagger_yaml)
  @swagger_yaml = swagger_yaml
end

Instance Method Details

#converterObject



14
15
16
# File 'lib/appmap/swagger/markdown_descriptions.rb', line 14

def converter
  method(:rdoc_to_markdown)
end

#performObject



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

def perform
  to_markdown = lambda do |obj|
    return obj.each(&to_markdown) if obj.is_a?(Array)
    return 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.(@swagger_yaml.deep_dup)
end