Sha256: e588e8b3ab71d5eeec895c2a133b962c95eab5281e12100aaee315f41974640e

Contents?: true

Size: 1.02 KB

Versions: 54

Compression:

Stored size: 1.02 KB

Contents

module AppMap
  module Swagger
    # Transform raw Swagger into a "stable" variant. For example, remove descriptions
    # and parameter examples, whose variance does not substantially affect the API.
    class Stable
      def initialize(swagger_yaml)
        @swagger_yaml = swagger_yaml
      end

      def perform
        clean_only = nil
        clean = lambda do |obj, properties = %w[description example]|
          return obj.each(&clean_only.(properties)) if obj.is_a?(Array)
          return 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
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
appmap-0.80.1 lib/appmap/swagger/stable.rb
appmap-0.80.0 lib/appmap/swagger/stable.rb
appmap-0.79.0 lib/appmap/swagger/stable.rb
appmap-0.78.0 lib/appmap/swagger/stable.rb
appmap-0.77.4 lib/appmap/swagger/stable.rb
appmap-0.77.3 lib/appmap/swagger/stable.rb
appmap-0.77.2 lib/appmap/swagger/stable.rb
appmap-0.77.1 lib/appmap/swagger/stable.rb
appmap-0.77.0 lib/appmap/swagger/stable.rb
appmap-0.76.0 lib/appmap/swagger/stable.rb
appmap-0.75.0 lib/appmap/swagger/stable.rb
appmap-0.74.0 lib/appmap/swagger/stable.rb
appmap-0.73.0 lib/appmap/swagger/stable.rb
appmap-0.72.5 lib/appmap/swagger/stable.rb
appmap-0.72.4 lib/appmap/swagger/stable.rb
appmap-0.72.3 lib/appmap/swagger/stable.rb
appmap-0.72.2 lib/appmap/swagger/stable.rb
appmap-0.72.1 lib/appmap/swagger/stable.rb
appmap-0.72.0 lib/appmap/swagger/stable.rb
appmap-0.71.0 lib/appmap/swagger/stable.rb