r2-oas 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/ISSUE_TEMPLATE.md +12 -0
- data/.github/PULL_REQUEST_TEMPLATE.md +12 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +7 -0
- data/.rubocop_todo.yml +224 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +3 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +207 -0
- data/LICENSE.txt +21 -0
- data/README.ja.md +585 -0
- data/README.md +582 -0
- data/Rakefile +8 -0
- data/bin/console +12 -0
- data/bin/setup +8 -0
- data/docs/HOW_TO_ANALYZE_DOCS.md +875 -0
- data/docs/HOW_TO_CLEAN_DOCS.md +19 -0
- data/docs/HOW_TO_DEPLOY_SWAGGER_DOC.md +839 -0
- data/docs/HOW_TO_DISPLAY_PATHS_LIST.md +28 -0
- data/docs/HOW_TO_DISPLAY_PATHS_STATS.md +53 -0
- data/docs/HOW_TO_GENERATE_DOCS.md +256 -0
- data/docs/HOW_TO_MONITOR_SWAGGER_DOC.md +219 -0
- data/docs/HOW_TO_START_SWAGGER_EDITOR.md +218 -0
- data/docs/HOW_TO_START_SWAGGER_UI.md +262 -0
- data/docs/HOW_TO_USE_HOOK_WHEN_GENERATE_DOC.md +244 -0
- data/docs/HOW_TO_USE_SCHEMA_NAMESPACE.md +176 -0
- data/docs/HOW_TO_USE_TAG_NAMESPACE.md +176 -0
- data/docs/versions/v3.md +155 -0
- data/lib/r2-oas.rb +36 -0
- data/lib/r2-oas/app_configuration.rb +102 -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 +69 -0
- data/lib/r2-oas/configuration/paths_config.rb +44 -0
- data/lib/r2-oas/deploy/client.rb +43 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/favicon-16x16.png +0 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/favicon-32x32.png +0 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/oauth2-redirect.html +68 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js +134 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-bundle.js.map +1 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js +22 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui-standalone-preset.js.map +1 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css +4 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.css.map +1 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js +9 -0
- data/lib/r2-oas/deploy/swagger-ui/dist/swagger-ui.js.map +1 -0
- data/lib/r2-oas/deploy/swagger-ui/index.html.erb +60 -0
- data/lib/r2-oas/errors.rb +7 -0
- data/lib/r2-oas/hooks/global_hook.rb +20 -0
- data/lib/r2-oas/hooks/hook.rb +77 -0
- data/lib/r2-oas/hooks/repository.rb +15 -0
- data/lib/r2-oas/logger/stdout_logger.rb +129 -0
- data/lib/r2-oas/pluggable_configuration.rb +33 -0
- data/lib/r2-oas/plugins/schema/v3/object/hookable_base_object.rb +100 -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/cleaner.rb +23 -0
- data/lib/r2-oas/schema/editor.rb +120 -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/monitor.rb +52 -0
- data/lib/r2-oas/schema/squeezer.rb +23 -0
- data/lib/r2-oas/schema/ui.rb +74 -0
- data/lib/r2-oas/schema/v3/analyzer.rb +58 -0
- data/lib/r2-oas/schema/v3/analyzer/base_analyzer.rb +76 -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/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 +28 -0
- data/lib/r2-oas/schema/v3/generator/base_generator.rb +88 -0
- data/lib/r2-oas/schema/v3/generator/components/object_generator.rb +83 -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 +49 -0
- data/lib/r2-oas/schema/v3/generator/path_generator.rb +90 -0
- data/lib/r2-oas/schema/v3/generator/schema_generator.rb +78 -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 +60 -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 +88 -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 +73 -0
- data/lib/r2-oas/schema/v3/object/base_object.rb +65 -0
- data/lib/r2-oas/schema/v3/object/components/request_body_object.rb +92 -0
- data/lib/r2-oas/schema/v3/object/components/schema_object.rb +55 -0
- data/lib/r2-oas/schema/v3/object/components_object.rb +81 -0
- data/lib/r2-oas/schema/v3/object/external_document_object.rb +19 -0
- data/lib/r2-oas/schema/v3/object/info_object.rb +34 -0
- data/lib/r2-oas/schema/v3/object/openapi_object.rb +58 -0
- data/lib/r2-oas/schema/v3/object/path_item_object.rb +167 -0
- data/lib/r2-oas/schema/v3/object/paths_object.rb +74 -0
- data/lib/r2-oas/schema/v3/object/public.rb +9 -0
- data/lib/r2-oas/schema/v3/object/server_object.rb +21 -0
- data/lib/r2-oas/schema/v3/object/tag_object.rb +36 -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 +3 -0
- data/lib/r2-oas/shared/sortable.rb +23 -0
- data/lib/r2-oas/task.rb +11 -0
- data/lib/r2-oas/task_logging.rb +39 -0
- data/lib/r2-oas/tasks/common.rake +26 -0
- data/lib/r2-oas/tasks/main.rake +117 -0
- data/lib/r2-oas/tasks/tool.rake +79 -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 +56 -0
- metadata +373 -0
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'include_ref_base_file_manager'
|
4
|
+
|
5
|
+
module R2OAS
|
6
|
+
module Schema
|
7
|
+
module V3
|
8
|
+
class ComponentsFileManager < IncludeRefBaseFileManager
|
9
|
+
def initialize(path, path_type = :ref)
|
10
|
+
super
|
11
|
+
@path_type = path_type
|
12
|
+
@original_path = path
|
13
|
+
@recursive_search_class = self.class
|
14
|
+
end
|
15
|
+
|
16
|
+
def skip_save?
|
17
|
+
save_file_path.in? paths_config.many_components_file_paths
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'base_file_manager'
|
4
|
+
require_relative '../pathname_manager'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
class IncludeRefBaseFileManager < BaseFileManager
|
10
|
+
REF = '$ref'
|
11
|
+
|
12
|
+
def initialize(path, path_type = :ref)
|
13
|
+
super
|
14
|
+
@convert_underscore_to_slash = true
|
15
|
+
@parent_save_file_paths = []
|
16
|
+
@recursive_search_class = self.class
|
17
|
+
end
|
18
|
+
|
19
|
+
class << self
|
20
|
+
alias build new
|
21
|
+
end
|
22
|
+
|
23
|
+
def descendants_paths
|
24
|
+
results = []
|
25
|
+
|
26
|
+
deep_search_ref_recursive(load_data) do |relative_paths|
|
27
|
+
results.push(*relative_paths)
|
28
|
+
end
|
29
|
+
|
30
|
+
results.uniq
|
31
|
+
end
|
32
|
+
alias descendants_ref_paths descendants_paths
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
attr_accessor :parent_save_file_paths, :recursive_search_class
|
37
|
+
|
38
|
+
def deep_search_ref_recursive(yaml, &block)
|
39
|
+
if yaml.is_a?(Hash)
|
40
|
+
yaml.each do |key, value|
|
41
|
+
process_deep_search_ref_recursive(key, value, &block)
|
42
|
+
end
|
43
|
+
# Support allOf/oneOf/anyOf
|
44
|
+
elsif yaml.is_a?(Array)
|
45
|
+
yaml.each do |el|
|
46
|
+
next unless el.is_a?(Hash)
|
47
|
+
|
48
|
+
el.each do |key, value|
|
49
|
+
process_deep_search_ref_recursive(key, value, &block)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def process_deep_search_ref_recursive(ref_key_or_not, ref_value_or_not, &block)
|
56
|
+
# Don't pick up JSON Schema $ref
|
57
|
+
# e.x.)
|
58
|
+
# $ref: { "type" => "string" }
|
59
|
+
if (ref_key_or_not.eql? REF) && ref_value_or_not.to_s.start_with?('#/')
|
60
|
+
|
61
|
+
# Avoid $ ref circular references
|
62
|
+
pm = PathnameManager.new(ref_value_or_not, :ref)
|
63
|
+
relative_save_file_path = pm.relative_save_file_path
|
64
|
+
|
65
|
+
if @parent_save_file_paths.include?(relative_save_file_path)
|
66
|
+
return
|
67
|
+
else
|
68
|
+
@parent_save_file_paths.push(relative_save_file_path)
|
69
|
+
end
|
70
|
+
|
71
|
+
child_file_manager = @recursive_search_class.build(ref_value_or_not, :ref)
|
72
|
+
child_load_data = child_file_manager.load_data
|
73
|
+
|
74
|
+
children_paths = []
|
75
|
+
deep_search_ref_recursive(child_load_data) do |children_path|
|
76
|
+
children_paths.push(*children_path)
|
77
|
+
end
|
78
|
+
|
79
|
+
results = [child_file_manager.save_file_path] + children_paths
|
80
|
+
yield results if block_given?
|
81
|
+
else
|
82
|
+
deep_search_ref_recursive(ref_value_or_not, &block)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'include_ref_base_file_manager'
|
4
|
+
require_relative 'components_file_manager'
|
5
|
+
require_relative '../pathname_manager'
|
6
|
+
|
7
|
+
module R2OAS
|
8
|
+
module Schema
|
9
|
+
module V3
|
10
|
+
class PathItemFileManager < IncludeRefBaseFileManager
|
11
|
+
def initialize(path, path_type = :ref)
|
12
|
+
super
|
13
|
+
@recursive_search_class = ComponentsFileManager
|
14
|
+
end
|
15
|
+
|
16
|
+
def skip_save?
|
17
|
+
save_file_path.in? paths_config.many_paths_file_paths
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/schema/v3/base'
|
4
|
+
|
5
|
+
module R2OAS
|
6
|
+
module Schema
|
7
|
+
module V3
|
8
|
+
class PathnameManager < Base
|
9
|
+
# e.x.) path = "#/components/schemas/Account" (when path_type = :ref)
|
10
|
+
def initialize(path, path_type = :full)
|
11
|
+
super()
|
12
|
+
@ext_name = :yml
|
13
|
+
@path_type = path_type
|
14
|
+
@path = path
|
15
|
+
end
|
16
|
+
|
17
|
+
def object_type
|
18
|
+
case @path
|
19
|
+
when /schemas/
|
20
|
+
'schemas'
|
21
|
+
when /requestBodies/
|
22
|
+
'requestBodies'
|
23
|
+
when /securitySchemes/
|
24
|
+
'securitySchemes'
|
25
|
+
when /parameters/
|
26
|
+
'parameters'
|
27
|
+
when /responses/
|
28
|
+
'responses'
|
29
|
+
when /examples/
|
30
|
+
'examples'
|
31
|
+
when /headers/
|
32
|
+
'headers'
|
33
|
+
when /links/
|
34
|
+
'links'
|
35
|
+
when /callbacks/
|
36
|
+
'callbacks'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def relative_save_file_path
|
41
|
+
result = normalized_about_path_type
|
42
|
+
if (@path_type.in? %i[ref relative]) && support_components_objects.include?(object_type)
|
43
|
+
dirname = File.dirname(result)
|
44
|
+
basename = File.basename(result, '.yml')
|
45
|
+
basename = basename.gsub(ns_div, '/').underscore
|
46
|
+
"#{schema_save_dir_path}/#{dirname}/#{basename}.yml"
|
47
|
+
elsif @path_type.eql?(:relative) && !support_components_objects.include?(object_type)
|
48
|
+
"#{schema_save_dir_path}/#{result.underscore}"
|
49
|
+
elsif @path_type.eql?(:full)
|
50
|
+
result
|
51
|
+
else
|
52
|
+
"#{schema_save_dir_path}/#{result}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def normalized_about_path_type
|
59
|
+
case @path_type
|
60
|
+
when :ref
|
61
|
+
"#{@path.gsub('#/', '')}.#{@ext_name}"
|
62
|
+
when :relative
|
63
|
+
"#{@path}.#{@ext_name}"
|
64
|
+
when :full
|
65
|
+
@path
|
66
|
+
else
|
67
|
+
raise NoSupportError, "Do not support path_type: #{@path_type}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module R2OAS
|
4
|
+
module Schema
|
5
|
+
module V3
|
6
|
+
class BaseObject
|
7
|
+
def initialize(*_args)
|
8
|
+
AppConfiguration::VALID_OPTIONS_KEYS.each do |key|
|
9
|
+
send("#{key}=", app_configuration_options[key])
|
10
|
+
end
|
11
|
+
|
12
|
+
PluggableConfiguration::VALID_OPTIONS_KEYS.each do |key|
|
13
|
+
instance_variable_set(:"@#{key}", pluggable_configuration_options[key])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def info_object_class
|
18
|
+
@use_object_classes[:info_object]
|
19
|
+
end
|
20
|
+
|
21
|
+
def paths_object_class
|
22
|
+
@use_object_classes[:paths_object]
|
23
|
+
end
|
24
|
+
|
25
|
+
def path_item_object_class
|
26
|
+
@use_object_classes[:path_item_object]
|
27
|
+
end
|
28
|
+
|
29
|
+
def external_document_object_class
|
30
|
+
@use_object_classes[:external_document_object]
|
31
|
+
end
|
32
|
+
|
33
|
+
def components_object_class
|
34
|
+
@use_object_classes[:components_object]
|
35
|
+
end
|
36
|
+
|
37
|
+
def components_schema_object_class
|
38
|
+
@use_object_classes[:components_schema_object]
|
39
|
+
end
|
40
|
+
|
41
|
+
def components_request_body_object_class
|
42
|
+
@use_object_classes[:components_request_body_object]
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def app_configuration_options
|
48
|
+
R2OAS.app_configuration_options
|
49
|
+
end
|
50
|
+
|
51
|
+
def pluggable_configuration_options
|
52
|
+
R2OAS.pluggable_configuration_options
|
53
|
+
end
|
54
|
+
|
55
|
+
# Can not define attr_accessor for PluggableConfiguration::VALID_OPTIONS_KEYS.
|
56
|
+
# Because, PuggableConfiguration module is not loaded when this class is loaded.
|
57
|
+
attr_accessor *AppConfiguration::VALID_OPTIONS_KEYS
|
58
|
+
|
59
|
+
def to_doc
|
60
|
+
raise 'Implement Inherit Class'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,92 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/plugins/schema/v3/object/hookable_base_object'
|
4
|
+
require 'r2-oas/schema/v3/manager/file/components_file_manager'
|
5
|
+
|
6
|
+
module R2OAS
|
7
|
+
module Schema
|
8
|
+
module V3
|
9
|
+
module Components
|
10
|
+
class RequestBodyObject < R2OAS::Plugins::Schema::V3::HookableBaseObject
|
11
|
+
def initialize(route_data, path)
|
12
|
+
super()
|
13
|
+
@path_comp = Routing::PathComponent.new(path)
|
14
|
+
@path = @path_comp.symbol_to_brace
|
15
|
+
@route_data = route_data
|
16
|
+
@verb = route_data[:verb]
|
17
|
+
@tag_name = route_data[:tag_name]
|
18
|
+
@schema_name = route_data[:schema_name]
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_doc
|
22
|
+
execute_before_create(@schema_name)
|
23
|
+
create_doc do
|
24
|
+
child_file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
|
25
|
+
schema_object = components_schema_object_class.new(@route_data, @path)
|
26
|
+
|
27
|
+
unless child_file_manager.skip_save?
|
28
|
+
result = {
|
29
|
+
'components' => {
|
30
|
+
'schemas' => {
|
31
|
+
_components_schema_name => schema_object.to_doc
|
32
|
+
}
|
33
|
+
}
|
34
|
+
}
|
35
|
+
doc.deep_merge!(
|
36
|
+
'has_one' => {
|
37
|
+
'type' => 'schema',
|
38
|
+
'original_path' => child_file_manager.original_path,
|
39
|
+
'data' => result
|
40
|
+
}
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
execute_after_create(@schema_name)
|
45
|
+
doc
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_doc
|
49
|
+
file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
|
50
|
+
doc.deep_merge!(
|
51
|
+
'content' => {
|
52
|
+
'application/json' => {
|
53
|
+
'schema' => {
|
54
|
+
'$ref' => file_manager.original_path
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}
|
58
|
+
)
|
59
|
+
yield if block_given?
|
60
|
+
end
|
61
|
+
|
62
|
+
# MEMO:
|
63
|
+
# please override in inherited class.
|
64
|
+
def components_schema_name(_doc, _path_component, _tag_name, _verb, schema_name)
|
65
|
+
schema_name
|
66
|
+
end
|
67
|
+
|
68
|
+
# MEMO:
|
69
|
+
# please override in inherited class.
|
70
|
+
def components_request_body_name(_doc, _path_component, _tag_name, _verb, schema_name)
|
71
|
+
schema_name
|
72
|
+
end
|
73
|
+
|
74
|
+
def generate?
|
75
|
+
file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
|
76
|
+
(@verb.in? http_methods_when_generate_request_body) && !file_manager.skip_save?
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def _components_schema_name
|
82
|
+
components_schema_name(doc, @path_comp, @tag_name, @verb, @schema_name)
|
83
|
+
end
|
84
|
+
|
85
|
+
def _components_request_body_name
|
86
|
+
components_request_body_name(doc, @path_comp, @tag_name, @verb, @schema_name)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/plugins/schema/v3/object/hookable_base_object'
|
4
|
+
|
5
|
+
module R2OAS
|
6
|
+
module Schema
|
7
|
+
module V3
|
8
|
+
module Components
|
9
|
+
class SchemaObject < R2OAS::Plugins::Schema::V3::HookableBaseObject
|
10
|
+
def initialize(route_data, path)
|
11
|
+
super()
|
12
|
+
@path_comp = Routing::PathComponent.new(path)
|
13
|
+
@path = @path_comp.symbol_to_brace
|
14
|
+
@route_data = route_data
|
15
|
+
@verb = route_data[:verb]
|
16
|
+
@tag_name = route_data[:tag_name]
|
17
|
+
@schema_name = route_data[:schema_name]
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_doc
|
21
|
+
execute_before_create(@schema_name)
|
22
|
+
create_doc
|
23
|
+
execute_after_create(@schema_name)
|
24
|
+
doc
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_doc
|
28
|
+
result = {
|
29
|
+
'type' => 'object',
|
30
|
+
'properties' => {
|
31
|
+
'id' => {
|
32
|
+
'type' => 'integer',
|
33
|
+
'format' => 'int64'
|
34
|
+
}
|
35
|
+
}
|
36
|
+
}
|
37
|
+
doc.merge!(result)
|
38
|
+
end
|
39
|
+
|
40
|
+
# MEMO:
|
41
|
+
# please override in inherited class.
|
42
|
+
def components_schema_name(_doc, _path_component, _tag_name, _verb, _http_status, schema_name)
|
43
|
+
schema_name
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def _components_schema_name(http_status)
|
49
|
+
components_schema_name(doc, @path_comp, @tag_name, @verb, http_status, @schema_name)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'r2-oas/plugins/schema/v3/object/hookable_base_object'
|
4
|
+
require_relative 'components/schema_object'
|
5
|
+
require_relative 'components/request_body_object'
|
6
|
+
|
7
|
+
module R2OAS
|
8
|
+
module Schema
|
9
|
+
module V3
|
10
|
+
class ComponentsObject < R2OAS::Plugins::Schema::V3::HookableBaseObject
|
11
|
+
def initialize(routes_data)
|
12
|
+
super()
|
13
|
+
@routes_data = routes_data
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_doc
|
17
|
+
create_doc_for_components_schemas!
|
18
|
+
create_doc_for_components_request_bodies!
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def create_doc_for_components_schemas!
|
24
|
+
result = components_schema_docs.each_with_object({}) do |(schema_name, components_schema_doc), docs|
|
25
|
+
docs[schema_name] = components_schema_doc
|
26
|
+
end
|
27
|
+
doc.merge!('schemas' => result)
|
28
|
+
end
|
29
|
+
|
30
|
+
def create_doc_for_components_request_bodies!
|
31
|
+
result = components_request_body_docs.each_with_object({}) do |(schema_name, components_request_body_doc), docs|
|
32
|
+
docs[schema_name] = components_request_body_doc
|
33
|
+
end
|
34
|
+
doc.merge!('requestBodies' => result)
|
35
|
+
end
|
36
|
+
|
37
|
+
# e.x.)
|
38
|
+
# [
|
39
|
+
# { path: "/tasks", data: {:verb=>"get", :path=>"/tasks", :tag_name=>"task" } },
|
40
|
+
# ]
|
41
|
+
def components_schema_docs
|
42
|
+
@routes_data.each_with_object({}) do |(route_el), data|
|
43
|
+
path = route_el[:path]
|
44
|
+
route_data = route_el[:data]
|
45
|
+
|
46
|
+
path_item_object = path_item_object_class.new(route_data, path)
|
47
|
+
path_item_object.http_statuses.each do |http_status|
|
48
|
+
components_schema_object = components_schema_object_class.new(route_data, path)
|
49
|
+
components_schema_doc = components_schema_object.to_doc
|
50
|
+
schema_name = components_schema_object.send(:_components_schema_name, http_status)
|
51
|
+
|
52
|
+
if data[schema_name].present?
|
53
|
+
data[schema_name].merge!(components_schema_doc)
|
54
|
+
else
|
55
|
+
data[schema_name] = components_schema_doc
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def components_request_body_docs
|
62
|
+
@routes_data.each_with_object({}) do |(route_el), data|
|
63
|
+
path = route_el[:path]
|
64
|
+
route_data = route_el[:data]
|
65
|
+
|
66
|
+
components_request_body_object = components_request_body_object_class.new(route_data, path)
|
67
|
+
next unless components_request_body_object.generate?
|
68
|
+
|
69
|
+
components_request_body_doc = components_request_body_object.to_doc
|
70
|
+
schema_name = components_request_body_object.send(:_components_request_body_name)
|
71
|
+
if data[schema_name].present?
|
72
|
+
data[schema_name].merge!(components_request_body_doc)
|
73
|
+
else
|
74
|
+
data[schema_name] = components_request_body_doc
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|