r2-oas 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +99 -0
- data/GEMSPEC.md +20 -0
- data/LICENSE.txt +21 -0
- data/README.ja.md +271 -0
- data/README.md +271 -0
- data/lib/r2-oas.rb +35 -0
- data/lib/r2-oas/app_configuration.rb +121 -0
- data/lib/r2-oas/app_configuration/deprecation.rb +28 -0
- data/lib/r2-oas/app_configuration/server.rb +35 -0
- data/lib/r2-oas/app_configuration/swagger.rb +35 -0
- data/lib/r2-oas/app_configuration/swagger/editor.rb +47 -0
- data/lib/r2-oas/app_configuration/swagger/ui.rb +45 -0
- data/lib/r2-oas/app_configuration/tool.rb +31 -0
- data/lib/r2-oas/app_configuration/tool/paths/stats.rb +43 -0
- data/lib/r2-oas/base.rb +48 -0
- data/lib/r2-oas/configuration.rb +121 -0
- data/lib/r2-oas/configuration/paths_config.rb +44 -0
- data/lib/r2-oas/deploy/client.rb +70 -0
- data/lib/r2-oas/deploy/swagger-ui/index.html.erb +60 -0
- data/lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb +100 -0
- data/lib/r2-oas/errors.rb +13 -0
- data/lib/r2-oas/hooks/global_hook.rb +20 -0
- data/lib/r2-oas/hooks/hook.rb +79 -0
- data/lib/r2-oas/hooks/repository.rb +15 -0
- data/lib/r2-oas/lib/core_ext/hash/deep_merge.rb +44 -0
- data/lib/r2-oas/lib/core_ext/object/blank.rb +135 -0
- data/lib/r2-oas/lib/three-way-merge/twm.rb +83 -0
- data/lib/r2-oas/logger/stdout_logger.rb +129 -0
- data/lib/r2-oas/pluggable_configuration.rb +36 -0
- data/lib/r2-oas/plugin/base.rb +44 -0
- data/lib/r2-oas/plugin/executor.rb +148 -0
- data/lib/r2-oas/plugin/hookable.rb +42 -0
- data/lib/r2-oas/plugin/public.rb +3 -0
- data/lib/r2-oas/plugin/transform/transform.rb +10 -0
- data/lib/r2-oas/plugin/transform/v3/transform.rb +20 -0
- data/lib/r2-oas/plugin/transform/v3/visitable.rb +37 -0
- data/lib/r2-oas/public.rb +5 -0
- data/lib/r2-oas/routing/adjustor.rb +44 -0
- data/lib/r2-oas/routing/base.rb +12 -0
- data/lib/r2-oas/routing/components/all.rb +5 -0
- data/lib/r2-oas/routing/components/base_component.rb +10 -0
- data/lib/r2-oas/routing/components/path_component.rb +67 -0
- data/lib/r2-oas/routing/components/request_component.rb +75 -0
- data/lib/r2-oas/routing/components/verb_component.rb +21 -0
- data/lib/r2-oas/routing/parser.rb +93 -0
- data/lib/r2-oas/schema/analyzer.rb +23 -0
- data/lib/r2-oas/schema/base.rb +11 -0
- data/lib/r2-oas/schema/builder.rb +23 -0
- data/lib/r2-oas/schema/cleaner.rb +23 -0
- data/lib/r2-oas/schema/editor.rb +146 -0
- data/lib/r2-oas/schema/generator.rb +23 -0
- data/lib/r2-oas/schema/manager/file/path_item_file_manager.rb +24 -0
- data/lib/r2-oas/schema/manager/file_manager.rb +26 -0
- data/lib/r2-oas/schema/monitor.rb +52 -0
- data/lib/r2-oas/schema/squeezer.rb +23 -0
- data/lib/r2-oas/schema/ui.rb +73 -0
- data/lib/r2-oas/schema/v3/analyzer.rb +58 -0
- data/lib/r2-oas/schema/v3/analyzer/base_analyzer.rb +71 -0
- data/lib/r2-oas/schema/v3/analyzer/components/object_analyzer.rb +38 -0
- data/lib/r2-oas/schema/v3/analyzer/components_analyzer.rb +30 -0
- data/lib/r2-oas/schema/v3/analyzer/path_analyzer.rb +116 -0
- data/lib/r2-oas/schema/v3/analyzer/tag_analyzer.rb +38 -0
- data/lib/r2-oas/schema/v3/base.rb +28 -0
- data/lib/r2-oas/schema/v3/builder.rb +28 -0
- data/lib/r2-oas/schema/v3/builder/base_builder.rb +72 -0
- data/lib/r2-oas/schema/v3/builder/doc_builder.rb +51 -0
- data/lib/r2-oas/schema/v3/cleaner.rb +19 -0
- data/lib/r2-oas/schema/v3/cleaner/base_cleaner.rb +30 -0
- data/lib/r2-oas/schema/v3/cleaner/components_cleaner.rb +42 -0
- data/lib/r2-oas/schema/v3/generator.rb +24 -0
- data/lib/r2-oas/schema/v3/generator/base_generator.rb +122 -0
- data/lib/r2-oas/schema/v3/generator/components/object_generator.rb +64 -0
- data/lib/r2-oas/schema/v3/generator/components/request_body_generator.rb +45 -0
- data/lib/r2-oas/schema/v3/generator/components_generator.rb +38 -0
- data/lib/r2-oas/schema/v3/generator/doc_generator.rb +115 -0
- data/lib/r2-oas/schema/v3/generator/path_generator.rb +78 -0
- data/lib/r2-oas/schema/v3/generator/schema_generator.rb +58 -0
- data/lib/r2-oas/schema/v3/manager/diff/base_array_diff_manager.rb +60 -0
- data/lib/r2-oas/schema/v3/manager/diff/base_diff_manager.rb +29 -0
- data/lib/r2-oas/schema/v3/manager/diff/base_hash_diff_manager.rb +95 -0
- data/lib/r2-oas/schema/v3/manager/diff/components_diff_manager.rb +19 -0
- data/lib/r2-oas/schema/v3/manager/diff/tag_diff_manager.rb +17 -0
- data/lib/r2-oas/schema/v3/manager/file/base_file_manager.rb +66 -0
- data/lib/r2-oas/schema/v3/manager/file/components_file_manager.rb +22 -0
- data/lib/r2-oas/schema/v3/manager/file/include_ref_base_file_manager.rb +89 -0
- data/lib/r2-oas/schema/v3/manager/file/path_item_file_manager.rb +22 -0
- data/lib/r2-oas/schema/v3/manager/file_manager.rb +12 -0
- data/lib/r2-oas/schema/v3/manager/pathname_manager.rb +78 -0
- data/lib/r2-oas/schema/v3/object/from_files/base_object.rb +62 -0
- data/lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb +103 -0
- data/lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb +102 -0
- data/lib/r2-oas/schema/v3/object/from_files/components_object.rb +46 -0
- data/lib/r2-oas/schema/v3/object/from_files/external_document_object.rb +23 -0
- data/lib/r2-oas/schema/v3/object/from_files/info_object.rb +23 -0
- data/lib/r2-oas/schema/v3/object/from_files/openapi_object.rb +61 -0
- data/lib/r2-oas/schema/v3/object/from_files/path_item_object.rb +110 -0
- data/lib/r2-oas/schema/v3/object/from_files/paths_object.rb +33 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/all.rb +4 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/deep_methods.rb +27 -0
- data/lib/r2-oas/schema/v3/object/from_files/utils/refs.rb +151 -0
- data/lib/r2-oas/schema/v3/object/from_routes/base_object.rb +75 -0
- data/lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb +96 -0
- data/lib/r2-oas/schema/v3/object/from_routes/components/schema_object.rb +59 -0
- data/lib/r2-oas/schema/v3/object/from_routes/components_object.rb +81 -0
- data/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb +28 -0
- data/lib/r2-oas/schema/v3/object/from_routes/info_object.rb +43 -0
- data/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb +59 -0
- data/lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb +175 -0
- data/lib/r2-oas/schema/v3/object/from_routes/paths_object.rb +77 -0
- data/lib/r2-oas/schema/v3/object/from_routes/public.rb +9 -0
- data/lib/r2-oas/schema/v3/object/from_routes/server_object.rb +21 -0
- data/lib/r2-oas/schema/v3/object/from_routes/tag_object.rb +37 -0
- data/lib/r2-oas/schema/v3/object/store.rb +54 -0
- data/lib/r2-oas/schema/v3/squeezer.rb +29 -0
- data/lib/r2-oas/schema/v3/squeezer/base_squeezer.rb +37 -0
- data/lib/r2-oas/schema/v3/squeezer/path_squeezer.rb +28 -0
- data/lib/r2-oas/schema/v3/squeezer/tag_squeezer.rb +19 -0
- data/lib/r2-oas/shared/all.rb +4 -0
- data/lib/r2-oas/shared/callable.rb +17 -0
- data/lib/r2-oas/shared/sortable.rb +23 -0
- data/lib/r2-oas/store.rb +122 -0
- data/lib/r2-oas/support/deprecation.rb +24 -0
- data/lib/r2-oas/support/deprecation/behavior.rb +21 -0
- data/lib/r2-oas/support/deprecation/instance_delegator.rb +42 -0
- data/lib/r2-oas/support/deprecation/reporting.rb +91 -0
- data/lib/r2-oas/task.rb +11 -0
- data/lib/r2-oas/task_logging.rb +41 -0
- data/lib/r2-oas/tasks/common.rake +25 -0
- data/lib/r2-oas/tasks/main.rake +132 -0
- data/lib/r2-oas/tasks/tool.rake +86 -0
- data/lib/r2-oas/tool/paths/ls.rb +15 -0
- data/lib/r2-oas/tool/paths/stats.rb +84 -0
- data/lib/r2-oas/version.rb +5 -0
- data/r2-oas.gemspec +48 -0
- metadata +415 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_analyzer'
|
4
|
+
require 'r2-oas/schema/v3/manager/file_manager'
|
5
|
+
require 'r2-oas/schema/v3/manager/diff/tag_diff_manager'
|
6
|
+
|
7
|
+
# Scope Rails
|
8
|
+
module R2OAS
|
9
|
+
module Schema
|
10
|
+
module V3
|
11
|
+
class TagAnalyzer < BaseAnalyzer
|
12
|
+
def initialize(after_schema_data, options = {})
|
13
|
+
super({}, after_schema_data, options)
|
14
|
+
@file_manager = FileManager.new('tags', :relative)
|
15
|
+
before_schema_data = @file_manager.load_data
|
16
|
+
@diff_manager = TagDiffManager.new(before_schema_data, after_schema_data)
|
17
|
+
end
|
18
|
+
|
19
|
+
def analyze_docs
|
20
|
+
save_file_path = @file_manager.save_file_path(type: :relative)
|
21
|
+
case @type
|
22
|
+
when :edited
|
23
|
+
@diff_manager.process_by_using_diff_data do |after_edited_data|
|
24
|
+
@file_manager.save(after_edited_data.to_yaml)
|
25
|
+
logger.info " Write schema file: \t#{save_file_path}"
|
26
|
+
end
|
27
|
+
when :existing
|
28
|
+
result = @diff_manager.after_target_data
|
29
|
+
@file_manager.save(result.to_yaml)
|
30
|
+
logger.info " Write schema file: \t#{save_file_path}"
|
31
|
+
else
|
32
|
+
raise NoImplementError
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative '../base'
|
4
|
+
|
5
|
+
# Scope Rails
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
class Base < ::R2OAS::Schema::Base
|
10
|
+
SUPPORT_COMPONENTS_OBJECTS = %w[
|
11
|
+
schemas
|
12
|
+
requestBodies
|
13
|
+
securitySchemes
|
14
|
+
parameters
|
15
|
+
responses
|
16
|
+
examples
|
17
|
+
headers
|
18
|
+
links
|
19
|
+
callbacks
|
20
|
+
].freeze
|
21
|
+
|
22
|
+
def support_components_objects
|
23
|
+
SUPPORT_COMPONENTS_OBJECTS
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'r2-oas/routing/parser'
|
6
|
+
require_relative 'builder/doc_builder'
|
7
|
+
require_relative 'builder/base_builder'
|
8
|
+
|
9
|
+
module R2OAS
|
10
|
+
module Schema
|
11
|
+
module V3
|
12
|
+
class Builder < BaseBuilder
|
13
|
+
extend Forwardable
|
14
|
+
|
15
|
+
def_delegators :@doc_builder, :oas_doc, :pure_oas_doc
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
super
|
19
|
+
@doc_builder = DocBuilder.new(options)
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_docs
|
23
|
+
@doc_builder.build_docs
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/schema/v3/base'
|
4
|
+
require 'r2-oas/routing/parser'
|
5
|
+
require 'r2-oas/schema/v3/object/from_routes/openapi_object'
|
6
|
+
require 'r2-oas/schema/v3/manager/file/path_item_file_manager'
|
7
|
+
|
8
|
+
module R2OAS
|
9
|
+
module Schema
|
10
|
+
module V3
|
11
|
+
class BaseBuilder < Base
|
12
|
+
include Sortable
|
13
|
+
|
14
|
+
def initialize(opts = {})
|
15
|
+
super
|
16
|
+
|
17
|
+
opts.keys.each do |key|
|
18
|
+
send("#{key}=", opts[key])
|
19
|
+
end
|
20
|
+
|
21
|
+
@opts = opts
|
22
|
+
@glob_schema_paths = create_glob_schema_paths
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_accessor :unit_paths_file_path
|
28
|
+
attr_accessor :skip_load_dot_paths
|
29
|
+
attr_accessor :opts
|
30
|
+
attr_accessor :use_plugin
|
31
|
+
attr_accessor :output
|
32
|
+
|
33
|
+
alias use_plugin? use_plugin
|
34
|
+
alias output? output
|
35
|
+
|
36
|
+
def schema_file_do_not_exists?
|
37
|
+
schema_files_paths.count == 0
|
38
|
+
end
|
39
|
+
|
40
|
+
def create_glob_schema_paths
|
41
|
+
exclude_paths_regexp_paths = ["#{schema_save_dir_path}/**.yml"]
|
42
|
+
components_security_schemes_regexp_paths = ["#{schema_save_dir_path}/components/securitySchemes/**/**.yml"]
|
43
|
+
|
44
|
+
# components/securitySchemes is not referenced in $ ref.
|
45
|
+
exclude_paths_regexp_paths + many_paths_file_paths + many_components_file_paths + components_security_schemes_regexp_paths
|
46
|
+
end
|
47
|
+
|
48
|
+
def schema_files_paths
|
49
|
+
Dir.glob(@glob_schema_paths)
|
50
|
+
end
|
51
|
+
|
52
|
+
def many_paths_file_paths
|
53
|
+
if unit_paths_file_path.present? && !skip_load_dot_paths
|
54
|
+
[unit_paths_file_path]
|
55
|
+
elsif !unit_paths_file_path.present? && !skip_load_dot_paths && paths_config.all_load_paths?
|
56
|
+
paths_config.many_paths_file_paths
|
57
|
+
else
|
58
|
+
Dir.glob("#{schema_save_dir_path}/paths/**/**.yml")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def many_components_file_paths
|
63
|
+
@many_components_file_paths ||= many_paths_file_paths.each_with_object([]) do |unit_paths_path, result|
|
64
|
+
file_manager = PathItemFileManager.new(unit_paths_path, :full)
|
65
|
+
components_file_paths_at_path = file_manager.descendants_ref_paths
|
66
|
+
result.push(*components_file_paths_at_path)
|
67
|
+
end.uniq
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'fileutils'
|
5
|
+
require 'r2-oas/schema/v3/object/from_files/openapi_object'
|
6
|
+
require_relative 'base_builder'
|
7
|
+
|
8
|
+
module R2OAS
|
9
|
+
module Schema
|
10
|
+
module V3
|
11
|
+
class DocBuilder < BaseBuilder
|
12
|
+
attr_accessor :oas_doc, :pure_oas_doc
|
13
|
+
|
14
|
+
def initialize(opts = {})
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_docs
|
19
|
+
logger.info '[Build OAS schema files] start'
|
20
|
+
logger.info '[Build OAS docs from schema files] start'
|
21
|
+
build_docs_from_schema_files
|
22
|
+
logger.info '[Build OAS docs from schema files] end'
|
23
|
+
logger.info '[Build OAS schema files] end'
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_docs_from_schema_files
|
29
|
+
result_before_squeeze = schema_files_paths.each_with_object({}) do |path, data|
|
30
|
+
file_manager = FileManager.new(path)
|
31
|
+
yaml = YAML.load_file(path)
|
32
|
+
data.deep_merge!(yaml)
|
33
|
+
logger.info " Use schema file: \t#{file_manager.save_file_path(type: :relative)}"
|
34
|
+
end
|
35
|
+
|
36
|
+
result = if many_paths_file_paths.present?
|
37
|
+
Squeezer.new(result_before_squeeze, many_paths_file_paths: many_paths_file_paths).squeeze_docs
|
38
|
+
else
|
39
|
+
result_before_squeeze
|
40
|
+
end
|
41
|
+
|
42
|
+
@pure_oas_doc = result.dup
|
43
|
+
rsult = FromFiles::OpenapiObject.new(result, opts).to_doc if use_plugin?
|
44
|
+
@oas_doc = result
|
45
|
+
|
46
|
+
File.write(output? ? output_path : doc_save_file_path, result.to_yaml)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'cleaner/base_cleaner'
|
4
|
+
require_relative 'cleaner/components_cleaner'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
class Cleaner < BaseCleaner
|
10
|
+
def clean_docs
|
11
|
+
logger.info '[Clean OAS file] start'
|
12
|
+
components_cleaner = ComponentsCleaner.new(@options)
|
13
|
+
components_cleaner.clean_docs
|
14
|
+
logger.info '[Clean OAS file] end'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/schema/v3/base'
|
4
|
+
require 'r2-oas/schema/v3/manager/file_manager'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
class BaseCleaner < Base
|
10
|
+
def clean_docs
|
11
|
+
clean_target_files.each do |file_path|
|
12
|
+
file_manager = FileManager.new(file_path, :full)
|
13
|
+
file_manager.delete
|
14
|
+
yield file_manager.save_file_path(type: :relative) if block_given?
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def many_paths_file_paths
|
21
|
+
Dir.glob("#{schema_save_dir_path}/paths/**/**.yml")
|
22
|
+
end
|
23
|
+
|
24
|
+
def clean_target_files
|
25
|
+
raise 'Please implement in inherited class.'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_cleaner'
|
4
|
+
require 'r2-oas/schema/v3/manager/file/path_item_file_manager'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
class ComponentsCleaner < BaseCleaner
|
10
|
+
def initialize(options = {})
|
11
|
+
super
|
12
|
+
@components_file_paths = Dir.glob("#{schema_save_dir_path}/components/**/**.yml")
|
13
|
+
@security_schemes_paths = Dir.glob("#{schema_save_dir_path}/components/securitySchemes/**/**.yml")
|
14
|
+
end
|
15
|
+
|
16
|
+
def clean_docs
|
17
|
+
logger.info '[Clean OAS file (components)] start'
|
18
|
+
super do |file_path|
|
19
|
+
logger.info " Delete schema file: \t#{file_path}"
|
20
|
+
end
|
21
|
+
logger.info '[Clean OAS file (components)] end'
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def clean_target_files
|
27
|
+
used_file_paths = many_paths_file_paths.each_with_object([]) do |unit_paths_path, result|
|
28
|
+
file_manager = PathItemFileManager.new(unit_paths_path, :full)
|
29
|
+
components_file_paths_at_path = file_manager.descendants_ref_paths
|
30
|
+
result.push(*components_file_paths_at_path)
|
31
|
+
end.uniq
|
32
|
+
|
33
|
+
all_file_paths - used_file_paths
|
34
|
+
end
|
35
|
+
|
36
|
+
def all_file_paths
|
37
|
+
(@components_file_paths - @security_schemes_paths).uniq
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'forwardable'
|
5
|
+
require 'r2-oas/routing/parser'
|
6
|
+
require_relative 'generator/doc_generator'
|
7
|
+
require_relative 'generator/base_generator'
|
8
|
+
|
9
|
+
module R2OAS
|
10
|
+
module Schema
|
11
|
+
module V3
|
12
|
+
class Generator < BaseGenerator
|
13
|
+
extend Forwardable
|
14
|
+
|
15
|
+
def_delegators :@doc_generator, :generate_docs
|
16
|
+
|
17
|
+
def initialize(options = {})
|
18
|
+
super
|
19
|
+
@doc_generator = DocGenerator.new(options)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/schema/v3/base'
|
4
|
+
require 'r2-oas/routing/parser'
|
5
|
+
require 'r2-oas/schema/v3/object/from_routes/openapi_object'
|
6
|
+
require 'r2-oas/schema/v3/manager/file/path_item_file_manager'
|
7
|
+
require 'r2-oas/store'
|
8
|
+
|
9
|
+
module R2OAS
|
10
|
+
module Schema
|
11
|
+
module V3
|
12
|
+
class BaseGenerator < Base
|
13
|
+
include Sortable
|
14
|
+
|
15
|
+
def initialize(options = {})
|
16
|
+
super
|
17
|
+
|
18
|
+
options.keys.each do |key|
|
19
|
+
send("#{key}=", options[key])
|
20
|
+
end
|
21
|
+
|
22
|
+
@store = ::R2OAS::Store.create(:schema)
|
23
|
+
@glob_schema_paths = create_glob_schema_paths
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
attr_accessor :unit_paths_file_path
|
29
|
+
attr_accessor :skip_load_dot_paths
|
30
|
+
attr_accessor :is_create_cache
|
31
|
+
attr_accessor :store
|
32
|
+
|
33
|
+
# Scope Rails
|
34
|
+
def create_docs
|
35
|
+
all_routes = create_all_routes
|
36
|
+
parser = Routing::Parser.new(all_routes)
|
37
|
+
|
38
|
+
routes_data = parser.routes_data
|
39
|
+
tags_data = parser.tags_data
|
40
|
+
schemas_data = parser.schemas_data
|
41
|
+
|
42
|
+
Schema::V3::OpenapiObject.new(routes_data, tags_data, schemas_data).to_doc
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_all_routes
|
46
|
+
::Rails.application.reload_routes!
|
47
|
+
::Rails.application.routes.routes
|
48
|
+
end
|
49
|
+
|
50
|
+
def schema_file_do_not_exists?
|
51
|
+
schema_files_paths.count == 0
|
52
|
+
end
|
53
|
+
|
54
|
+
def create_glob_schema_paths
|
55
|
+
exclude_paths_regexp_paths = ["#{schema_save_dir_path}/**.yml"]
|
56
|
+
paths_regexp_paths = ["#{schema_save_dir_path}/paths/**/**.yml"]
|
57
|
+
components_schemas_regexp_paths = ["#{schema_save_dir_path}/components/**/**.yml"]
|
58
|
+
components_security_schemes_regexp_paths = ["#{schema_save_dir_path}/components/securitySchemes/**/**.yml"]
|
59
|
+
|
60
|
+
if exists_paths_files?
|
61
|
+
# components/securitySchemes is not referenced in $ ref.
|
62
|
+
exclude_paths_regexp_paths + many_paths_file_paths + many_components_file_paths + components_security_schemes_regexp_paths
|
63
|
+
else
|
64
|
+
exclude_paths_regexp_paths + paths_regexp_paths + components_schemas_regexp_paths
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def schema_files_paths
|
69
|
+
Dir.glob(@glob_schema_paths)
|
70
|
+
end
|
71
|
+
|
72
|
+
def many_paths_file_paths
|
73
|
+
if unit_paths_file_path.present? && !skip_load_dot_paths
|
74
|
+
[unit_paths_file_path]
|
75
|
+
elsif !unit_paths_file_path.present? && !skip_load_dot_paths && paths_config.all_load_paths?
|
76
|
+
paths_config.many_paths_file_paths
|
77
|
+
else
|
78
|
+
Dir.glob("#{schema_save_dir_path}/paths/**/**.yml")
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def many_components_file_paths
|
83
|
+
@many_components_file_paths ||= many_paths_file_paths.each_with_object([]) do |unit_paths_path, result|
|
84
|
+
file_manager = PathItemFileManager.new(unit_paths_path, :full)
|
85
|
+
components_file_paths_at_path = file_manager.descendants_ref_paths
|
86
|
+
result.push(*components_file_paths_at_path)
|
87
|
+
end.uniq
|
88
|
+
end
|
89
|
+
|
90
|
+
def exists_paths_files?
|
91
|
+
Dir.glob("#{schema_save_dir_path}/paths/**/**.yml").present?
|
92
|
+
end
|
93
|
+
|
94
|
+
def cache_docs
|
95
|
+
if exists_cache?
|
96
|
+
result = IO.binread(abs_cache_docs_path)
|
97
|
+
inflate = Zlib::Inflate.inflate(result)
|
98
|
+
@cache_docs ||= Marshal.load(inflate)
|
99
|
+
else
|
100
|
+
@cache_docs ||= {}
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def exists_cache?
|
105
|
+
FileTest.exists?(abs_cache_docs_path)
|
106
|
+
end
|
107
|
+
|
108
|
+
def abs_cache_docs_path
|
109
|
+
File.expand_path(relative_cahe_docs_path)
|
110
|
+
end
|
111
|
+
|
112
|
+
def relative_cahe_docs_path
|
113
|
+
"#{@root_dir_path}/.docs"
|
114
|
+
end
|
115
|
+
|
116
|
+
def unknown_paths_path
|
117
|
+
"#{@root_dir_path}/src/paths/unknown.yml"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|