r2-oas 0.3.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +55 -1
  3. data/GEMSPEC.md +2 -2
  4. data/README.ja.md +73 -43
  5. data/README.md +75 -39
  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 +57 -11
  10. data/lib/r2-oas/configuration/paths_config.rb +6 -3
  11. data/lib/r2-oas/deploy/client.rb +1 -1
  12. data/lib/r2-oas/errors.rb +5 -0
  13. data/lib/r2-oas/helpers/file_helper.rb +68 -0
  14. data/lib/r2-oas/hooks/hook.rb +7 -5
  15. data/lib/r2-oas/lib/core_ext/all.rb +5 -0
  16. data/lib/r2-oas/lib/core_ext/string/filters.rb +29 -0
  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 +47 -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 +3 -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 +9 -2
  28. data/lib/r2-oas/schema/monitor.rb +1 -1
  29. data/lib/r2-oas/schema/ui.rb +1 -1
  30. data/lib/r2-oas/schema/v3/analyzer/path_analyzer.rb +1 -1
  31. data/lib/r2-oas/schema/v3/builder.rb +1 -1
  32. data/lib/r2-oas/schema/v3/builder/base_builder.rb +14 -2
  33. data/lib/r2-oas/schema/v3/builder/doc_builder.rb +10 -2
  34. data/lib/r2-oas/schema/v3/generator/base_generator.rb +7 -2
  35. data/lib/r2-oas/schema/v3/generator/doc_generator.rb +1 -1
  36. data/lib/r2-oas/schema/v3/manager/file/include_ref_base_file_manager.rb +3 -2
  37. data/lib/r2-oas/schema/v3/object/from_files/base_object.rb +62 -0
  38. data/lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb +103 -0
  39. data/lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb +102 -0
  40. data/lib/r2-oas/schema/v3/object/from_files/components_object.rb +46 -0
  41. data/lib/r2-oas/schema/v3/object/from_files/external_document_object.rb +23 -0
  42. data/lib/r2-oas/schema/v3/object/from_files/info_object.rb +23 -0
  43. data/lib/r2-oas/schema/v3/object/from_files/openapi_object.rb +61 -0
  44. data/lib/r2-oas/schema/v3/object/from_files/path_item_object.rb +110 -0
  45. data/lib/r2-oas/schema/v3/object/from_files/paths_object.rb +33 -0
  46. data/lib/r2-oas/schema/v3/object/from_files/utils/all.rb +4 -0
  47. data/lib/r2-oas/schema/v3/object/from_files/utils/deep_methods.rb +27 -0
  48. data/lib/r2-oas/schema/v3/object/from_files/utils/refs.rb +151 -0
  49. data/lib/r2-oas/schema/v3/object/{public.rb → from_routes/all.rb} +0 -0
  50. data/lib/r2-oas/schema/v3/object/from_routes/base_object.rb +41 -0
  51. data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/request_body_object.rb +19 -28
  52. data/lib/r2-oas/schema/v3/object/{components → from_routes/components}/schema_object.rb +12 -16
  53. data/lib/r2-oas/schema/v3/object/{components_object.rb → from_routes/components_object.rb} +19 -13
  54. data/lib/r2-oas/schema/v3/object/{external_document_object.rb → from_routes/external_document_object.rb} +9 -2
  55. data/lib/r2-oas/schema/v3/object/{info_object.rb → from_routes/info_object.rb} +9 -2
  56. data/lib/r2-oas/schema/v3/object/{openapi_object.rb → from_routes/openapi_object.rb} +16 -11
  57. data/lib/r2-oas/schema/v3/object/{path_item_object.rb → from_routes/path_item_object.rb} +8 -8
  58. data/lib/r2-oas/schema/v3/object/{paths_object.rb → from_routes/paths_object.rb} +13 -30
  59. data/lib/r2-oas/schema/v3/object/{server_object.rb → from_routes/server_object.rb} +0 -0
  60. data/lib/r2-oas/schema/v3/object/{tag_object.rb → from_routes/tag_object.rb} +2 -1
  61. data/lib/r2-oas/schema/v3/object/store.rb +54 -0
  62. data/lib/r2-oas/shared/all.rb +1 -0
  63. data/lib/r2-oas/shared/callable.rb +17 -0
  64. data/lib/r2-oas/store.rb +20 -16
  65. data/lib/r2-oas/support/deprecation.rb +26 -0
  66. data/lib/r2-oas/support/deprecation/behavior.rb +21 -0
  67. data/lib/r2-oas/support/deprecation/instance_delegator.rb +42 -0
  68. data/lib/r2-oas/support/deprecation/reporting.rb +91 -0
  69. data/lib/r2-oas/task.rb +1 -2
  70. data/lib/r2-oas/task_logging.rb +3 -7
  71. data/lib/r2-oas/tasks/common.rake +1 -2
  72. data/lib/r2-oas/tasks/main.rake +59 -9
  73. data/lib/r2-oas/version.rb +1 -1
  74. data/r2-oas.gemspec +2 -7
  75. metadata +55 -69
  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/lib/r2-oas/app_configuration/tool.rb +0 -31
  86. data/lib/r2-oas/app_configuration/tool/paths/stats.rb +0 -43
  87. data/lib/r2-oas/pluggable_configuration.rb +0 -33
  88. data/lib/r2-oas/plugins/schema/v3/object/hookable_base_object.rb +0 -100
  89. data/lib/r2-oas/schema/v3/object/base_object.rb +0 -65
  90. data/lib/r2-oas/tasks/tool.rake +0 -83
  91. data/lib/r2-oas/tool/paths/ls.rb +0 -15
  92. data/lib/r2-oas/tool/paths/stats.rb +0 -84
