r2-oas 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (134) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +50 -0
  3. data/GEMSPEC.md +2 -2
  4. data/README.ja.md +54 -37
  5. data/README.md +55 -32
  6. data/lib/r2-oas.rb +4 -5
  7. data/lib/r2-oas/app_configuration.rb +17 -5
  8. data/lib/r2-oas/app_configuration/deprecation.rb +28 -0
  9. data/lib/r2-oas/configuration.rb +56 -0
  10. data/lib/r2-oas/deploy/client.rb +21 -6
  11. data/lib/r2-oas/{plugins/schema/v3/object → dynamic/schema/v3/object/from_routes}/hookable_base_object.rb +7 -7
  12. data/lib/r2-oas/errors.rb +5 -0
  13. data/lib/r2-oas/hooks/hook.rb +7 -5
  14. data/lib/r2-oas/lib/core_ext/all.rb +5 -0
  15. data/lib/r2-oas/lib/core_ext/string/filters.rb +29 -0
  16. data/lib/r2-oas/pluggable_configuration.rb +8 -5
  17. data/lib/r2-oas/plugin/base.rb +44 -0
  18. data/lib/r2-oas/plugin/executor.rb +148 -0
  19. data/lib/r2-oas/plugin/hookable.rb +42 -0
  20. data/lib/r2-oas/plugin/public.rb +3 -0
  21. data/lib/r2-oas/plugin/transform/transform.rb +10 -0
  22. data/lib/r2-oas/plugin/transform/v3/transform.rb +20 -0
  23. data/lib/r2-oas/plugin/transform/v3/visitable.rb +37 -0
  24. data/lib/r2-oas/public.rb +5 -0
  25. data/lib/r2-oas/schema/base.rb +1 -1
  26. data/lib/r2-oas/schema/builder.rb +1 -1
  27. data/lib/r2-oas/schema/editor.rb +8 -1
  28. data/lib/r2-oas/schema/v3/analyzer/path_analyzer.rb +1 -1
  29. data/lib/r2-oas/schema/v3/builder.rb +1 -1
  30. data/lib/r2-oas/schema/v3/builder/base_builder.rb +14 -2
  31. data/lib/r2-oas/schema/v3/builder/doc_builder.rb +10 -2
  32. data/lib/r2-oas/schema/v3/generator/base_generator.rb +7 -2
  33. data/lib/r2-oas/schema/v3/generator/doc_generator.rb +1 -1
  34. data/lib/r2-oas/schema/v3/manager/file/include_ref_base_file_manager.rb +3 -2
  35. data/lib/r2-oas/schema/v3/object/from_files/base_object.rb +62 -0
  36. data/lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb +103 -0
  37. data/lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb +102 -0
  38. data/lib/r2-oas/schema/v3/object/from_files/components_object.rb +46 -0
  39. data/lib/r2-oas/schema/v3/object/from_files/external_document_object.rb +23 -0
  40. data/lib/r2-oas/schema/v3/object/from_files/info_object.rb +23 -0
  41. data/lib/r2-oas/schema/v3/object/from_files/openapi_object.rb +61 -0
  42. data/lib/r2-oas/schema/v3/object/from_files/path_item_object.rb +110 -0
  43. data/lib/r2-oas/schema/v3/object/from_files/paths_object.rb +33 -0
  44. data/lib/r2-oas/schema/v3/object/from_files/utils/all.rb +4 -0
  45. data/lib/r2-oas/schema/v3/object/from_files/utils/deep_methods.rb +27 -0
  46. data/lib/r2-oas/schema/v3/object/from_files/utils/refs.rb +151 -0
  47. data/lib/r2-oas/schema/v3/object/{base_object.rb → from_routes/base_object.rb} +11 -1
  48. data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/request_body_object.rb +23 -19
  49. data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/schema_object.rb +16 -12
  50. data/lib/r2-oas/schema/v3/object/{components_object.rb → from_routes/components_object.rb} +11 -11
  51. data/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb +28 -0
  52. data/lib/r2-oas/schema/v3/object/{info_object.rb → from_routes/info_object.rb} +11 -2
  53. data/lib/r2-oas/schema/v3/object/{openapi_object.rb → from_routes/openapi_object.rb} +12 -11
  54. data/lib/r2-oas/schema/v3/object/{path_item_object.rb → from_routes/path_item_object.rb} +6 -6
  55. data/lib/r2-oas/schema/v3/object/{paths_object.rb → from_routes/paths_object.rb} +11 -8
  56. data/lib/r2-oas/schema/v3/object/{public.rb → from_routes/public.rb} +0 -0
  57. data/lib/r2-oas/schema/v3/object/{server_object.rb → from_routes/server_object.rb} +0 -0
  58. data/lib/r2-oas/schema/v3/object/{tag_object.rb → from_routes/tag_object.rb} +2 -1
  59. data/lib/r2-oas/schema/v3/object/store.rb +54 -0
  60. data/lib/r2-oas/shared/all.rb +1 -0
  61. data/lib/r2-oas/shared/callable.rb +17 -0
  62. data/lib/r2-oas/store.rb +20 -16
  63. data/lib/r2-oas/support/deprecation.rb +26 -0
  64. data/lib/r2-oas/support/deprecation/behavior.rb +21 -0
  65. data/lib/r2-oas/support/deprecation/instance_delegator.rb +42 -0
  66. data/lib/r2-oas/support/deprecation/reporting.rb +91 -0
  67. data/lib/r2-oas/task.rb +1 -2
  68. data/lib/r2-oas/task_logging.rb +3 -7
  69. data/lib/r2-oas/tasks/common.rake +1 -2
  70. data/lib/r2-oas/tasks/main.rake +60 -9
  71. data/lib/r2-oas/version.rb +1 -1
  72. data/r2-oas.gemspec +1 -6
  73. metadata +51 -110
  74. data/.github/ISSUE_TEMPLATE.md +0 -12
  75. data/.github/PULL_REQUEST_TEMPLATE.md +0 -12
  76. data/.gitignore +0 -16
  77. data/.rspec +0 -3
  78. data/.rubocop.yml +0 -10
  79. data/.rubocop_todo.yml +0 -291
  80. data/.travis.yml +0 -26
  81. data/Appraisals +0 -13
  82. data/CODE_OF_CONDUCT.md +0 -74
  83. data/Gemfile +0 -12
  84. data/Rakefile +0 -8
  85. data/bin/console +0 -12
  86. data/bin/setup +0 -8
  87. data/devscript/all_support_ruby.sh +0 -43
  88. data/devscript/bundle_for_all_support_ruby.sh +0 -31
  89. data/devscript/rspec_for_all_support_ruby.sh +0 -27
  90. data/docs/.nojekyll +0 -0
  91. data/docs/README.md +0 -173
  92. data/docs/_sidebar.md +0 -25
  93. data/docs/attention/if_clash.md +0 -17
  94. data/docs/index.html +0 -29
  95. data/docs/schema/3.0.0.md +0 -155
  96. data/docs/setting/COC.md +0 -14
  97. data/docs/setting/CORS.md +0 -22
  98. data/docs/setting/configure.md +0 -176
  99. data/docs/trableshouting/runtime_error.md +0 -44
  100. data/docs/usage/analyze_docs.md +0 -875
  101. data/docs/usage/clean_docs.md +0 -19
  102. data/docs/usage/deploy_docs.md +0 -839
  103. data/docs/usage/display_paths_list.md +0 -35
  104. data/docs/usage/display_paths_stats.md +0 -54
  105. data/docs/usage/edit_docs.md +0 -218
  106. data/docs/usage/generate_docs.md +0 -412
  107. data/docs/usage/monitor_docs.md +0 -219
  108. data/docs/usage/use_hook_methods.md +0 -236
  109. data/docs/usage/use_hook_to_generate_docs.md +0 -235
  110. data/docs/usage/use_schema_namespace.md +0 -181
  111. data/docs/usage/use_tag_namespace.md +0 -180
  112. data/docs/usage/view_docs.md +0 -262
  113. data/gemfiles/ruby_2.3.3.gemfile +0 -11
  114. data/gemfiles/ruby_2.4.2.gemfile +0 -11
  115. data/gemfiles/ruby_2.5.8.gemfile +0 -11
  116. data/gemfiles/ruby_2.6.6.gemfile +0 -11
  117. data/gemfiles/ruby_2.7.1.gemfile +0 -11
  118. data/lib/r2-oas/app_configuration/tool.rb +0 -31
  119. data/lib/r2-oas/app_configuration/tool/paths/stats.rb +0 -43
  120. data/lib/r2-oas/deploy/swagger-ui/dist/favicon-16x16.png +0 -0
  121. data/lib/r2-oas/deploy/swagger-ui/dist/favicon-32x32.png +0 -0
  122. data/lib/r2-oas/deploy/swagger-ui/dist/oauth2-redirect.html +0 -68
  123. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js +0 -134
  124. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js.map +0 -1
  125. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js +0 -22
  126. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js.map +0 -1
  127. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css +0 -4
  128. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css.map +0 -1
  129. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js +0 -9
  130. data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js.map +0 -1
  131. data/lib/r2-oas/schema/v3/object/external_document_object.rb +0 -19
  132. data/lib/r2-oas/tasks/tool.rake +0 -76
  133. data/lib/r2-oas/tool/paths/ls.rb +0 -15
  134. data/lib/r2-oas/tool/paths/stats.rb +0 -84
