-
Notifications
You must be signed in to change notification settings - Fork 13
/
rake_tasks.rb
49 lines (38 loc) · 1.56 KB
/
rake_tasks.rb
1
2
3
4
5
6
7
8
9
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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