@@ -1,26 +0,0 @@
1
- ---
2
- sudo: false
3
-
4
- language: ruby
5
-
6
- cache: bundler
7
-
8
- rvm:
9
- - 2.3.3
10
- - 2.4.2
11
- - 2.5.7
12
- - 2.6.5
13
- - 2.7.1
14
-
15
- before_install: gem install bundler
16
-
17
- gemfile:
18
- - Gemfile
19
- bundler_args: "--without development --deployment"
20
-
21
- install:
22
- - bundle install
23
-
24
- script:
25
- - ruby -e "if RUBY_VERSION >= '2.7'; system('bundle exec rubocop --fail-level=W'); end"
26
- - bundle exec rspec spec --exclude-pattern "spec/r2-oas/tasks/tool_spec.rb,spec/r2-oas/tool/paths/stats_spec.rb"
data/Appraisals DELETED
@@ -1,13 +0,0 @@
1
- appraise 'ruby-2.3.3' do
2
- end
3
- appraise 'ruby-2.4.2' do
4
- end
5
- # stable
6
- appraise 'ruby-2.5.8' do
7
- end
8
- # stable
9
- appraise 'ruby-2.6.6' do
10
- end
11
- # stable
12
- appraise 'ruby-2.7.1' do
13
- end
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at te108186@gmail.com. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
-
5
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
6
-
7
- # Specify your gem's dependencies in r2-oas.gemspec
8
- gemspec
9
-
10
- group :test do
11
- gem 'sqlite3'
12
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bundler/gem_tasks'
4
- require 'rspec/core/rake_task'
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- task default: :spec
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'tool/paths/stats'
4
-
5
- module R2OAS
6
- module AppConfiguration
7
- class Tool
8
- DEFAULT_PATHS_STATS = PathsStats.new
9
-
10
- VALID_OPTIONS_KEYS = [
11
- :paths_stats
12
- ].freeze
13
-
14
- attr_accessor *VALID_OPTIONS_KEYS
15
-
16
- def initialize
17
- set_default
18
- end
19
-
20
- def configure
21
- yield self
22
- end
23
-
24
- private
25
-
26
- def set_default
27
- self.paths_stats = DEFAULT_PATHS_STATS
28
- end
29
- end
30
- end
31
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module R2OAS
4
- module AppConfiguration
5
- class Tool
6
- class PathsStats
7
- DEFAULT_MONTH_TO_TURN_TO_WARNING_COLOR = 3
8
- DEFAULT_WARNING_COLOR = :red
9
- DEFAULT_TABLE_TITLE_COLOR = :yellow
10
- DEFAULT_HEADING_COLOR = :yellow
11
- DEFAULT_HIGHLIGHT_COLOR = :magenta
12
-
13
- VALID_OPTIONS_KEYS = %i[
14
- month_to_turn_to_warning_color
15
- warning_color
16
- table_title_color
17
- heading_color
18
- highlight_color
19
- ].freeze
20
-
21
- attr_accessor *VALID_OPTIONS_KEYS
22
-
23
- def initialize
24
- set_default
25
- end
26
-
27
- def configure
28
- yield self
29
- end
30
-
31
- private
32
-
33
- def set_default
34
- self.month_to_turn_to_warning_color = DEFAULT_MONTH_TO_TURN_TO_WARNING_COLOR
35
- self.warning_color = DEFAULT_WARNING_COLOR
36
- self.table_title_color = DEFAULT_TABLE_TITLE_COLOR
37
- self.heading_color = DEFAULT_HEADING_COLOR
38
- self.highlight_color = DEFAULT_HIGHLIGHT_COLOR
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,33 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'schema/v3/object/public'
4
-
5
- module R2OAS
6
- module PluggableConfiguration
7
- # rubocop:disable Style/MutableConstant
8
- DEFAULT_USE_OBJECT_CLASSES = {
9
- info_object: R2OAS::Schema::V3::InfoObject,
10
- paths_object: R2OAS::Schema::V3::PathsObject,
11
- path_item_object: R2OAS::Schema::V3::PathItemObject,
12
- external_document_object: R2OAS::Schema::V3::ExternalDocumentObject,
13
- components_object: R2OAS::Schema::V3::ComponentsObject,
14
- components_schema_object: R2OAS::Schema::V3::Components::SchemaObject,
15
- components_request_body_object: R2OAS::Schema::V3::Components::RequestBodyObject
16
- }
17
- # rubocop:enable Style/MutableConstant
18
-
19
- VALID_OPTIONS_KEYS = [
20
- :use_object_classes
21
- ].freeze
22
-
23
- attr_accessor *VALID_OPTIONS_KEYS
24
-
25
- private
26
-
27
- module_function
28
-
29
- def set_default(target)
30
- target.use_object_classes = DEFAULT_USE_OBJECT_CLASSES
31
- end
32
- end
33
- end
@@ -1,100 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'r2-oas/schema/v3/object/base_object'
4
- require 'r2-oas/hooks/hook'
5
-
6
- module R2OAS
7
- module Plugins
8
- module Schema
9
- module V3
10
- class HookableBaseObject < R2OAS::Schema::V3::BaseObject
11
- module ClassMethods
12
- def before_create(&block)
13
- proc = (block_given? ? block : proc {})
14
- on(:before_create, proc)
15
- end
16
-
17
- def after_create(&block)
18
- proc = (block_given? ? block : proc {})
19
- on(:after_create, proc)
20
- end
21
- end
22
-
23
- def self.inherited(base)
24
- base.extend ClassMethods
25
- self.hook = Hooks::Hook.register(base)
26
- end
27
-
28
- def self.hooks
29
- superclass.hook.repository[self].global_hooks_data
30
- end
31
-
32
- def self.hook=(value)
33
- @@hook = value
34
- end
35
-
36
- def self.hook
37
- @@hook
38
- end
39
-
40
- class << self
41
- def on(on, callback, once = false)
42
- hook.on(on, callback, self, once)
43
- end
44
-
45
- # MEMO: Do not Use
46
- def off(on, callback, once = false)
47
- hook.off(on, callback, self, once)
48
- end
49
-
50
- def execute_hook(on, *data)
51
- hook.execute_hook(on, *data, self)
52
- end
53
-
54
- def has_hook?(name)
55
- hook.has_hook?(name, self)
56
- end
57
- end
58
-
59
- attr_accessor :doc
60
-
61
- def initialize
62
- super
63
- self.doc = {}
64
- end
65
-
66
- # MEMO: Please overwrite when passing arguments other than `doc`
67
- def to_doc
68
- execute_before_create
69
- create_doc
70
- execute_after_create
71
- doc
72
- end
73
-
74
- def use_superclass_hook
75
- self.class.hook.repository[self.class] = self.class.hook.repository[self.class.superclass]
76
- end
77
-
78
- private
79
-
80
- def create_doc
81
- raise NoImplementError
82
- end
83
-
84
- def execute_before_create(*data)
85
- execute_hook_method(:before_create, *data)
86
- end
87
-
88
- def execute_after_create(*data)
89
- execute_hook_method(:after_create, *data)
90
- end
91
-
92
- def execute_hook_method(method_name, *data)
93
- args = [doc].push(*data)
94
- self.class.execute_hook(method_name.to_sym, *args) if self.class.has_hook?(method_name.to_sym)
95
- end
96
- end
97
- end
98
- end
99
- end
100
- end
@@ -1,65 +0,0 @@
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
@@ -1,83 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'r2-oas/deploy/client'
4
- require 'r2-oas/tool/paths/ls'
5
- require 'r2-oas/tool/paths/stats'
6
- require 'r2-oas/task_logging'
7
- load File.expand_path('common.rake', __dir__)
8
-
9
- namespace :routes do
10
- namespace :oas do
11
- desc 'Deploy OAS Document'
12
- task deploy: [:common] do
13
- start do
14
- client_options = {}
15
- client = R2OAS::Deploy::Client.new(client_options)
16
-
17
- download_dist_th = Thread.new do
18
- puts 'Download swagger-api/swagger-ui/dist ... (async)'
19
- client.download_swagger_ui_dist
20
- end
21
-
22
- builder_options = { unit_paths_file_path: unit_paths_file_path }
23
- builder = R2OAS::Schema::Builder.new(builder_options)
24
- builder.build_docs
25
-
26
- download_dist_th.join
27
- client.deploy
28
- end
29
- end
30
-
31
- desc 'Display paths list'
32
- task paths_ls: [:common] do
33
- fd = IO.sysopen('/dev/null', 'w+')
34
- $stdout = IO.new(fd)
35
- logger.level = :null
36
-
37
- start do
38
- $stdout = StringIO.new
39
-
40
- paths_ls_options = {}
41
- paths_ls = R2OAS::Tool::Paths::Ls.new(paths_ls_options)
42
- paths_ls.print
43
- end
44
-
45
- result = $stdout.string
46
- $stdout = STDOUT
47
- puts result
48
- end
49
-
50
- desc 'Display paths stats'
51
- task paths_stats: [:common] do
52
- fd = IO.sysopen('/dev/null', 'w+')
53
- $stdout = IO.new(fd)
54
- logger.level = :null
55
-
56
- start do
57
- builder_options = { skip_load_dot_paths: true }
58
- builder = R2OAS::Schema::Builder.new(builder_options)
59
- builder.build_docs
60
-
61
- $stdout = StringIO.new
62
-
63
- paths_log_options = {}
64
- paths_log = R2OAS::Tool::Paths::Stats.new(paths_log_options)
65
- paths_log.print
66
- end
67
-
68
- result = $stdout.string
69
- $stdout = STDOUT
70
- puts result
71
- end
72
-
73
- private
74
-
75
- def unit_paths_file_path
76
- ENV.fetch('PATHS_FILE', '')
77
- end
78
-
79
- def existing_schema_file_path
80
- ENV.fetch('OAS_FILE', '')
81
- end
82
- end
83
- end