@@ -1,3 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'sortable'
4
+ require_relative 'callable'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module R2OAS
4
+ module Callable
5
+ def deep_call(data, target, callback)
6
+ return data unless data.is_a?(Hash)
7
+
8
+ data.each do |key, value|
9
+ if key.eql? target
10
+ data[key] = callback.call(value)
11
+ else
12
+ data[key] = deep_call(value, target, callback)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -9,29 +9,32 @@ module R2OAS
9
9
  class Store
10
10
  attr_accessor :data
11
11
 
12
- def initialize(data = {})
12
+ def initialize(type, data = {})
13
13
  if data.empty?
14
14
  @data = {}
15
- @data['type'] = :schema
15
+ @type = type
16
+ @data['type'] = type
16
17
  @data['data'] = {}
17
18
  else
19
+ @type = type
18
20
  @data = data
19
21
  end
20
22
  end
21
23
 
22
- def add(key, value, type = :schema)
23
- sha1 = calc_sha1(key, value)
24
+ def add(key, value)
25
+ case @type
26
+ when :schema
27
+ sha1 = calc_sha1(key, value)
24
28
 
25
- @data['data'][sha1] ||= {}
26
- @data['type'] = type
27
- @data['data'][sha1]['key'] = key
28
- @data['data'][sha1]['value'] = Zlib::Deflate.deflate(value)
29
+ @data['data'][sha1] ||= {}
30
+ @data['data'][sha1]['key'] = key
31
+ @data['data'][sha1]['value'] = Zlib::Deflate.deflate(value)
32
+ end
29
33
  end
