diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index aa88d98b..10a3a9c7 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -91,7 +91,6 @@ Lint/AmbiguousOperator:
- "lib/r2-oas/base.rb"
- "lib/r2-oas/routing/parser.rb"
- "lib/r2-oas/app_configuration.rb"
- - "lib/r2-oas/pluggable_configuration.rb"
Metrics/MethodLength:
Exclude:
@@ -161,7 +160,6 @@ Naming/ConstantName:
Naming/PredicateName:
Exclude:
- "lib/r2-oas/hooks/hook.rb"
- - "lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb"
- "lib/r2-oas/plugin/hookable.rb"
Style/DoubleNegation:
@@ -179,7 +177,6 @@ Naming/AccessorMethodName:
Exclude:
- "lib/r2-oas/configuration.rb"
- "lib/r2-oas/app_configuration.rb"
- - "lib/r2-oas/pluggable_configuration.rb"
- "lib/r2-oas/schema/v3/object/from_files/base_object.rb"
- "spec/support/helpers/store_helper.rb"
- "spec/support/helpers/store_helper.rb"
@@ -196,17 +193,12 @@ Lint/UnderscorePrefixedVariableName:
- "lib/r2-oas/schema/v3/object/from_files/components/request_body_object.rb"
- "lib/r2-oas/schema/v3/object/from_files/components/schema_object.rb"
-Lint/UselessAccessModifier:
- Exclude:
- - "lib/r2-oas/pluggable_configuration.rb"
-
Style/IdenticalConditionalBranches:
Exclude:
- "lib/r2-oas/schema/editor.rb"
Style/ClassVars:
Exclude:
- - "lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb"
- "lib/r2-oas/plugin/hookable.rb"
Style/AccessModifierDeclarations:
diff --git a/.travis.yml b/.travis.yml
index dc8bf590..c1421166 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -6,7 +6,6 @@ language: ruby
cache: bundler
rvm:
- - 2.3.3
- 2.4.2
- 2.5.7
- 2.6.5
diff --git a/Appraisals b/Appraisals
index 969f6304..20f94bca 100644
--- a/Appraisals
+++ b/Appraisals
@@ -1,6 +1,4 @@
-appraise 'ruby-2.3.3' do
-end
-appraise 'ruby-2.4.2' do
+appraise 'ruby-2.4.4' do
end
# stable
appraise 'ruby-2.5.8' do
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 60f66b27..3977f9f4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,14 @@
-# Change Log
+# CHANGELOG
+
+## v0.5.0
+
+2020-01-29
+
+- [`Breaking`] Remove `use_object_classes` option ([#171](https://github.com/yukihirop/r2-oas/pull/171))
+- [`Feature`] Upgrade init command ([#176](https://github.com/yukihirop/r2-oas/pull/176))
+- [`EOL`] EOL Ruby `2.3` and Support over Ruby `2.5.0` ([#170](https://github.com/yukihirop/r2-oas/pull/170))
+
+Please see mileston [v0.5.0](https://github.com/yukihirop/r2-oas/milestone/5?closed=1)
## v0.4.1
diff --git a/Gemfile b/Gemfile
index bef486a3..b36d1498 100644
--- a/Gemfile
+++ b/Gemfile
@@ -6,7 +6,3 @@ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
# Specify your gem's dependencies in r2-oas.gemspec
gemspec
-
-group :test do
- gem 'sqlite3'
-end
diff --git a/README.ja.md b/README.ja.md
index eec697f4..9b1b50eb 100644
--- a/README.ja.md
+++ b/README.ja.md
@@ -50,8 +50,17 @@ $ brew cask install chromedriver
gemをrequire後、以下のrakeタスクを実行するだけです。
```bash
-bundle exec routes:oas:docs
-bundle exec routes:oas:editor
+$ bundle exec rake routes:oas:init
+ create oas_docs
+ create oas_docs/.paths
+ create oas_docs/plugins/helpers
+ create oas_docs/tasks/helpers
+ create oas_docs/plugins/.gitkeep
+ create oas_docs/plugins/helpers/.gitkeep
+ create oas_docs/tasks/.gitkeep
+ create oas_docs/tasks/helpers/.gitkeep
+$ bundle exec rake routes:oas:docs
+$ bundle exec rake routes:oas:editor
```
#### Generate docs
@@ -79,6 +88,14 @@ railsプロジェクトのルートディレクトリで以下のコマンドが
```bash
$ bundle exec rake routes:oas:init
+ create oas_docs
+ create oas_docs/.paths
+ create oas_docs/plugins/helpers
+ create oas_docs/tasks/helpers
+ create oas_docs/plugins/.gitkeep
+ create oas_docs/plugins/helpers/.gitkeep
+ create oas_docs/tasks/.gitkeep
+ create oas_docs/tasks/helpers/.gitkeep
```
### Generate
@@ -141,7 +158,7 @@ $ OAS_FILE="~/Desktop/swagger.yml" bundle exec rake routes:oas:analyze
## ❤️ Support Ruby Version
-- Ruby (>= 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin18])
+- Ruby (>= 2.5.0)
## ❤️ Support Rouging
@@ -185,8 +202,6 @@ OpenAPIの3.0.0をサポートしてます。
.
.
===== Bundle install for All Support Ruby Result =====
-ruby-2.3.3: 0
-ruby-2.4.2: 0
ruby-2.5.8: 0
ruby-2.6.6: 0
ruby-2.7.1: 0
@@ -214,8 +229,6 @@ ruby-2.7.1: 0
.
.
===== Rspec for All Support Ruby Result =====
-ruby-2.3.3: 0
-ruby-2.4.2: 0
ruby-2.5.8: 0
ruby-2.6.6: 0
ruby-2.7.1: 0
diff --git a/README.md b/README.md
index 1aee30e2..dc33db1b 100644
--- a/README.md
+++ b/README.md
@@ -64,8 +64,17 @@ R2OAS.load_tasks
```
```bash
-bundle exec routes:oas:docs
-bundle exec routes:oas:editor
+$ bundle exec rake routes:oas:init
+ create oas_docs
+ create oas_docs/.paths
+ create oas_docs/plugins/helpers
+ create oas_docs/tasks/helpers
+ create oas_docs/plugins/.gitkeep
+ create oas_docs/plugins/helpers/.gitkeep
+ create oas_docs/tasks/.gitkeep
+ create oas_docs/tasks/helpers/.gitkeep
+$ bundle exec rake routes:oas:docs
+$ bundle exec rake routes:oas:editor
```
#### Generate docs
@@ -90,6 +99,14 @@ Initialize r2-oas.
```bash
$ bundle exec rake routes:oas:init
+ create oas_docs
+ create oas_docs/.paths
+ create oas_docs/plugins/helpers
+ create oas_docs/tasks/helpers
+ create oas_docs/plugins/.gitkeep
+ create oas_docs/plugins/helpers/.gitkeep
+ create oas_docs/tasks/.gitkeep
+ create oas_docs/tasks/helpers/.gitkeep
```
### Generate
@@ -147,7 +164,7 @@ Full docs are available at https://yukihirop.github.io/r2-oas
## ❤️ Support Ruby Version
-- Ruby (>= 2.3.3p222 (2016-11-21 revision 56859) [x86_64-darwin18])
+- Ruby (>= 2.5.0)
## ❤️ Support Rouging
@@ -189,8 +206,6 @@ Full docs are available at https://yukihirop.github.io/r2-oas/#/setting/configur
.
.
===== Bundle install for All Support Ruby Result =====
-ruby-2.3.3: 0
-ruby-2.4.2: 0
ruby-2.5.8: 0
ruby-2.6.6: 0
ruby-2.7.1: 0
@@ -218,8 +233,6 @@ ruby-2.7.1: 0
.
.
===== Rspec for All Support Ruby Result =====
-ruby-2.3.3: 0
-ruby-2.4.2: 0
ruby-2.5.8: 0
ruby-2.6.6: 0
ruby-2.7.1: 0
diff --git a/devscript/all_support_ruby.sh b/devscript/all_support_ruby.sh
index 0f48b0d4..caa4bce7 100755
--- a/devscript/all_support_ruby.sh
+++ b/devscript/all_support_ruby.sh
@@ -9,8 +9,6 @@ fi
which rbenv > /dev/null 2>&1 && if [ $? -ne 0 ]; then echo -e 'rbenv is need\nPlease install rbenv: https://github.com/rbenv/rbenv'; exit 1; fi
declare -a all_support_ruby=(
- '2.3.3'
- '2.4.2'
'2.5.8'
'2.6.6'
'2.7.1'
diff --git a/devscript/bundle_for_all_support_ruby.sh b/devscript/bundle_for_all_support_ruby.sh
index 55d1e23b..11058632 100755
--- a/devscript/bundle_for_all_support_ruby.sh
+++ b/devscript/bundle_for_all_support_ruby.sh
@@ -13,11 +13,7 @@ for version in $@; do
echo ${version} > ./.ruby-version && rbenv rehash
# Bundle install
- if [[ $version == "2.3.3" ]]; then
- BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle _1.17.3_ install --path vendor/bundle && report+=("ruby-${version}: $?")
- else
- BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle install --path vendor/bundle && report+=("ruby-${version}: $?")
- fi
+ BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle install --path vendor/bundle && report+=("ruby-${version}: $?")
if [ $? -ne 0 ]; then report+=("ruby-${version}: 1 (failed)");fi
echo "== End for Ruby Version: ${version} =="
diff --git a/devscript/rspec_for_all_support_ruby.sh b/devscript/rspec_for_all_support_ruby.sh
index fc2abe72..4609d6ec 100755
--- a/devscript/rspec_for_all_support_ruby.sh
+++ b/devscript/rspec_for_all_support_ruby.sh
@@ -9,11 +9,7 @@ for version in $@; do
echo ${version} > ./.ruby-version && rbenv rehash
# Rspec
- if [[ $version == "2.3.3" ]];then
- BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle _1.17.3_ exec rspec --format progress && report+=("ruby-${version}: $?")
- else
- BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle exec rspec --format progress && report+=("ruby-${version}: $?")
- fi
+ BUNDLE_GEMFILE=./gemfiles/ruby_${version}.gemfile bundle exec rspec --format progress && report+=("ruby-${version}: $?")
if [ $? -ne 0 ]; then report+=("ruby-${version}: 1 (failed)");fi
echo "== End for Ruby Version: ${version} =="
diff --git a/docs/_sidebar.md b/docs/_sidebar.md
index f74398c1..d500900c 100644
--- a/docs/_sidebar.md
+++ b/docs/_sidebar.md
@@ -6,8 +6,8 @@
* **Usage**
* [🆕 __Use plugins__](/usage/use_plugins)
* [🆕 __Define tasks__](/usage/define_tasks)
- * [__[Deprecated] Use hook methods__](/usage/use_hook_methods)
- * [__[Deprecated] Use Hook to Generate Docs__](/usage/use_hook_to_generate_docs)
+ * [__[before v0.4.1] Use hook methods__](/usage/use_hook_methods)
+ * [__[before v0.4.1] Use Hook to Generate Docs__](/usage/use_hook_to_generate_docs)
* [Initialize](/usage/initialize)
* [Silent Log](/usage/silent_log)
* [Generate Docs](/usage/generate_docs)
diff --git a/docs/setting/configure.md b/docs/setting/configure.md
index ed931632..96285a6e 100644
--- a/docs/setting/configure.md
+++ b/docs/setting/configure.md
@@ -36,16 +36,6 @@ R2OAS.configure do |config|
swagger.editor.exposed_port = "8080/tcp"
end
- config.use_object_classes = {
- info_object: R2OAS::Schema::V3::InfoObject,
- paths_object: R2OAS::Schema::V3::PathsObject,
- path_item_object: R2OAS::Schema::V3::PathItemObject,
- external_document_object: R2OAS::Schema::V3::ExternalDocumentObject,
- components_object: R2OAS::Schema::V3::ComponentsObject,
- components_schema_object: R2OAS::Schema::V3::Components::SchemaObject,
- components_request_body_object: R2OAS::Schema::V3::Components::RequestBodyObject
- }
-
config.http_statuses_when_http_method = {
get: {
default: %w(200 422),
@@ -125,12 +115,6 @@ we explain the options that can be set.
|swagger|editor|port|Swagger Editor Port|`"8080"`|
|swagger|editor|exposed_port|Swagger Editor Exposed Port|`"8080/tcp"`|
-#### hook
-
-|option|description|default|
-|------|-----------|-------|
-|use_object_classes|Object class(hook class) to generate Openapi document|{ info_object: `R2OAS::Schema::V3::InfoObject`,
paths_object: `R2OAS::Schema::V3::PathsObject`,
path_item_object: `R2OAS::Schema::V3::PathItemObject`, external_document_object: `R2OAS::Schema::V3::ExternalDocumentObject`,
components_object: `R2OAS::Schema::V3::ComponentsObject`,
components_schema_object: `R2OAS::Schema::V3::Components::SchemaObject`,
components_request_body_object:`R2OAS::Schema::V3::Components::RequestBodyObject` }|
-
#### deprecation
|option|children option|description|default|
diff --git a/docs/usage/initialize.md b/docs/usage/initialize.md
index 56282610..8348a79d 100644
--- a/docs/usage/initialize.md
+++ b/docs/usage/initialize.md
@@ -12,6 +12,14 @@ R2OAS.load_tasks
```bash
$ bundle exec rake routes:oas:init
+ create oas_docs
+ create oas_docs/.paths
+ create oas_docs/plugins/helpers
+ create oas_docs/tasks/helpers
+ create oas_docs/plugins/.gitkeep
+ create oas_docs/plugins/helpers/.gitkeep
+ create oas_docs/tasks/.gitkeep
+ create oas_docs/tasks/helpers/.gitkeep
```
By default, the directory is created as follows.
diff --git a/docs/usage/use_hook_methods.md b/docs/usage/use_hook_methods.md
index 90e4e250..eefb410a 100644
--- a/docs/usage/use_hook_methods.md
+++ b/docs/usage/use_hook_methods.md
@@ -1,7 +1,6 @@
-# [Deprecated] Use hook methods
+# [before v0.4.1] Use hook methods
-!> ・will be removed in `v0.4.2`
- ・Please use the `plugin` instead
+!> This option is valid until `v0.4.1`. Please use `plugin` instead for `v0.5.0` and above
Supported hook(life cycle methods) is like this:
diff --git a/docs/usage/use_hook_to_generate_docs.md b/docs/usage/use_hook_to_generate_docs.md
index f8cc5cc0..afd5a756 100644
--- a/docs/usage/use_hook_to_generate_docs.md
+++ b/docs/usage/use_hook_to_generate_docs.md
@@ -1,7 +1,6 @@
-## [Deprecated] Use hook to generate docs
+# [before v0.4.1] Use hook to generate docs
-!> ・will be removed in `v0.4.2`
- ・Please use the `plugin` instead
+!> This option is valid until `v0.4.1`. Please use `plugin` instead for `v0.5.0` and above
## Prepare
diff --git a/gemfiles/ruby_2.3.3.gemfile b/gemfiles/ruby_2.3.3.gemfile
deleted file mode 100644
index eec6090a..00000000
--- a/gemfiles/ruby_2.3.3.gemfile
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file was generated by Appraisal
-
-source "https://rubygems.org"
-
-ruby '2.3.3'
-
-group :test do
- gem "sqlite3"
-end
-
-gemspec path: "../"
diff --git a/gemfiles/ruby_2.4.2.gemfile b/gemfiles/ruby_2.4.2.gemfile
deleted file mode 100644
index 751f9321..00000000
--- a/gemfiles/ruby_2.4.2.gemfile
+++ /dev/null
@@ -1,11 +0,0 @@
-# This file was generated by Appraisal
-
-source "https://rubygems.org"
-
-ruby '2.4.2'
-
-group :test do
- gem "sqlite3"
-end
-
-gemspec path: "../"
diff --git a/lib/r2-oas/configuration.rb b/lib/r2-oas/configuration.rb
index 94943a9f..bc2855cc 100644
--- a/lib/r2-oas/configuration.rb
+++ b/lib/r2-oas/configuration.rb
@@ -3,17 +3,17 @@
require 'fileutils'
require_relative 'app_configuration'
-require_relative 'pluggable_configuration'
require_relative 'configuration/paths_config'
require_relative 'logger/stdout_logger'
require_relative 'support/deprecation'
+require_relative 'helpers/file_helper'
module R2OAS
module Configuration
extend AppConfiguration
- extend PluggableConfiguration
+ include Helpers::FileHelper
- PUBLIC_VALID_OPTIONS_KEYS = AppConfiguration::VALID_OPTIONS_KEYS + PluggableConfiguration::VALID_OPTIONS_KEYS
+ PUBLIC_VALID_OPTIONS_KEYS = AppConfiguration::VALID_OPTIONS_KEYS
UNPUBLIC_VALID_OPTIONS_KEYS = %i[
paths_config
@@ -24,18 +24,8 @@ module Configuration
attr_accessor *PUBLIC_VALID_OPTIONS_KEYS
- # MEMO: override because deprecated
- def use_object_classes=(data)
- ::R2OAS::Deprecation.will_remove(<<-MSG.squish)
- Using a R2OAS.use_object_classes= in configuration is deprecated and
- will be removed in r2-oas (v0.4.2).
- MSG
- @use_object_classes = data
- end
-
def self.extended(base)
base.send :set_default_for_configuration, base
- base.send :set_default_for_pluggable, base
end
def configure
@@ -63,17 +53,14 @@ def app_configuration_options
end
end
- def pluggable_configuration_options
- PluggableConfiguration::VALID_OPTIONS_KEYS.inject({}) do |option, key|
- option.merge!(key => send(key))
- end
- end
-
def load_tasks
load_local_tasks
end
def init
+ old_stdout = $stdout
+ $stdout = StringIO.new
+
plugins_path = File.expand_path("#{root_dir_path}/#{local_plugins_dir_name}")
plugins_helpers_path = "#{plugins_path}/helpers"
tasks_path = File.expand_path("#{root_dir_path}/#{local_tasks_dir_name}")
@@ -84,14 +71,21 @@ def init
gitkeep_tasks_path = "#{tasks_path}/.gitkeep"
gitkeep_tasks_helpers_path = "#{tasks_helpers_path}/.gitkeep"
- FileUtils.mkdir_p(plugins_helpers_path) unless FileTest.exists?(plugins_helpers_path)
- FileUtils.mkdir_p(tasks_helpers_path) unless FileTest.exists?(tasks_helpers_path)
+ paths_config.create_dot_paths(false)
+ mkdir_p_dir_or_skip(plugins_helpers_path)
+ mkdir_p_dir_or_skip(tasks_helpers_path)
+ write_file_or_skip(gitkeep_plugins_path, '')
+ write_file_or_skip(gitkeep_plugins_helpers_path, '')
+ write_file_or_skip(gitkeep_tasks_path, '')
+ write_file_or_skip(gitkeep_tasks_helpers_path, '')
+
+ if $stdout.string.present?
+ STDOUT.puts $stdout.string
+ else
+ STDOUT.puts "Already Initialized existing oas_docs in #{root_dir_path}"
+ end
- File.write(gitkeep_plugins_path, '') unless FileTest.exists?(gitkeep_plugins_path)
- File.write(gitkeep_plugins_helpers_path, '') unless FileTest.exists?(gitkeep_plugins_helpers_path)
- File.write(gitkeep_tasks_path, '') unless FileTest.exists?(gitkeep_tasks_path)
- File.write(gitkeep_tasks_helpers_path, '') unless FileTest.exists?(gitkeep_tasks_helpers_path)
- paths_config.create_dot_paths
+ $stdout = old_stdout
end
def output_dir_path
@@ -117,9 +111,5 @@ def load_local_plugins
def set_default_for_configuration(target)
AppConfiguration.set_default(target)
end
-
- def set_default_for_pluggable(target)
- PluggableConfiguration.set_default(target)
- end
end
end
diff --git a/lib/r2-oas/configuration/paths_config.rb b/lib/r2-oas/configuration/paths_config.rb
index c53e74d8..c4b78a42 100644
--- a/lib/r2-oas/configuration/paths_config.rb
+++ b/lib/r2-oas/configuration/paths_config.rb
@@ -1,10 +1,13 @@
# frozen_string_literal: true
require 'r2-oas/schema/manager/file/path_item_file_manager'
+require 'r2-oas/helpers/file_helper'
module R2OAS
module Configuration
class PathsConfig
+ include Helpers::FileHelper
+
def initialize(root_dir_path, schema_save_dir_name)
@root_dir_path = root_dir_path
@schema_save_dir_path = "#{root_dir_path}/#{schema_save_dir_name}"
@@ -25,11 +28,11 @@ def many_paths_file_paths
end.uniq.compact.reject(&:empty?)
end
- def create_dot_paths
+ def create_dot_paths(silent = true)
abs_root_path = File.expand_path(@root_dir_path)
- FileUtils.mkdir_p(abs_root_path) unless FileTest.exists?(abs_root_path)
- File.write(abs_paths_path, '') unless FileTest.exists?(abs_paths_path)
+ mkdir_p_dir_or_skip(abs_root_path, silent)
+ write_file_or_skip(abs_paths_path, '', silent)
end
def many_components_file_paths
diff --git a/lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb b/lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb
deleted file mode 100644
index bda482cc..00000000
--- a/lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb
+++ /dev/null
@@ -1,100 +0,0 @@
-# frozen_string_literal: true
-
-require 'r2-oas/schema/v3/object/from_routes/base_object'
-require 'r2-oas/hooks/hook'
-
-module R2OAS
- module Dynamic
- module Schema
- module V3
- class HookableBaseObject < R2OAS::Schema::V3::BaseObject
- module ClassMethods
- def before_create(&block)
- proc = (block_given? ? block : proc {})
- on(:before_create, proc)
- end
-
- def after_create(&block)
- proc = (block_given? ? block : proc {})
- on(:after_create, proc)
- end
- end
-
- def self.inherited(base)
- base.extend ClassMethods
- self.hook = Hooks::Hook.register(:dynamic, base)
- end
-
- def self.hooks
- superclass.hook.repository[:dynamic][self].global_hooks_data
- end
-
- def self.hook=(value)
- @@hook = value
- end
-
- def self.hook
- @@hook
- end
-
- class << self
- def on(on, callback, once = false)
- hook.on(on, callback, self, once)
- end
-
- # MEMO: Do not Use
- def off(on, callback, once = false)
- hook.off(on, callback, self, once)
- end
-
- def execute_hook(on, *data)
- hook.execute_hook(on, *data, self)
- end
-
- def has_hook?(name)
- hook.has_hook?(name, self)
- end
- end
-
- attr_accessor :doc
-
- def initialize(opts = {})
- super(opts)
- self.doc = {}
- end
-
- # MEMO: Please overwrite when passing arguments other than `doc`
- def to_doc
- execute_before_create
- create_doc
- execute_after_create
- doc
- end
-
- def use_superclass_hook
- self.class.hook.repository[:dynamic][self.class] = self.class.hook.repository[:dynamic][self.class.superclass]
- end
-
- private
-
- def create_doc
- raise NoImplementError
- end
-
- def execute_before_create(*data)
- execute_hook_method(:before_create, *data)
- end
-
- def execute_after_create(*data)
- execute_hook_method(:after_create, *data)
- end
-
- def execute_hook_method(method_name, *data)
- args = [doc].push(*data)
- self.class.execute_hook(method_name.to_sym, *args) if self.class.has_hook?(method_name.to_sym)
- end
- end
- end
- end
- end
-end
diff --git a/lib/r2-oas/helpers/file_helper.rb b/lib/r2-oas/helpers/file_helper.rb
new file mode 100644
index 00000000..e89792ce
--- /dev/null
+++ b/lib/r2-oas/helpers/file_helper.rb
@@ -0,0 +1,68 @@
+# frozen_string_literal: true
+
+require 'fileutils'
+
+# https :/ / keyesberry.hatenadiary.org / entry / 20101107 / p1
+#
+# Text attributes
+# 0 All attributes off
+# 1 Bold on
+# 4 Underscore (on monochrome display adapter only)
+# 5 Blink on
+# 7 Reverse video on
+# 8 Concealed on
+
+# Foreground colors
+# 30 Black
+# 31 Red
+# 32 Green
+# 33 Yellow
+# 34 Blue
+# 35 Magenta
+# 36 Cyan
+# 37 White
+
+# Background colors
+# 40 Black
+# 41 Red
+# 42 Green
+# 43 Yellow
+# 44 Blue
+# 45 Magenta
+# 46 Cyan
+# 47 White
+module R2OAS
+ module Helpers
+ module FileHelper
+ def write_file_or_skip(file_path, data, silent = false)
+ unless FileTest.exists?(file_path)
+ File.write(file_path, data)
+ puts "#{space}#{bold('create')}\t#{relative(file_path)}" unless silent
+ end
+ end
+
+ def mkdir_p_dir_or_skip(dir_path, silent = false)
+ unless FileTest.exists?(dir_path)
+ FileUtils.mkdir_p(dir_path)
+ puts "#{space}#{bold('create')}\t#{relative(dir_path)}" unless silent
+ end
+ end
+
+ private
+
+ def relative(path)
+ current_dir_pathname = Pathname.new(Dir.pwd)
+ target_path = Pathname.new(path)
+ target_path.relative_path_from(current_dir_pathname)
+ end
+
+ def bold(str)
+ "\e[1m#{str}\e[0m"
+ end
+
+ def space
+ ' '
+ end
+ end
+ end
+end
diff --git a/lib/r2-oas/pluggable_configuration.rb b/lib/r2-oas/pluggable_configuration.rb
deleted file mode 100644
index e4aa1f89..00000000
--- a/lib/r2-oas/pluggable_configuration.rb
+++ /dev/null
@@ -1,36 +0,0 @@
-# frozen_string_literal: true
-
-require 'r2-oas/schema/v3/object/from_routes/public'
-require_relative 'support/deprecation'
-
-module R2OAS
- module PluggableConfiguration
- # rubocop:disable Style/MutableConstant
- DEFAULT_USE_OBJECT_CLASSES = {
- info_object: R2OAS::Schema::V3::InfoObject,
- paths_object: R2OAS::Schema::V3::PathsObject,
- path_item_object: R2OAS::Schema::V3::PathItemObject,
- external_document_object: R2OAS::Schema::V3::ExternalDocumentObject,
- components_object: R2OAS::Schema::V3::ComponentsObject,
- components_schema_object: R2OAS::Schema::V3::Components::SchemaObject,
- components_request_body_object: R2OAS::Schema::V3::Components::RequestBodyObject
- }
- # rubocop:enable Style/MutableConstant
-
- VALID_OPTIONS_KEYS = %i[
- use_object_classes
- ].freeze
-
- attr_reader *VALID_OPTIONS_KEYS
-
- private
-
- module_function
-
- def set_default(target)
- Deprecation.silence do
- target.use_object_classes = DEFAULT_USE_OBJECT_CLASSES
- end
- end
- end
-end
diff --git a/lib/r2-oas/plugin/hookable.rb b/lib/r2-oas/plugin/hookable.rb
index 03fed2ff..3594464e 100644
--- a/lib/r2-oas/plugin/hookable.rb
+++ b/lib/r2-oas/plugin/hookable.rb
@@ -5,6 +5,11 @@
module R2OAS
module Plugin
module Hookable
+ def self.extended(base)
+ super
+ base.class_variable_set(:@@hook_klass, ::R2OAS::Hooks::Hook.register(:plugin, base))
+ end
+
def hooks_map
hook_klass.repository[:plugin]
end
@@ -14,11 +19,11 @@ def hooks
end
def hook_klass=(klass)
- @@hook_klass = klass
+ class_variable_set(:@@hook_klass, klass)
end
def hook_klass
- @@hook_klass
+ class_variable_get(:@@hook_klass)
end
def on(on, callback, once = false)
diff --git a/lib/r2-oas/public.rb b/lib/r2-oas/public.rb
index cef7cde2..16ecf3ef 100644
--- a/lib/r2-oas/public.rb
+++ b/lib/r2-oas/public.rb
@@ -1,5 +1,3 @@
# frozen_string_literal: true
require 'r2-oas/configuration'
-require 'r2-oas/errors'
-require 'r2-oas/schema/v3/object/from_routes/public'
diff --git a/lib/r2-oas/schema/editor.rb b/lib/r2-oas/schema/editor.rb
index 71961d13..266aa000 100644
--- a/lib/r2-oas/schema/editor.rb
+++ b/lib/r2-oas/schema/editor.rb
@@ -1,7 +1,7 @@
# frozen_string_literal:true
require 'docker'
-require 'eventmachine'
+require 'em/pure_ruby'
require 'watir'
require 'tempfile'
require 'fileutils'
diff --git a/lib/r2-oas/schema/monitor.rb b/lib/r2-oas/schema/monitor.rb
index 508122f1..a3b4f341 100644
--- a/lib/r2-oas/schema/monitor.rb
+++ b/lib/r2-oas/schema/monitor.rb
@@ -1,6 +1,6 @@
# frozen_string_literal:true
-require 'eventmachine'
+require 'em/pure_ruby'
# Scope Rails
module R2OAS
diff --git a/lib/r2-oas/schema/ui.rb b/lib/r2-oas/schema/ui.rb
index c2d1ec39..dd08f241 100644
--- a/lib/r2-oas/schema/ui.rb
+++ b/lib/r2-oas/schema/ui.rb
@@ -1,7 +1,7 @@
# frozen_string_literal:true
require 'docker'
-require 'eventmachine'
+require 'em/pure_ruby'
require 'watir'
require 'forwardable'
diff --git a/lib/r2-oas/schema/v3/object/from_routes/public.rb b/lib/r2-oas/schema/v3/object/from_routes/all.rb
similarity index 100%
rename from lib/r2-oas/schema/v3/object/from_routes/public.rb
rename to lib/r2-oas/schema/v3/object/from_routes/all.rb
diff --git a/lib/r2-oas/schema/v3/object/from_routes/base_object.rb b/lib/r2-oas/schema/v3/object/from_routes/base_object.rb
index 392fbb68..067cef46 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/base_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/base_object.rb
@@ -16,40 +16,16 @@ def initialize(opts = {})
send("#{key}=", app_configuration_options[key])
end
- PluggableConfiguration::VALID_OPTIONS_KEYS.each do |key|
- instance_variable_set(:"@#{key}", pluggable_configuration_options[key])
- end
-
@opts = opts
@plugin_executor = ::R2OAS::Plugin::Executor.new(@plugins, opts)
end
- def info_object_class
- @use_object_classes[:info_object]
- end
-
- def paths_object_class
- @use_object_classes[:paths_object]
- end
-
- def path_item_object_class
- @use_object_classes[:path_item_object]
- end
-
- def external_document_object_class
- @use_object_classes[:external_document_object]
- end
-
- def components_object_class
- @use_object_classes[:components_object]
+ def doc
+ @doc ||= {}
end
- def components_schema_object_class
- @use_object_classes[:components_schema_object]
- end
-
- def components_request_body_object_class
- @use_object_classes[:components_request_body_object]
+ def to_doc
+ raise 'Implement Inherit Class'
end
private
@@ -58,17 +34,7 @@ def app_configuration_options
R2OAS.app_configuration_options
end
- def pluggable_configuration_options
- R2OAS.pluggable_configuration_options
- end
-
- # Can not define attr_accessor for PluggableConfiguration::VALID_OPTIONS_KEYS.
- # Because, PuggableConfiguration module is not loaded when this class is loaded.
attr_accessor *AppConfiguration::VALID_OPTIONS_KEYS
-
- def to_doc
- raise 'Implement Inherit Class'
- end
end
end
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb b/lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb
index 648863cf..82d846c6 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/components/request_body_object.rb
@@ -1,13 +1,14 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
+require 'r2-oas/schema/v3/object/from_routes/base_object'
require 'r2-oas/schema/v3/manager/file/components_file_manager'
+require_relative 'schema_object'
module R2OAS
module Schema
module V3
module Components
- class RequestBodyObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class RequestBodyObject < R2OAS::Schema::V3::BaseObject
def initialize(route_data, path, opts = {})
super(opts)
@path_comp = Routing::PathComponent.new(path)
@@ -23,10 +24,9 @@ def initialize(route_data, path, opts = {})
end
def to_doc
- execute_before_create(@schema_name)
create_doc do
child_file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
- schema_object = components_schema_object_class.new(@route_data, @path, @opts)
+ schema_object = Components::SchemaObject.new(@route_data, @path, @opts)
unless child_file_manager.skip_save?
result = {
@@ -45,22 +45,9 @@ def to_doc
)
end
end
- execute_after_create(@schema_name)
doc
end
- # MEMO:
- # please override in inherited class.
- def components_schema_name(_doc, _path_component, _tag_name, _verb, schema_name)
- schema_name
- end
-
- # MEMO:
- # please override in inherited class.
- def components_request_body_name(_doc, _path_component, _tag_name, _verb, schema_name)
- schema_name
- end
-
def generate?
file_manager = ComponentsFileManager.new("#/components/schemas/#{_components_schema_name}", :ref)
(@verb.in? http_methods_when_generate_request_body) && !file_manager.skip_save?
@@ -83,11 +70,11 @@ def create_doc
end
def _components_schema_name
- components_schema_name(doc, @path_comp, @tag_name, @verb, @schema_name)
+ @schema_name
end
def _components_request_body_name
- components_request_body_name(doc, @path_comp, @tag_name, @verb, @schema_name)
+ @schema_name
end
end
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/components/schema_object.rb b/lib/r2-oas/schema/v3/object/from_routes/components/schema_object.rb
index 40630a85..7a121913 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/components/schema_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/components/schema_object.rb
@@ -1,12 +1,12 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
+require 'r2-oas/schema/v3/object/from_routes/base_object'
module R2OAS
module Schema
module V3
module Components
- class SchemaObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class SchemaObject < R2OAS::Schema::V3::BaseObject
def initialize(route_data, path, opts = {})
super(opts)
@path_comp = Routing::PathComponent.new(path)
@@ -22,18 +22,10 @@ def initialize(route_data, path, opts = {})
end
def to_doc
- execute_before_create(@schema_name)
create_doc
- execute_after_create(@schema_name)
doc
end
- # MEMO:
- # please override in inherited class.
- def components_schema_name(_doc, _path_component, _tag_name, _verb, _http_status, schema_name)
- schema_name
- end
-
private
def create_doc
@@ -49,8 +41,8 @@ def create_doc
doc.merge!(result)
end
- def _components_schema_name(http_status)
- components_schema_name(doc, @path_comp, @tag_name, @verb, http_status, @schema_name)
+ def _components_schema_name(_http_status)
+ @schema_name
end
end
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/components_object.rb b/lib/r2-oas/schema/v3/object/from_routes/components_object.rb
index 40282158..ef05fcba 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/components_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/components_object.rb
@@ -1,18 +1,24 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
+require_relative 'base_object'
require_relative 'components/schema_object'
require_relative 'components/request_body_object'
+require_relative 'path_item_object'
module R2OAS
module Schema
module V3
- class ComponentsObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class ComponentsObject < BaseObject
def initialize(routes_data, opts = {})
super(opts)
@routes_data = routes_data
end
+ def to_doc
+ create_doc
+ doc
+ end
+
def create_doc
create_doc_for_components_schemas!
create_doc_for_components_request_bodies!
@@ -24,14 +30,14 @@ def create_doc_for_components_schemas!
result = components_schema_docs.each_with_object({}) do |(schema_name, components_schema_doc), docs|
docs[schema_name] = components_schema_doc
end
- doc.merge!('schemas' => result)
+ doc.merge!({ 'schemas' => result })
end
def create_doc_for_components_request_bodies!
result = components_request_body_docs.each_with_object({}) do |(schema_name, components_request_body_doc), docs|
docs[schema_name] = components_request_body_doc
end
- doc.merge!('requestBodies' => result)
+ doc.merge!({ 'requestBodies' => result })
end
# e.x.)
@@ -43,9 +49,9 @@ def components_schema_docs
path = route_el[:path]
route_data = route_el[:data]
- path_item_object = path_item_object_class.new(route_data, path, @opts)
+ path_item_object = PathItemObject.new(route_data, path, @opts)
path_item_object.http_statuses.each do |http_status|
- components_schema_object = components_schema_object_class.new(route_data, path, @opts)
+ components_schema_object = Components::SchemaObject.new(route_data, path, @opts)
components_schema_doc = components_schema_object.to_doc
schema_name = components_schema_object.send(:_components_schema_name, http_status)
@@ -63,7 +69,7 @@ def components_request_body_docs
path = route_el[:path]
route_data = route_el[:data]
- components_request_body_object = components_request_body_object_class.new(route_data, path, @opts)
+ components_request_body_object = Components::RequestBodyObject.new(route_data, path, @opts)
next unless components_request_body_object.generate?
components_request_body_doc = components_request_body_object.to_doc
diff --git a/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb b/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb
index 8e86ce89..db3752dc 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/external_document_object.rb
@@ -1,15 +1,13 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
+require_relative 'base_object'
module R2OAS
module Schema
module V3
- class ExternalDocumentObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class ExternalDocumentObject < BaseObject
def to_doc
- execute_before_create
create_doc
- execute_after_create
doc
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/info_object.rb b/lib/r2-oas/schema/v3/object/from_routes/info_object.rb
index 298c3035..d1a49c59 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/info_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/info_object.rb
@@ -1,15 +1,13 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
+require_relative 'base_object'
module R2OAS
module Schema
module V3
- class InfoObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class InfoObject < BaseObject
def to_doc
- execute_before_create
create_doc
- execute_after_create
doc
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb b/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb
index 16506024..32e0723b 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb
@@ -3,6 +3,10 @@
require_relative 'base_object'
require_relative 'tag_object'
require_relative 'server_object'
+require_relative 'info_object'
+require_relative 'external_document_object'
+require_relative 'components_object'
+require_relative 'paths_object'
module R2OAS
module Schema
@@ -25,13 +29,13 @@ def to_doc
'servers' => servers_doc,
'components' => components_doc
}
- result
+ doc.merge!(result)
end
private
def info_doc
- info_object_class.new(@opts).to_doc
+ InfoObject.new(@opts).to_doc
end
def tags_doc
@@ -39,11 +43,11 @@ def tags_doc
end
def paths_doc
- paths_object_class.new(@routes_data, @opts).to_doc
+ PathsObject.new(@routes_data, @opts).to_doc
end
def external_docs_doc
- external_document_object_class.new(@opts).to_doc
+ ExternalDocumentObject.new(@opts).to_doc
end
def servers_doc
@@ -51,7 +55,7 @@ def servers_doc
end
def components_doc
- components_object_class.new(@routes_data, @opts).to_doc
+ ComponentsObject.new(@routes_data, @opts).to_doc
end
end
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb b/lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb
index 714f6783..a8b0904c 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/path_item_object.rb
@@ -1,13 +1,15 @@
# frozen_string_literal: true
require 'forwardable'
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
require 'r2-oas/routing/components/path_component'
+require_relative 'base_object'
+require_relative 'components/schema_object'
+require_relative 'components/request_body_object'
module R2OAS
module Schema
module V3
- class PathItemObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class PathItemObject < BaseObject
extend Forwardable
# reference
# https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#path-item-object
@@ -27,15 +29,13 @@ def initialize(route_data, path, opts = {})
@required_parameters = route_data[:required_parameters]
@format_name = create_format_name
@http_status_manager = HttpStatusManager.new(@path, @verb, http_statuses_when_http_method)
- @components_schema_object = components_schema_object_class.new(route_data, path, opts)
- @components_request_body_object = components_request_body_object_class.new(route_data, path, opts)
+ @components_schema_object = Components::SchemaObject.new(route_data, path, opts)
+ @components_request_body_object = Components::RequestBodyObject.new(route_data, path, opts)
support_field_name? if route_data.key?(:verb)
end
def to_doc
- execute_before_create(@path)
create_doc
- execute_after_create(@path)
doc
end
diff --git a/lib/r2-oas/schema/v3/object/from_routes/paths_object.rb b/lib/r2-oas/schema/v3/object/from_routes/paths_object.rb
index 0915773e..55ffbb5f 100644
--- a/lib/r2-oas/schema/v3/object/from_routes/paths_object.rb
+++ b/lib/r2-oas/schema/v3/object/from_routes/paths_object.rb
@@ -1,23 +1,28 @@
# frozen_string_literal: true
-require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object'
require 'r2-oas/routing/components/path_component'
+require_relative 'base_object'
+require_relative 'path_item_object'
module R2OAS
module Schema
module V3
- class PathsObject < R2OAS::Dynamic::Schema::V3::HookableBaseObject
+ class PathsObject < BaseObject
def initialize(routes_data, opts = {})
super(opts)
@routes_data = routes_data
- define_hookable_tmp_object_class
+ end
+
+ def to_doc
+ create_doc
+ doc
end
def create_doc
if unit_paths_file_path.present?
unit_paths_data = YAML.load_file(unit_paths_file_path)['paths']
result = unit_paths_data.each_with_object({}) do |(path, path_item_doc), docs|
- docs[path] = HookableTmpObjectClass.new(path_item_doc, path, @opts).to_doc
+ docs[path] = PathItemObject.new(path_item_doc, path, @opts).to_doc
end
else
result = path_item_docs.each_with_object({}) do |(path, path_item_doc), docs|
@@ -29,31 +34,6 @@ def create_doc
private
- def define_hookable_tmp_object_class
- klass = Class.new(path_item_object_class) do |_c|
- def initialize(data, path, opts = {})
- super(opts)
- @data = data
- @path = path
- @path_comp = Routing::PathComponent.new(path)
- use_superclass_hook
- end
-
- def create_doc
- doc.merge!(@data)
- end
-
- def to_doc
- execute_before_create(@path)
- create_doc
- execute_after_create(@path)
- execute_transform_plugins(:path_item, doc, @path_comp)
- doc
- end
- end
- Object.const_set(:HookableTmpObjectClass, klass) unless defined?(HookableTmpObjectClass)
- end
-
def path_item_docs
# e.x.)
# [
@@ -63,7 +43,7 @@ def path_item_docs
path = route_el[:path]
route_data = route_el[:data]
- path_item_doc = path_item_object_class.new(route_data, path, @opts).to_doc
+ path_item_doc = PathItemObject.new(route_data, path, @opts).to_doc
if data[path].present?
data[path].merge!(path_item_doc)
else
diff --git a/lib/r2-oas/tasks/main.rake b/lib/r2-oas/tasks/main.rake
index 2d0b24c6..3460638d 100644
--- a/lib/r2-oas/tasks/main.rake
+++ b/lib/r2-oas/tasks/main.rake
@@ -10,9 +10,8 @@ load File.expand_path('common.rake', __dir__)
namespace :routes do
namespace :oas do
desc '[R2-OAS] Initialize'
- task init: [:common] do
+ task :init do
R2OAS.init
- puts '[R2-OAS] Initialized!'
end
desc '[R2-OAS] Generate OAS documentation files'
diff --git a/lib/r2-oas/version.rb b/lib/r2-oas/version.rb
index 7b32085e..10b6dfdc 100644
--- a/lib/r2-oas/version.rb
+++ b/lib/r2-oas/version.rb
@@ -1,5 +1,5 @@
# frozen_string_literal: true
module R2OAS
- VERSION = '0.4.1'
+ VERSION = '0.5.0'
end
diff --git a/r2-oas.gemspec b/r2-oas.gemspec
index 5779a4d9..fe2d1394 100644
--- a/r2-oas.gemspec
+++ b/r2-oas.gemspec
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
- spec.required_ruby_version = Gem::Requirement.new('>= 2.3.3p222')
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
spec.add_runtime_dependency 'docker-api', '>= 1.34.2'
spec.add_runtime_dependency 'easy_diff', '>= 1.0.0'
diff --git a/spec/r2-oas/configuration_spec.rb b/spec/r2-oas/configuration_spec.rb
index 92a82673..22c1d151 100644
--- a/spec/r2-oas/configuration_spec.rb
+++ b/spec/r2-oas/configuration_spec.rb
@@ -4,18 +4,6 @@
RSpec.describe R2OAS::Configuration do
describe 'configure' do
- before(:all) do
- class RtsdInfoObject < R2OAS::Schema::V3::InfoObject; end
- class RtsdPathsObject < R2OAS::Schema::V3::PathsObject; end
- class RtsdPathItemObject < R2OAS::Schema::V3::PathItemObject; end
- class RtsdExternalDocumentObject < R2OAS::Schema::V3::ExternalDocumentObject; end
- class RtsdComponentsObject < R2OAS::Schema::V3::ComponentsObject; end
- module Components
- class RtsdSchemaObject < R2OAS::Schema::V3::Components::SchemaObject; end
- class RtsdRequestBodyObject < R2OAS::Schema::V3::Components::RequestBodyObject; end
- end
- end
-
context 'when default setting' do
before do
class DefaultDummy
@@ -56,14 +44,6 @@ class DefaultDummy
expect(subject[:swagger].editor.image).to eq 'swaggerapi/swagger-editor'
expect(subject[:swagger].editor.port).to eq '81'
expect(subject[:swagger].editor.exposed_port).to eq '8080/tcp'
- # object classes
- expect(subject[:use_object_classes][:info_object]).to eq R2OAS::Schema::V3::InfoObject
- expect(subject[:use_object_classes][:paths_object]).to eq R2OAS::Schema::V3::PathsObject
- expect(subject[:use_object_classes][:path_item_object]).to eq R2OAS::Schema::V3::PathItemObject
- expect(subject[:use_object_classes][:external_document_object]).to eq R2OAS::Schema::V3::ExternalDocumentObject
- expect(subject[:use_object_classes][:components_object]).to eq R2OAS::Schema::V3::ComponentsObject
- expect(subject[:use_object_classes][:components_schema_object]).to eq R2OAS::Schema::V3::Components::SchemaObject
- expect(subject[:use_object_classes][:components_request_body_object]).to eq R2OAS::Schema::V3::Components::RequestBodyObject
# plugin configuration
expect(subject[:plugins]).to eq []
expect(subject[:local_plugins_dir_name]).to eq 'plugins'
@@ -131,16 +111,6 @@ class CustomDummy
swagger.editor.port = '91'
swagger.editor.exposed_port = '9090/tcp'
end
- # object classes
- config.use_object_classes = {
- info_object: RtsdInfoObject,
- paths_object: RtsdPathsObject,
- path_item_object: RtsdPathItemObject,
- external_document_object: RtsdExternalDocumentObject,
- components_object: RtsdComponentsObject,
- components_schema_object: Components::RtsdSchemaObject,
- components_request_body_object: Components::RtsdRequestBodyObject
- }
# plugins configuration
config.plugins = [
['r2oas-plugin-transform-sample', { loose: false }],
@@ -190,14 +160,6 @@ class CustomDummy
expect(subject[:swagger].editor.image).to eq 'original/swagger-editor'
expect(subject[:swagger].editor.port).to eq '91'
expect(subject[:swagger].editor.exposed_port).to eq '9090/tcp'
- # object classes
- expect(subject[:use_object_classes][:info_object]).to eq RtsdInfoObject
- expect(subject[:use_object_classes][:paths_object]).to eq RtsdPathsObject
- expect(subject[:use_object_classes][:path_item_object]).to eq RtsdPathItemObject
- expect(subject[:use_object_classes][:external_document_object]).to eq RtsdExternalDocumentObject
- expect(subject[:use_object_classes][:components_object]).to eq RtsdComponentsObject
- expect(subject[:use_object_classes][:components_schema_object]).to eq Components::RtsdSchemaObject
- expect(subject[:use_object_classes][:components_request_body_object]).to eq Components::RtsdRequestBodyObject
# plugin configuration
expect(subject[:plugins]).to include(
['r2oas-plugin-transform-sample', { loose: false }],
@@ -209,28 +171,9 @@ class CustomDummy
expect(subject[:deprecation].silenced).to eq true
end
end
+ end
- context 'deprecation warning' do
- context 'when deprecation.silenced is false (default)' do
- it do
- expect do
- R2OAS.configure do |config|
- config.use_object_classes = {}
- end
- end.to output(/DEPRECATION WARNING: Using a R2OAS.use_object_classes= in configuration is deprecated and will be removed in r2-oas \(v0.4.2\)./).to_stderr
- end
- end
-
- context 'when deprecation.silenced is true' do
- it do
- expect do
- R2OAS.configure do |config|
- config.deprecation.silenced = true
- config.use_object_classes = {}
- end
- end.not_to output(/DEPRECATION WARNING: Using a R2OAS.use_object_classes= in configuration is deprecated and will be removed in r2-oas \(v0.4.2\)./).to_stderr
- end
- end
- end
+ describe 'init' do
+ it { expect { described_class.init }.not_to raise_error }
end
end
diff --git a/spec/r2-oas/schema/v3/object/from_files/utils/refs_spec.rb b/spec/r2-oas/schema/v3/object/from_files/utils/refs_spec.rb
index 427d7ac1..26ff5430 100644
--- a/spec/r2-oas/schema/v3/object/from_files/utils/refs_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_files/utils/refs_spec.rb
@@ -82,8 +82,8 @@
context 'when error not occurs' do
it do
- expect { subject.schema_name = 'API_V1_Task_200_GET' }.not_to raise_error(NoMethodError)
- expect { subject[:schema_name] = 'API_V1_Task_200_GET' }.not_to raise_error(R2OAS::RefInvalidAssignment)
+ expect { subject.schema_name = 'API_V1_Task_200_GET' }.not_to raise_error
+ expect { subject[:schema_name] = 'API_V1_Task_200_GET' }.not_to raise_error
end
end
end
diff --git a/spec/r2-oas/schema/v3/object/from_routes/base_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/base_object_spec.rb
index 4782d14c..3136c280 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/base_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/base_object_spec.rb
@@ -5,7 +5,6 @@
RSpec.describe R2OAS::Schema::V3::BaseObject do
let(:object) { described_class.new }
let(:swagger) { object.send(:swagger) }
- let(:use_object_classes) { object.instance_variable_get(:@use_object_classes) }
let(:http_statuses_when_http_method) { object.send(:http_statuses_when_http_method) }
describe '.initialize' do
@@ -27,13 +26,6 @@
it { expect(swagger.editor.image).to eq 'swaggerapi/swagger-editor' }
it { expect(swagger.editor.port).to eq '81' }
it { expect(swagger.editor.exposed_port).to eq '8080/tcp' }
- it { expect(use_object_classes[:info_object]).to eq R2OAS::Schema::V3::InfoObject }
- it { expect(use_object_classes[:paths_object]).to eq R2OAS::Schema::V3::PathsObject }
- it { expect(use_object_classes[:path_item_object]).to eq R2OAS::Schema::V3::PathItemObject }
- it { expect(use_object_classes[:external_document_object]).to eq R2OAS::Schema::V3::ExternalDocumentObject }
- it { expect(use_object_classes[:components_object]).to eq R2OAS::Schema::V3::ComponentsObject }
- it { expect(use_object_classes[:components_schema_object]).to eq R2OAS::Schema::V3::Components::SchemaObject }
- it { expect(use_object_classes[:components_request_body_object]).to eq R2OAS::Schema::V3::Components::RequestBodyObject }
it { expect(http_statuses_when_http_method[:get]).to eq default: %w[200 422], path_parameter: %w[200 404 422] }
it { expect(http_statuses_when_http_method[:post]).to eq default: %w[201 422], path_parameter: %w[201 404 422] }
it { expect(http_statuses_when_http_method[:patch]).to eq default: %w[204 422], path_parameter: %w[204 404 422] }
@@ -43,49 +35,15 @@
end
context 'when override settings' do
- let(:info_object_class) { double('TestInfoObjectClass') }
-
before do
R2OAS.configure do |config|
config.namespace_type = :dot
config.doc_save_file_name = 'apidoc.yml'
- config.use_object_classes.merge!(
- info_object: info_object_class
- )
end
end
it { expect(object.send(:namespace_type)).to eq :dot }
it { expect(object.send(:doc_save_file_name)).to eq 'apidoc.yml' }
- it { expect(use_object_classes[:info_object]).to eq info_object_class }
end
end
-
- describe '#info_object_class' do
- it { expect(object.info_object_class).to eq R2OAS::Schema::V3::InfoObject }
- end
-
- describe '#paths_object_class' do
- it { expect(object.paths_object_class).to eq R2OAS::Schema::V3::PathsObject }
- end
-
- describe '#path_item_object_class' do
- it { expect(object.path_item_object_class).to eq R2OAS::Schema::V3::PathItemObject }
- end
-
- describe '#external_document_object_class' do
- it { expect(object.external_document_object_class).to eq R2OAS::Schema::V3::ExternalDocumentObject }
- end
-
- describe '#components_object_class' do
- it { expect(object.components_object_class).to eq R2OAS::Schema::V3::ComponentsObject }
- end
-
- describe '#components_schema_object_class' do
- it { expect(object.components_schema_object_class).to eq R2OAS::Schema::V3::Components::SchemaObject }
- end
-
- describe '#components_request_body_object_class' do
- it { expect(object.components_request_body_object_class).to eq R2OAS::Schema::V3::Components::RequestBodyObject }
- end
end
diff --git a/spec/r2-oas/schema/v3/object/from_routes/components/request_body_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/components/request_body_object_spec.rb
index e02c6138..bcd1cf20 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/components/request_body_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/components/request_body_object_spec.rb
@@ -8,7 +8,7 @@
{ format_name: '', path: '/api/v1/tasks/{id}', required_parameters: { id: { type: 'integer' } }, schema_name: 'Api_V1_Task', tag_name: 'api/v1/task', verb: 'patch' }
end
let(:opts) { {} }
- let(:object) { R2OAS.use_object_classes[:components_request_body_object].new(route_data, path, opts) }
+ let(:object) { described_class.new(route_data, path, opts) }
before do
init
@@ -28,35 +28,6 @@
'data' => { 'components' => { 'schemas' => { 'Api_V1_Task' => { 'type' => 'object', 'properties' => { 'id' => { 'type' => 'integer', 'format' => 'int64' } } } } } } }
end
end
-
- context 'when use before_create && after_create' do
- before do
- module Components
- class TestRequestBodyObject < R2OAS::Schema::V3::Components::RequestBodyObject
- before_create do |doc, _schema_name|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc, _schema_name|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- components_request_body_object: Components::TestRequestBodyObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
end
describe '#create_doc (private)' do
diff --git a/spec/r2-oas/schema/v3/object/from_routes/components/schema_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/components/schema_object_spec.rb
index d4c5eb82..81cd0b72 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/components/schema_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/components/schema_object_spec.rb
@@ -8,7 +8,7 @@
{ format_name: '', path: '/api/v1/tasks/{id}', required_parameters: { id: { type: 'integer' } }, schema_name: 'Api_V1_Task', tag_name: 'api/v1/task', verb: 'patch' }
end
let(:opts) { {} }
- let(:object) { R2OAS.use_object_classes[:components_schema_object].new(route_data, path, opts) }
+ let(:object) { described_class.new(route_data, path, opts) }
before do
init
@@ -24,35 +24,6 @@
expect(object.to_doc).to eq 'properties' => { 'id' => { 'format' => 'int64', 'type' => 'integer' } }, 'type' => 'object'
end
end
-
- context 'when use before_create && after_create' do
- before do
- module Components
- class TestSchemaObject < R2OAS::Schema::V3::Components::SchemaObject
- before_create do |doc, _schema_name|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc, _schema_name|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- components_schema_object: Components::TestSchemaObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
end
describe '#create_doc (private)' do
@@ -60,40 +31,4 @@ class TestSchemaObject < R2OAS::Schema::V3::Components::SchemaObject
expect(object.send(:create_doc)).to eq 'properties' => { 'id' => { 'format' => 'int64', 'type' => 'integer' } }, 'type' => 'object'
end
end
-
- describe '#components_schema_name' do
- before do
- module Components
- class TestSchemaObject2 < R2OAS::Schema::V3::Components::SchemaObject
- NS_DIV = '_'
- # e.x.)
- # GET(200) /v1/tasks/{id} => V1_Task_P1_GET_200
- def components_schema_name(_doc, path_component, tag_name, verb, http_status, _schema_name)
- path_parameters_count = path_component.path_parameters.count
- excluded_path_parameters = path_component.path_excluded_path_parameters
- excluded_path_parameters_arr = excluded_path_parameters.split('/').delete_if(&:empty?)
- base_schema_name = excluded_path_parameters.split('/').map(&:singularize).map(&:camelize).join(NS_DIV)
-
- base_schema_name = tag_name.split('/').map(&:singularize).map(&:camelize).join(NS_DIV) + base_schema_name if excluded_path_parameters.eql? '' || excluded_path_parameters_arr.count == 1
-
- if path_parameters_count.zero?
- [base_schema_name, verb.upcase, http_status].join(NS_DIV)
- else
- [base_schema_name, "P#{path_parameters_count}", verb.upcase, http_status].join(NS_DIV)
- end
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- components_schema_object: Components::TestSchemaObject2
- )
- end
- end
- end
-
- it do
- expect(object.send(:_components_schema_name, '204')).to eq 'Api_V1_Task_P1_PATCH_204'
- end
- end
end
diff --git a/spec/r2-oas/schema/v3/object/from_routes/components_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/components_object_spec.rb
index d4d185d2..9f5d7896 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/components_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/components_object_spec.rb
@@ -12,7 +12,7 @@
{ data: { format_name: '', path: '/api/v1/tasks/{id}', required_parameters: { id: { type: 'integer' } }, schema_name: 'Api_V1_Task', tag_name: 'api/v1/task', verb: 'delete' }, path: '/api/v1/tasks/{id}' }
]
end
- let(:object) { R2OAS.use_object_classes[:components_object].new(routes_data) }
+ let(:object) { described_class.new(routes_data) }
before do
init
@@ -22,35 +22,6 @@
delete_oas_docs
end
- describe '#to_doc' do
- context 'when use before_create && after_create' do
- before do
- class TestComponentsObject < R2OAS::Schema::V3::ComponentsObject
- before_create do |doc|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- components_object: TestComponentsObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
- end
-
describe '#create_doc' do
context 'when default' do
it do
diff --git a/spec/r2-oas/schema/v3/object/from_routes/external_document_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/external_document_object_spec.rb
index 4b2f944c..0c9bcfa2 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/external_document_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/external_document_object_spec.rb
@@ -4,36 +4,7 @@
RSpec.describe R2OAS::Schema::V3::ExternalDocumentObject do
let(:opts) { {} }
- let(:object) { R2OAS.use_object_classes[:external_document_object].new(opts) }
-
- describe '#to_doc' do
- context 'when use before_create && after_create' do
- before do
- class TestExternalDocumentObject < R2OAS::Schema::V3::ExternalDocumentObject
- before_create do |doc|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- external_document_object: TestExternalDocumentObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
- end
+ let(:object) { described_class.new(opts) }
describe '#create_doc' do
it { expect(object.send(:create_doc)).to eq 'description' => '', 'url' => '' }
diff --git a/spec/r2-oas/schema/v3/object/from_routes/info_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/info_object_spec.rb
index fcba249a..eba6f1d9 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/info_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/info_object_spec.rb
@@ -4,36 +4,7 @@
RSpec.describe R2OAS::Schema::V3::InfoObject do
let(:opts) { {} }
- let(:object) { R2OAS.use_object_classes[:info_object].new(opts) }
-
- describe '#to_doc' do
- context 'when use before_create && after_create' do
- before do
- class TestInfoObject < R2OAS::Schema::V3::InfoObject
- before_create do |doc|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- info_object: TestInfoObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
- end
+ let(:object) { described_class.new(opts) }
describe '#create_doc (private)' do
it do
diff --git a/spec/r2-oas/schema/v3/object/from_routes/path_item_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/path_item_object_spec.rb
index d3f3b2b4..71c15322 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/path_item_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/path_item_object_spec.rb
@@ -7,36 +7,7 @@
{ format_name: '', path: '/api/v1/tasks/{id}', required_parameters: { id: { type: 'integer' } }, schema_name: 'Api_V1_Task', tag_name: 'api/v1/task', verb: 'delete' }
end
let(:path) { '/api/v1/tasks/{id}' }
- let(:object) { R2OAS.use_object_classes[:path_item_object].new(route_data, path) }
-
- describe '#to_doc' do
- context 'when use before_create && after_create' do
- before do
- class TestPathItemObject < R2OAS::Schema::V3::PathItemObject
- before_create do |doc, _path|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc, _path|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- path_item_object: TestPathItemObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
- end
+ let(:object) { described_class.new(route_data, path) }
describe '#create_doc' do
it do
diff --git a/spec/r2-oas/schema/v3/object/from_routes/paths_object_spec.rb b/spec/r2-oas/schema/v3/object/from_routes/paths_object_spec.rb
index a28f0767..8951eb26 100644
--- a/spec/r2-oas/schema/v3/object/from_routes/paths_object_spec.rb
+++ b/spec/r2-oas/schema/v3/object/from_routes/paths_object_spec.rb
@@ -4,7 +4,7 @@
RSpec.describe R2OAS::Schema::V3::PathsObject do
let(:routes_data) { [] }
- let(:object) { R2OAS.use_object_classes[:paths_object].new(routes_data) }
+ let(:object) { described_class.new(routes_data) }
before do
init
@@ -14,35 +14,6 @@
delete_oas_docs
end
- describe '#to_doc' do
- context 'when use before_create && after_create' do
- before do
- class TestPathsObject < R2OAS::Schema::V3::PathsObject
- before_create do |doc, _path|
- doc.merge!(
- 'before_key' => 'before_value'
- )
- end
-
- after_create do |doc, _path|
- doc.merge!(
- 'after_key' => 'after_value'
- )
- end
- end
-
- R2OAS.configure do |config|
- config.use_object_classes.merge!(
- paths_object: TestPathsObject
- )
- end
- end
-
- it { expect(object.to_doc['before_key']).to eq 'before_value' }
- it { expect(object.to_doc['after_key']).to eq 'after_value' }
- end
- end
-
describe '#create_doc' do
context 'when namespace_type is :underbar' do
let(:routes_data) do
diff --git a/spec/r2-oas/tasks/main_spec.rb b/spec/r2-oas/tasks/main_spec.rb
index 6119cb65..28e20339 100644
--- a/spec/r2-oas/tasks/main_spec.rb
+++ b/spec/r2-oas/tasks/main_spec.rb
@@ -76,7 +76,7 @@
end
it 'should do not occur error' do
- expect { subject }.not_to raise_error(R2OAS::NoFileExistsError)
+ expect { subject }.not_to raise_error
end
it do
subject
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index e0827a36..565676db 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -4,6 +4,7 @@
# workaround uninitialized constant R2OAS::ActiveSupport
require 'action_controller/railtie'
require 'r2-oas'
+require 'r2-oas/schema/v3/object/from_routes/all'
require 'pry'
# needs to load the app
diff --git a/spec/support/helpers/config_helper.rb b/spec/support/helpers/config_helper.rb
index 7c6808e1..7bda4602 100644
--- a/spec/support/helpers/config_helper.rb
+++ b/spec/support/helpers/config_helper.rb
@@ -29,16 +29,6 @@ def reset_config
swagger.editor.exposed_port = '8080/tcp'
end
- config.use_object_classes = {
- info_object: R2OAS::Schema::V3::InfoObject,
- paths_object: R2OAS::Schema::V3::PathsObject,
- path_item_object: R2OAS::Schema::V3::PathItemObject,
- external_document_object: R2OAS::Schema::V3::ExternalDocumentObject,
- components_object: R2OAS::Schema::V3::ComponentsObject,
- components_schema_object: R2OAS::Schema::V3::Components::SchemaObject,
- components_request_body_object: R2OAS::Schema::V3::Components::RequestBodyObject
- }
-
config.http_statuses_when_http_method = {
get: {
default: %w[200 422],
diff --git a/spec/support/helpers/hooks_helper.rb b/spec/support/helpers/hooks_helper.rb
index 7374a496..cc8d26bb 100644
--- a/spec/support/helpers/hooks_helper.rb
+++ b/spec/support/helpers/hooks_helper.rb
@@ -4,6 +4,6 @@
module HooksHelper
def reset_plugin_repo
- ::R2OAS::Hooks::Hook.repository[:plugin] = {}
+ ::R2OAS::Hooks::Hook.repository[:plugin] = {} if ::R2OAS::Hooks::Hook.repository.is_a? Hash
end
end