From 868700ae0ca962e0b2b73ac5e36bf15cbfd13645 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Wed, 27 Jan 2021 23:44:57 +0900 Subject: [PATCH 01/14] Fix Unable to load the EventMachine C extension; To use the pure-ruby reactor, require 'em/pure_ruby' --- lib/r2-oas/schema/editor.rb | 2 +- lib/r2-oas/schema/monitor.rb | 2 +- lib/r2-oas/schema/ui.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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' From 01b595f84e737a971f8a0dea52ce84e178632f0a Mon Sep 17 00:00:00 2001 From: yukihirop Date: Wed, 27 Jan 2021 23:45:26 +0900 Subject: [PATCH 02/14] Fix Error loading the 'sqlite3' Active Record adapter in ruby 2.4.2 ``` == Rspec for Ruby Version: 2.4.2 == An error occurred while loading spec_helper. - Did you mean? rspec ./spec/rake_helper.rb Failure/Error: ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? incompatible library version - r2-oas/gemfiles/vendor/bundle/ruby/2.4.0/gems/sqlite3-1.4.2/lib/sqlite3/sqlite3_native.bundle ``` [ref] https://qiita.com/Kta-M/items/254a1ba141827a989cb7 --- gemfiles/ruby_2.4.2.gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gemfiles/ruby_2.4.2.gemfile b/gemfiles/ruby_2.4.2.gemfile index 751f9321..3c31f5fd 100644 --- a/gemfiles/ruby_2.4.2.gemfile +++ b/gemfiles/ruby_2.4.2.gemfile @@ -5,7 +5,7 @@ source "https://rubygems.org" ruby '2.4.2' group :test do - gem "sqlite3" + gem 'sqlite3', '~> 1.3.6' end gemspec path: "../" From e703960770568c4db269e30fd3ec39257536c0c8 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Thu, 28 Jan 2021 00:09:32 +0900 Subject: [PATCH 03/14] EOL ruby 2.3.x and Support Over Ruby 2.5.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since sqlite3 is not included in ruby ​​2.5.0, ruby ​​2.5.0 was removed. Problems only for operation check ``` $ /bin/bash devscript/all_support_ruby.sh rspec 2.5.0 == Rspec for Ruby Version: 2.5.0 == An error occurred while loading spec_helper. - Did you mean? rspec ./spec/rake_helper.rb Failure/Error: ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:') LoadError: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? incompatible library version - /Users/yukihirop/RubyProjects/r2-oas/gemfiles/vendor/bundle/ruby/2.5.0/gems/sqlite3-1.4.2/lib/sqlite3/sqlite3_native.bundle ``` --- .travis.yml | 1 - Appraisals | 4 +--- Gemfile | 4 ---- README.ja.md | 2 +- README.md | 2 +- devscript/all_support_ruby.sh | 2 -- devscript/bundle_for_all_support_ruby.sh | 6 +----- devscript/rspec_for_all_support_ruby.sh | 6 +----- gemfiles/ruby_2.3.3.gemfile | 11 ----------- gemfiles/ruby_2.4.2.gemfile | 11 ----------- r2-oas.gemspec | 2 +- 11 files changed, 6 insertions(+), 45 deletions(-) delete mode 100644 gemfiles/ruby_2.3.3.gemfile delete mode 100644 gemfiles/ruby_2.4.2.gemfile 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/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..334954b8 100644 --- a/README.ja.md +++ b/README.ja.md @@ -141,7 +141,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 diff --git a/README.md b/README.md index 1aee30e2..b657c5e6 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,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 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/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 3c31f5fd..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', '~> 1.3.6' -end - -gemspec path: "../" 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' From 519726f276c5ddcf85ff8add7ed93c52ad6108e3 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Thu, 28 Jan 2021 02:46:03 +0900 Subject: [PATCH 04/14] Remove use_object_classes option --- .rubocop_todo.yml | 6 -- docs/setting/configure.md | 16 ----- docs/usage/use_hook_methods.md | 4 +- docs/usage/use_hook_to_generate_docs.md | 4 +- lib/r2-oas/configuration.rb | 24 +------ lib/r2-oas/pluggable_configuration.rb | 36 ---------- lib/r2-oas/public.rb | 2 - .../object/from_routes/{public.rb => all.rb} | 0 .../v3/object/from_routes/base_object.rb | 25 +++---- spec/r2-oas/configuration_spec.rb | 61 ----------------- .../v3/object/from_routes/base_object_spec.rb | 14 ---- .../components/request_body_object_spec.rb | 31 +-------- .../components/schema_object_spec.rb | 67 +------------------ .../from_routes/components_object_spec.rb | 31 +-------- .../external_document_object_spec.rb | 31 +-------- .../v3/object/from_routes/info_object_spec.rb | 31 +-------- .../from_routes/path_item_object_spec.rb | 31 +-------- .../object/from_routes/paths_object_spec.rb | 31 +-------- spec/support/helpers/config_helper.rb | 10 --- 19 files changed, 20 insertions(+), 435 deletions(-) delete mode 100644 lib/r2-oas/pluggable_configuration.rb rename lib/r2-oas/schema/v3/object/from_routes/{public.rb => all.rb} (100%) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aa88d98b..318a79b7 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: @@ -179,7 +178,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,10 +194,6 @@ 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" 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/use_hook_methods.md b/docs/usage/use_hook_methods.md index 90e4e250..0eb55d30 100644 --- a/docs/usage/use_hook_methods.md +++ b/docs/usage/use_hook_methods.md @@ -1,7 +1,7 @@ # [Deprecated] 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..c90aae28 100644 --- a/docs/usage/use_hook_to_generate_docs.md +++ b/docs/usage/use_hook_to_generate_docs.md @@ -1,7 +1,7 @@ ## [Deprecated] 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/lib/r2-oas/configuration.rb b/lib/r2-oas/configuration.rb index 94943a9f..265748bd 100644 --- a/lib/r2-oas/configuration.rb +++ b/lib/r2-oas/configuration.rb @@ -3,7 +3,6 @@ require 'fileutils' require_relative 'app_configuration' -require_relative 'pluggable_configuration' require_relative 'configuration/paths_config' require_relative 'logger/stdout_logger' require_relative 'support/deprecation' @@ -11,9 +10,8 @@ module R2OAS module Configuration extend AppConfiguration - extend PluggableConfiguration - 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 +22,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,12 +51,6 @@ 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 @@ -117,9 +99,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/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/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/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..37927539 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 @@ -2,6 +2,7 @@ require 'forwardable' require 'r2-oas/plugin/executor' +require 'r2-oas/schema/v3/object/from_routes/all' module R2OAS module Schema @@ -16,40 +17,36 @@ 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] + InfoObject end def paths_object_class - @use_object_classes[:paths_object] + PathsObject end def path_item_object_class - @use_object_classes[:path_item_object] + PathItemObject end def external_document_object_class - @use_object_classes[:external_document_object] + ExternalDocumentObject end def components_object_class - @use_object_classes[:components_object] + ComponentsObject end def components_schema_object_class - @use_object_classes[:components_schema_object] + Components::SchemaObject end def components_request_body_object_class - @use_object_classes[:components_request_body_object] + Components::RequestBodyObject end private @@ -58,12 +55,6 @@ 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 diff --git a/spec/r2-oas/configuration_spec.rb b/spec/r2-oas/configuration_spec.rb index 92a82673..32dbb9c1 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,5 @@ class CustomDummy expect(subject[:deprecation].silenced).to eq true 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 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..f5f451ae 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,21 +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 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/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], From 650bf893ff353cb044d96811a33b04cd9f2b86e8 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Thu, 28 Jan 2021 03:23:22 +0900 Subject: [PATCH 05/14] Stop inheriting HookableBaseObject --- .rubocop_todo.yml | 2 - .../from_routes/hookable_base_object.rb | 100 ------------------ .../v3/object/from_routes/base_object.rb | 12 ++- .../components/request_body_object.rb | 22 +--- .../from_routes/components/schema_object.rb | 14 +-- .../object/from_routes/components_object.rb | 13 ++- .../from_routes/external_document_object.rb | 6 +- .../v3/object/from_routes/info_object.rb | 6 +- .../v3/object/from_routes/openapi_object.rb | 2 +- .../v3/object/from_routes/path_item_object.rb | 6 +- .../v3/object/from_routes/paths_object.rb | 37 ++----- spec/spec_helper.rb | 1 + spec/support/helpers/hooks_helper.rb | 4 +- 13 files changed, 43 insertions(+), 182 deletions(-) delete mode 100644 lib/r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 318a79b7..10a3a9c7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -160,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: @@ -200,7 +199,6 @@ Style/IdenticalConditionalBranches: 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/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/schema/v3/object/from_routes/base_object.rb b/lib/r2-oas/schema/v3/object/from_routes/base_object.rb index 37927539..b679e288 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 @@ -21,6 +21,14 @@ def initialize(opts = {}) @plugin_executor = ::R2OAS::Plugin::Executor.new(@plugins, opts) end + def doc + @_doc ||= {} + end + + def to_doc + raise 'Implement Inherit Class' + end + def info_object_class InfoObject end @@ -56,10 +64,6 @@ def app_configuration_options end 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..5043d0f0 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,13 @@ # 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' 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,7 +23,6 @@ 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) @@ -45,22 +44,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 +69,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..33fd112c 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 @@ -50,7 +42,7 @@ def create_doc end def _components_schema_name(http_status) - components_schema_name(doc, @path_comp, @tag_name, @verb, http_status, @schema_name) + @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..4744dc81 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,23 @@ # 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' 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 +29,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.) 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..f346691a 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 @@ -25,7 +25,7 @@ def to_doc 'servers' => servers_doc, 'components' => components_doc } - result + doc.merge!(result) end private 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..a4fd136f 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,13 @@ # frozen_string_literal: true require 'forwardable' -require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object' +require_relative 'base_object' require 'r2-oas/routing/components/path_component' 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 @@ -33,9 +33,7 @@ def initialize(route_data, path, opts = {}) 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..c5d77379 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,27 @@ # frozen_string_literal: true -require 'r2-oas/dynamic/schema/v3/object/from_routes/hookable_base_object' +require_relative 'base_object' require 'r2-oas/routing/components/path_component' 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] = path_item_object_class.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 +33,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.) # [ 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/hooks_helper.rb b/spec/support/helpers/hooks_helper.rb index 7374a496..d8e8c320 100644 --- a/spec/support/helpers/hooks_helper.rb +++ b/spec/support/helpers/hooks_helper.rb @@ -4,6 +4,8 @@ module HooksHelper def reset_plugin_repo - ::R2OAS::Hooks::Hook.repository[:plugin] = {} + if ::R2OAS::Hooks::Hook.repository.is_a? Hash + ::R2OAS::Hooks::Hook.repository[:plugin] = {} + end end end From 573cfa60be863909ad168121a2c5f2e129f0c4bf Mon Sep 17 00:00:00 2001 From: yukihirop Date: Thu, 28 Jan 2021 23:53:52 +0900 Subject: [PATCH 06/14] Remove BaseObject#***_class --- .../v3/object/from_routes/base_object.rb | 29 ------------------- .../components/request_body_object.rb | 3 +- .../object/from_routes/components_object.rb | 7 +++-- .../v3/object/from_routes/openapi_object.rb | 13 ++++++--- .../v3/object/from_routes/path_item_object.rb | 8 +++-- .../v3/object/from_routes/paths_object.rb | 7 +++-- .../v3/object/from_routes/base_object_spec.rb | 28 ------------------ 7 files changed, 24 insertions(+), 71 deletions(-) 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 b679e288..c4d53eb0 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 @@ -2,7 +2,6 @@ require 'forwardable' require 'r2-oas/plugin/executor' -require 'r2-oas/schema/v3/object/from_routes/all' module R2OAS module Schema @@ -29,34 +28,6 @@ def to_doc raise 'Implement Inherit Class' end - def info_object_class - InfoObject - end - - def paths_object_class - PathsObject - end - - def path_item_object_class - PathItemObject - end - - def external_document_object_class - ExternalDocumentObject - end - - def components_object_class - ComponentsObject - end - - def components_schema_object_class - Components::SchemaObject - end - - def components_request_body_object_class - Components::RequestBodyObject - end - private def app_configuration_options 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 5043d0f0..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 @@ -2,6 +2,7 @@ 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 @@ -25,7 +26,7 @@ def initialize(route_data, path, opts = {}) def to_doc 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 = { 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 4744dc81..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 @@ -3,6 +3,7 @@ require_relative 'base_object' require_relative 'components/schema_object' require_relative 'components/request_body_object' +require_relative 'path_item_object' module R2OAS module Schema @@ -48,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) @@ -68,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/openapi_object.rb b/lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb index f346691a..16add5ac 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,11 @@ 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 @@ -31,7 +36,7 @@ def to_doc private def info_doc - info_object_class.new(@opts).to_doc + InfoObject.new(@opts).to_doc end def tags_doc @@ -39,11 +44,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 +56,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 a4fd136f..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,8 +1,10 @@ # frozen_string_literal: true require 'forwardable' -require_relative '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 @@ -27,8 +29,8 @@ 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 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 c5d77379..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,7 +1,8 @@ # frozen_string_literal: true -require_relative 'base_object' require 'r2-oas/routing/components/path_component' +require_relative 'base_object' +require_relative 'path_item_object' module R2OAS module Schema @@ -21,7 +22,7 @@ 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] = path_item_object_class.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| @@ -42,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/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 f5f451ae..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 @@ -46,32 +46,4 @@ it { expect(object.send(:doc_save_file_name)).to eq 'apidoc.yml' } 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 From 9fcdf185eeadaf080b689da1a6bc3ee241271156 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 00:05:18 +0900 Subject: [PATCH 07/14] bundle exec rubocop -a --- lib/r2-oas/schema/v3/object/from_routes/base_object.rb | 2 +- .../schema/v3/object/from_routes/components/schema_object.rb | 2 +- lib/r2-oas/schema/v3/object/from_routes/openapi_object.rb | 1 - spec/support/helpers/hooks_helper.rb | 4 +--- 4 files changed, 3 insertions(+), 6 deletions(-) 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 c4d53eb0..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 @@ -21,7 +21,7 @@ def initialize(opts = {}) end def doc - @_doc ||= {} + @doc ||= {} end def to_doc 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 33fd112c..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 @@ -41,7 +41,7 @@ def create_doc doc.merge!(result) end - def _components_schema_name(http_status) + def _components_schema_name(_http_status) @schema_name end 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 16add5ac..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 @@ -8,7 +8,6 @@ require_relative 'components_object' require_relative 'paths_object' - module R2OAS module Schema module V3 diff --git a/spec/support/helpers/hooks_helper.rb b/spec/support/helpers/hooks_helper.rb index d8e8c320..cc8d26bb 100644 --- a/spec/support/helpers/hooks_helper.rb +++ b/spec/support/helpers/hooks_helper.rb @@ -4,8 +4,6 @@ module HooksHelper def reset_plugin_repo - if ::R2OAS::Hooks::Hook.repository.is_a? Hash - ::R2OAS::Hooks::Hook.repository[:plugin] = {} - end + ::R2OAS::Hooks::Hook.repository[:plugin] = {} if ::R2OAS::Hooks::Hook.repository.is_a? Hash end end From 493200cf7d658812f1c602ac4ef2ec48599df968 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 00:26:03 +0900 Subject: [PATCH 08/14] Update docs --- docs/_sidebar.md | 4 ++-- docs/usage/use_hook_methods.md | 5 ++--- docs/usage/use_hook_to_generate_docs.md | 5 ++--- 3 files changed, 6 insertions(+), 8 deletions(-) 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/usage/use_hook_methods.md b/docs/usage/use_hook_methods.md index 0eb55d30..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 -!> ・This option is valid until `v0.4.1`. - ・Please use `plugin` instead for `v0.5.0` and above +!> 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 c90aae28..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 -!> ・This option is valid until `v0.4.1`. - ・Please use `plugin` instead for `v0.5.0` and above +!> This option is valid until `v0.4.1`. Please use `plugin` instead for `v0.5.0` and above ## Prepare From 550bc16a380f178a8e0da7703d06c89dd377a085 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 02:37:31 +0900 Subject: [PATCH 09/14] Fix NameError: uninitialized class variable @@hook_klass in R2OAS::Plugin::Hookable --- lib/r2-oas/plugin/hookable.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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) From 74cd4e74a322f4589b5cb81d5673e39ae5f0a40d Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 22:56:46 +0900 Subject: [PATCH 10/14] Upgrade init command --- README.ja.md | 21 +++++++- README.md | 21 +++++++- docs/usage/initialize.md | 8 +++ lib/r2-oas/configuration.rb | 26 ++++++--- lib/r2-oas/configuration/paths_config.rb | 9 ++-- lib/r2-oas/helpers/file_helper.rb | 68 ++++++++++++++++++++++++ lib/r2-oas/tasks/main.rake | 3 +- spec/r2-oas/configuration_spec.rb | 4 ++ 8 files changed, 144 insertions(+), 16 deletions(-) create mode 100644 lib/r2-oas/helpers/file_helper.rb diff --git a/README.ja.md b/README.ja.md index 334954b8..1ba2c636 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 diff --git a/README.md b/README.md index b657c5e6..0204af59 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 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/lib/r2-oas/configuration.rb b/lib/r2-oas/configuration.rb index 265748bd..bc2855cc 100644 --- a/lib/r2-oas/configuration.rb +++ b/lib/r2-oas/configuration.rb @@ -6,10 +6,12 @@ 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 + include Helpers::FileHelper PUBLIC_VALID_OPTIONS_KEYS = AppConfiguration::VALID_OPTIONS_KEYS @@ -56,6 +58,9 @@ def load_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}") @@ -66,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 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/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/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/spec/r2-oas/configuration_spec.rb b/spec/r2-oas/configuration_spec.rb index 32dbb9c1..22c1d151 100644 --- a/spec/r2-oas/configuration_spec.rb +++ b/spec/r2-oas/configuration_spec.rb @@ -172,4 +172,8 @@ class CustomDummy end end end + + describe 'init' do + it { expect { described_class.init }.not_to raise_error } + end end From a03426860f4b9c13b3c12e596f128e3d9bba6b82 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 23:08:14 +0900 Subject: [PATCH 11/14] Modify README about ruby EOL --- README.ja.md | 4 ---- README.md | 4 ---- 2 files changed, 8 deletions(-) diff --git a/README.ja.md b/README.ja.md index 1ba2c636..9b1b50eb 100644 --- a/README.ja.md +++ b/README.ja.md @@ -202,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 @@ -231,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 0204af59..dc33db1b 100644 --- a/README.md +++ b/README.md @@ -206,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 @@ -235,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 From 22baeae98e934fe8df4656237350ac9d32f93e37 Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 23:24:03 +0900 Subject: [PATCH 12/14] Do not use raise_error(SpecificErrorClass) [ref] https://stackoverflow.com/a/61155092/9434894 --- spec/r2-oas/schema/v3/object/from_files/utils/refs_spec.rb | 4 ++-- spec/r2-oas/tasks/main_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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 From 131ef78ee13676011e4fb0c9911981c7a92674ef Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 23:36:17 +0900 Subject: [PATCH 13/14] v0.5.0 --- lib/r2-oas/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 38617bbe703966f10c4466d1020e40ac2c93d87e Mon Sep 17 00:00:00 2001 From: yukihirop Date: Fri, 29 Jan 2021 23:44:38 +0900 Subject: [PATCH 14/14] Update CHANGELOG --- CHANGELOG.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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