30
34
 
31
35
  def save
32
- type = @data['type']
33
36
  @data['data'].values.each do |value|
34
- case type
37
+ case @type
35
38
  when :schema
36
39
  save_path = value['key']
37
40
  save_data = Zlib::Inflate.inflate(value['value'])
@@ -43,7 +46,7 @@ module R2OAS
43
46
  end
44
47
 
45
48
  def dup_slice(*sha1s)
46
- dup_store = Store.new(@data.dup)
49
+ dup_store = Store.new(@type, @data.dup)
47
50
  dup_data = dup_store.data['data']
48
51
  dup_store.data['data'] = sha1s.each_with_object({}) { |sha1, data| data[sha1] = dup_data[sha1] if dup_store.key?(sha1) }
49
52
  dup_store
@@ -102,16 +105,17 @@ module R2OAS
102
105
  class << self
103
106
  extend Forwardable
104
107
 
105
- def_delegators :instance, :add
108
+ def_delegators :instance, :add, :save, :dup_slice, :checksum?, :key?, :exists?, :diff_from
106
109
 
107
- def create
108
- instance
110
+ def create(type = :schema)
111
+ instance(type)
109
112
  end
110
113
 
111
114
  private
112
115
 
113
- def instance
114
- @instance ||= new
116
+ def instance(type)
117
+ @instance ||= {}
118
+ @instance[type] ||= new(type)
115
119
  end
116
120
  end
117
121
  end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'singleton'
