Sha256: 16ab429b766f84850d6a5c28fb6fed2a072adfdc40220b9de07d8444f27c7885

Contents?: true

Size: 1.56 KB

Versions: 57

Compression:

Stored size: 1.56 KB

Contents

require 'rake'
require 'yaml'
require 'fileutils'
require 'appmap/node_cli'
require 'appmap/swagger/markdown_descriptions'
require 'appmap/swagger/stable'

module AppMap
  module Swagger
    module RakeTasks
      extend self
      extend Rake::DSL

      def configuration
        AppMap.configuration
      end

      def define_tasks
        generate_swagger = lambda do |t, args|
          appmap_js = AppMap::NodeCLI.new(verbose: Rake.verbose == true)

          FileUtils.mkdir_p configuration.swagger_config.output_dir
          swagger_template = Tempfile.new('swagger_template')

          swagger_template.write(configuration.swagger_config.template.to_yaml)
          swagger_template.close

          cmd = %w[swagger]
          cmd << '--openapi-template' << swagger_template.path

          swagger_raw, = appmap_js.command(cmd)

          gen_swagger = YAML.load(swagger_raw)
          gen_swagger_full = AppMap::Swagger::MarkdownDescriptions.new(gen_swagger).perform
          gen_swagger_stable = AppMap::Swagger::Stable.new(gen_swagger).perform
  
          swagger = configuration.swagger_config.template.merge(gen_swagger_full)
          File.write File.join(configuration.swagger_config.output_dir, 'openapi.yaml'), YAML.dump(swagger)
  
          swagger = configuration.swagger_config.template.merge(gen_swagger_stable)
          File.write File.join(configuration.swagger_config.output_dir, 'openapi_stable.yaml'), YAML.dump(swagger)  
        end

        desc configuration.swagger_config.description
        task :swagger, &generate_swagger
      end
    end
  end
end

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
appmap-1.1.1 lib/appmap/swagger/rake_tasks.rb
appmap-1.0.1 lib/appmap/swagger/rake_tasks.rb
appmap-1.0.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.103.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.102.2 lib/appmap/swagger/rake_tasks.rb
appmap-0.102.1 lib/appmap/swagger/rake_tasks.rb
appmap-0.102.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.101.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.100.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.99.4 lib/appmap/swagger/rake_tasks.rb
appmap-0.99.2 lib/appmap/swagger/rake_tasks.rb
appmap-0.99.1 lib/appmap/swagger/rake_tasks.rb
appmap-0.99.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.98.1 lib/appmap/swagger/rake_tasks.rb
appmap-0.98.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.97.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.96.0 lib/appmap/swagger/rake_tasks.rb
appmap-0.95.2 lib/appmap/swagger/rake_tasks.rb
appmap-0.95.1 lib/appmap/swagger/rake_tasks.rb
appmap-0.95.0 lib/appmap/swagger/rake_tasks.rb