Class: AppMap::Swagger::Stable

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

Overview

Transform raw Swagger into a “stable” variant. For example, remove descriptions and parameter examples, whose variance does not substantially affect the API.

Instance Method Summary collapse

Constructor Details

#initialize(swagger_yaml) ⇒ Stable

Returns a new instance of Stable.



6
7
8
# File 'lib/appmap/swagger/stable.rb', line 6

def initialize(swagger_yaml)
  @swagger_yaml = swagger_yaml
end

Instance Method Details

#performObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appmap/swagger/stable.rb', line 10

def perform
  clean_only = nil
  clean = lambda do |obj, properties = %w[description example]|
    next obj.each(&clean_only.(properties)) if obj.is_a?(Array)
    next unless obj.is_a?(Hash)

    properties.each { |property| obj.delete property }

    obj.each do |key, value|
      # Don't clean 'description' from within 'properties'
      props = key == 'properties' ? %w[example] : properties
      clean_only.(props).(value)
    end

    obj
  end

  clean_only = lambda do |properties|
    lambda do |example|
      clean.(example, properties)
    end
  end

  clean.(@swagger_yaml.deep_dup)
end