4
+
5
+ require_relative 'deprecation/instance_delegator'
6
+ require_relative 'deprecation/reporting'
7
+ require_relative 'deprecation/behavior'
8
+
9
+ module R2OAS
10
+ class Deprecation
11
+ include Singleton
12
+ # Be sure to follow the Singleton module
13
+ include InstanceDelegator
14
+ include Behavior
15
+ include Reporting
16
+
17
+ # The version number in which the deprecated behavior will be removed, by default.
18
+ attr_accessor :deprecation_horizon
19
+
20
+ def initialize(deprecation_horizon = '0.4.2', gem_name = 'r2-oas')
21
+ self.gem_name = gem_name
22
+ self.deprecation_horizon = deprecation_horizon
23
+ self.silenced = false
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MEMO:
4
+ # copy from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/deprecation/behaviors.rb
5
+ module R2OAS
6
+ class Deprecation
7
+ class DeprecationError < StandardError; end
8
+
9
+ DEFAULT_BEHAVIORS = {
10
+ stderr: lambda { |message, _callstack, _deprecation_horizon, _gem_name|
11
+ $stderr.puts(message)
12
+ }
13
+ }.freeze
14
+
15
+ module Behavior
16
+ def behavior
17
+ @behavior ||= [DEFAULT_BEHAVIORS[:stderr]]
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ # copy from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/deprecation/instance_delegator.rb
6
+ module R2OAS
7
+ class Deprecation
8
+ module InstanceDelegator
9
+ # MEMO:
10
+ # base must be singleton class
11
+ def self.included(base)
12
+ base.extend(ClassMethods)
13
+ base.singleton_class.extend(Forwardable)
14
+ base.singleton_class.prepend(OverrideDelegators)
15
+ base.public_class_method :new
16
+ end
17
+
18
+ module ClassMethods
19
+ # override Module#include
20
+ def include(included_module)
21
+ included_module.instance_methods.each { |m| method_added(m) }
22
+ super
23
+ end
24
+
25
+ def method_added(method_name)
26
+ singleton_class.def_delegators(:instance, method_name)
27
+ end
28
+ end
29
+
30
+ module OverrideDelegators
31
+ def warn(message = nil, callstack = nil)
32
+ # MEMO:
33
+ # Why update callstack
34
+ # https://github.com/rails/rails/pull/26686
35
+ callstack ||= caller_locations(2)
36
+ super
37
+ end
38
+ alias will_remove warn
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # MEMO:
4
+ # copy from https://github.com/rails/rails/blob/master/activesupport/lib/active_support/deprecation/reporting.rb
5
+ module R2OAS
6
+ class Deprecation
7
+ module Reporting
8
+ attr_accessor :silenced, :gem_name
9
+
10
+ FILE_LINE_METHOD_REGEXP = /^(?<file>.+?):(?<line>\d+)(?::in `(?<method>.*?)')?/.freeze
11
+ R2OAS_GEM_ROOT = File.expand_path('../../../../', __dir__) + '/lib'
12
+
13
+ def warn(message = nil, callstack = nil)
14
+ return if silenced
15
+
16
+ callstack ||= caller_locations(2)
17
+ deprecation_message(callstack, message).tap do |msg|
18
+ behavior.each { |b| b.call(msg, callstack, deprecation_horizon, gem_name) }
19
+ end
20
+ end
21
+ alias will_remove warn
22
+
23
+ def silence
24
+ old_silenced = silenced
25
+ self.silenced = true
26
+ yield if block_given?
27
+ self.silenced = old_silenced
28
+ end
29
+
30
+ private
31
+
32
+ def deprecation_message(callstack, message = nil)
33
+ message ||= 'You are using deprecated behavior which will be removed from the next major or minor release.'
34
+ "DEPRECATION WARNING: #{message} #{deprecation_caller_message(callstack)}"
35
+ end
36
+
37
+ def deprecation_caller_message(callstack)
38
+ file, line, method = extract_callstack(callstack)
39
+ if file
40
+ if line && method
41
+ "(called from #{method} at #{file}:#{line})"
42
+ else
43
+ "(called from #{file}:#{line})"
44
+ end
45
+ end
46
+ end
47
+
48
+ def extract_callstack(callstack)
49
+ return _extract_callback(callstack) if callstack.first.is_a? String
50
+
51
+ offending_line = callstack.find do |frame|
52
+ frame.absolute_path && !ignored_callstack(frame.absolute_path)
53
+ end || callstack.first
54
+
55
+ [offending_line.path, offending_line.lineno, offending_line.label]
56
+ end
57
+
58
+ # e.g.)
59
+ # callback = /path/to/file.rb:274:in `require'
60
+ #
61
+ # file = /path/to/file.rb
62
+ # line = 274
63
+ # method = require
64
+ def _extract_callstack(_callback)
65
+ warn 'Please pass `caller_options` to the deprecation API' if $VERBOSE
66
+ offending_line = callstack.find { |line| !ignored_callstack(line) || callstack.first }
67
+
68
+ if offendihng_line
69
+ md = offending_line.match(FILE_LINE_METHOD_REGEXP)
70
+
71
+ if md.present?
72
+ md.captures
73
+ else
74
+ offending_line
75
+ end
76
+ end
77
+ end
78
+
79
+ # MEMO:
80
+ # see https://docs.ruby-lang.org/ja/latest/class/RbConfig.html#C_-C-O-N-F-I-G
81
+ def ignored_callstack(path)
82
+ # MEMO:
83
+ #
84
+ # e.g.)
85
+ # R2OAS_GEM_ROOT = "/Users/yukihirop/RubyProjects/r2-oas/lib"
86
+ # rubylibprefix = "/Users/yukihirop/.rbenv/versions/2.7.1/lib/ruby"
87
+ path.start_with?(R2OAS_GEM_ROOT) || path.start_with?(RbConfig::CONFIG['rubylibprefix'])
88
+ end
89
+ end
90
+ end
91
+ end
@@ -4,8 +4,7 @@ module R2OAS
4
4
  class Task < ::Rails::Railtie
5
5
  rake_tasks do
6
6
  main_task_path = File.join(File.dirname(__FILE__), './tasks/main.rake')
7
- tool_task_path = File.join(File.dirname(__FILE__), './tasks/tool.rake')
8
- Dir[main_task_path, tool_task_path].each { |f| load f }
7
+ Dir[main_task_path].each { |f| load f }
9
8
  end
10
9
  end
11
10
  end
@@ -20,20 +20,16 @@ module R2OAS
20
20
 
21
21
  private
22
22
 
23
- def start
24
- logger.info '[R2-OAS] start'
23
+ def start(initial = '[R2-OAS]')
24
+ logger.info "#{initial} start"
25
25
  yield
26
- logger.info '[R2-OAS] end'
26
+ logger.info "#{initial} end"
27
27
  end
28
28
 
29
29
  def logger
30
30
  R2OAS.logger
31
31
  end
32
32
 
33
- def set_info_level
34
- R2OAS.logger.level = StdoutLogger::INFO
35
- end
36
-
37
33
  def set_debug_level
38
34
  R2OAS.logger.level = StdoutLogger::DEBUG
39
35
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../task_logging'
3
+ require 'r2-oas/task_logging'
4
4
 
5
5
  namespace :routes do
6
6
  namespace :oas do
@@ -10,7 +10,6 @@ namespace :routes do
10
10
  # desc "Setup a common setting for every tasks"
11
11
  task common: [:environment] do
12
12
  create_dot_paths
13
- set_info_level
14
13
  end
15
14
 
16
15
  # private
@@ -3,12 +3,19 @@
3
3
  require 'r2-oas/schema/editor'
4
4
  require 'r2-oas/schema/ui'
5
5
  require 'r2-oas/schema/monitor'
6
+ require 'r2-oas/deploy/client'
6
7
  require 'r2-oas/task_logging'
7
8
  load File.expand_path('common.rake', __dir__)
8
9
 
9
10
  namespace :routes do
10
11
  namespace :oas do
11
- desc 'Generate OAS documentation files'
12
+ desc '[R2-OAS] Initialize'
13
+ task init: [:common] do
14
+ R2OAS.init
15
+ puts '[R2-OAS] Initialized!'
16
+ end
17
+
18
+ desc '[R2-OAS] Generate OAS documentation files'
12
19
  task docs: [:common] do
13
20
  start do
14
21
  is_create_cache = cache_docs.eql? 'true'
@@ -18,7 +25,7 @@ namespace :routes do
18
25
  end
19
26
  end
20
27
 
21
- desc 'Analyze OAS documentation'
28
+ desc '[R2-OAS] Analyze OAS documentation'
22
29
  task analyze: [:common] do
23
30
  start do
24
31
  analyzer_options = { type: :existing, existing_schema_file_path: existing_schema_file_path }
@@ -31,16 +38,29 @@ namespace :routes do
31
38
  end
32
39
  end
33
40
 
34
- desc 'Distribute OAS documentation'
35
- task dist: [:common] do
41
+ desc '[R2-OAS] Build OAS documentation'
42
+ task build: [:common] do
36
43
  start do
37
- builder_options = { unit_paths_file_path: unit_paths_file_path }
44
+ output_dir_path = File.expand_path(R2OAS.output_dir_path)
45
+ FileUtils.mkdir_p(output_dir_path) unless FileTest.exists?(output_dir_path)
46
+
47
+ is_overrirde_src = override_src.eql? 'true'
48
+ use_plugin = skip_plugin.eql? 'false'
49
+ builder_options = { unit_paths_file_path: unit_paths_file_path, use_plugin: use_plugin, output: true }
38
50
  builder = R2OAS::Schema::Builder.new(builder_options)
39
51
  builder.build_docs
52
+
53
+ if is_overrirde_src
54
+ before_schama_data = builder.pure_oas_doc
55
+ after_schema_data = builder.oas_doc
56
+ analyzer_options = { type: :edited }
57
+ analyzer = R2OAS::Schema::Analyzer.new(before_schama_data, after_schema_data, analyzer_options)
58
+ analyzer.analyze_docs
59
+ end
40
60
  end
41
61
  end
42
62
 
43
- desc 'Open Swagger Editor'
63
+ desc '[R2-OAS] Open Swagger Editor'
44
64
  task editor: [:common] do
45
65
  start do
46
66
  builder_options = { unit_paths_file_path: unit_paths_file_path }
@@ -54,7 +74,7 @@ namespace :routes do
54
74
  end
55
75
  end
56
76
 
57
- desc 'Open Swagger UI'
77
+ desc '[R2-OAS] Open Swagger UI'
58
78
  task ui: [:common] do
59
79
  start do
60
80
  builder_options = { unit_paths_file_path: unit_paths_file_path }
@@ -67,7 +87,7 @@ namespace :routes do
67
87
  end
68
88
  end
69
89
 
70
- desc 'Monitor OAS Document'
90
+ desc '[R2-OAS] Monitor OAS Document'
71
91
  task monitor: [:common] do
72
92
  start do
73
93
  builder_options = { unit_paths_file_path: unit_paths_file_path }
@@ -81,7 +101,7 @@ namespace :routes do
81
101
  end
82
102
  end
83
103
 
84
- desc 'Clean OAS Document'
104
+ desc '[R2-OAS] Clean OAS Document'
85
105
  task clean: [:common] do
86
106
  start do
87
107
  builder_options = { skip_load_dot_paths: true }
@@ -93,6 +113,29 @@ namespace :routes do
93
113
  end
94
114
  end
95
115
 
116
+ desc '[R2-OAS] Deploy OAS Document'
117
+ task deploy: [:common] do
118
+ start do
119
+ client_options = {}
120
+ client = R2OAS::Deploy::Client.new(client_options)
121
+
122
+ download_dist_th = Thread.new do
123
+ puts 'Download swagger-api/swagger-ui/dist ... (async)'
124
+ client.download_swagger_ui_dist
125
+ end
126
+
127
+ output_dir_path = File.expand_path(R2OAS.output_dir_path)
128
+ FileUtils.mkdir_p(output_dir_path) unless FileTest.exists?(output_dir_path)
129
+
130
+ builder_options = { unit_paths_file_path: unit_paths_file_path, use_plugin: true, output: true }
131
+ builder = R2OAS::Schema::Builder.new(builder_options)
132
+ builder.build_docs
133
+
134
+ download_dist_th.join
135
+ client.deploy
136
+ end
137
+ end
138
+
96
139
  private
97
140
 
98
141
  def unit_paths_file_path
@@ -106,5 +149,13 @@ namespace :routes do
106
149
  def cache_docs
107
150
  ENV.fetch('CACHE_DOCS', 'false')
108
151
  end
152
+
153
+ def override_src
154
+ ENV.fetch('OVERRIDE_SRC', 'false')
155
+ end
156
+
157
+ def skip_plugin
158
+ ENV.fetch('SKIP_PLUGIN', 'false')
159
+ end
109
160
  end
110
161
  end