From 475929e9aa6f586387ddb928bacf2f0c81bf2672 Mon Sep 17 00:00:00 2001 From: Jay Danielian Date: Thu, 1 Aug 2019 08:37:05 -0400 Subject: [PATCH] Renames gems to open_api-rswag-* --- Gemfile | 6 +-- rswag-api/bin/rails | 2 +- rswag-specs/lib/tasks/rswag-specs_tasks.rake | 2 +- rswag-specs/open_api-rswag-specs.gemspec | 2 +- rswag-ui/bin/rails | 2 +- .../rswag/ui/custom/custom_generator.rb | 2 +- .../rswag/ui/install/templates/rswag-ui.rb | 2 +- rswag-ui/lib/open_api/rswag/ui.rb | 16 +++++++ .../lib/open_api/rswag/ui/configuration.rb | 37 +++++++++++++++ rswag-ui/lib/open_api/rswag/ui/engine.rb | 19 ++++++++ .../lib/{ => open_api}/rswag/ui/index.erb | 0 rswag-ui/lib/open_api/rswag/ui/middleware.rb | 46 +++++++++++++++++++ rswag-ui/lib/rswag/ui.rb | 14 ------ rswag-ui/lib/rswag/ui/configuration.rb | 35 -------------- rswag-ui/lib/rswag/ui/engine.rb | 17 ------- rswag-ui/lib/rswag/ui/middleware.rb | 44 ------------------ rswag-ui/lib/tasks/rswag-ui_tasks.rake | 2 +- rswag-ui/package-lock.json | 2 +- rswag-ui/package.json | 2 +- rswag-ui/rswag-ui.gemspec | 6 +-- 20 files changed, 133 insertions(+), 125 deletions(-) create mode 100644 rswag-ui/lib/open_api/rswag/ui.rb create mode 100644 rswag-ui/lib/open_api/rswag/ui/configuration.rb create mode 100644 rswag-ui/lib/open_api/rswag/ui/engine.rb rename rswag-ui/lib/{ => open_api}/rswag/ui/index.erb (100%) create mode 100644 rswag-ui/lib/open_api/rswag/ui/middleware.rb delete mode 100644 rswag-ui/lib/rswag/ui.rb delete mode 100644 rswag-ui/lib/rswag/ui/configuration.rb delete mode 100644 rswag-ui/lib/rswag/ui/engine.rb delete mode 100644 rswag-ui/lib/rswag/ui/middleware.rb diff --git a/Gemfile b/Gemfile index 685ce22..ba8c5fd 100644 --- a/Gemfile +++ b/Gemfile @@ -18,20 +18,20 @@ end gem 'sqlite3', '~> 1.3.6' gem 'open_api-rswag-api', path: './rswag-api' -gem 'rswag-ui', path: './rswag-ui' +gem 'open_api-rswag-ui', path: './rswag-ui' group :test do gem 'capybara' gem 'capybara-webkit' gem 'generator_spec' gem 'rspec-rails' - gem 'rswag-specs', path: './rswag-specs' + gem 'open_api-rswag-specs', path: './rswag-specs' gem 'test-unit' end group :development do gem 'guard-rspec', require: false - gem 'rswag-specs', path: './rswag-specs' + gem 'open_api-rswag-specs', path: './rswag-specs' gem 'rubocop' end diff --git a/rswag-api/bin/rails b/rswag-api/bin/rails index 1ef582f..28e3103 100755 --- a/rswag-api/bin/rails +++ b/rswag-api/bin/rails @@ -2,7 +2,7 @@ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/rswag/api/engine', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/open_api/rswag/api/engine', __FILE__) # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) diff --git a/rswag-specs/lib/tasks/rswag-specs_tasks.rake b/rswag-specs/lib/tasks/rswag-specs_tasks.rake index 08a62b8..f400bb6 100644 --- a/rswag-specs/lib/tasks/rswag-specs_tasks.rake +++ b/rswag-specs/lib/tasks/rswag-specs_tasks.rake @@ -8,7 +8,7 @@ namespace :rswag do t.pattern = 'spec/requests/**/*_spec.rb, spec/api/**/*_spec.rb, spec/integration/**/*_spec.rb' # NOTE: rspec 2.x support - if Rswag::Specs::RSPEC_VERSION > 2 && Rswag::Specs.config.swagger_dry_run + if OpenApi::Rswag::Specs::RSPEC_VERSION > 2 && OpenApi::Rswag::Specs.config.swagger_dry_run t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--dry-run', '--order defined' ] else t.rspec_opts = [ '--format Rswag::Specs::SwaggerFormatter', '--order defined' ] diff --git a/rswag-specs/open_api-rswag-specs.gemspec b/rswag-specs/open_api-rswag-specs.gemspec index 424fcfa..94bc6fd 100644 --- a/rswag-specs/open_api-rswag-specs.gemspec +++ b/rswag-specs/open_api-rswag-specs.gemspec @@ -4,7 +4,7 @@ $LOAD_PATH.push File.expand_path('lib', __dir__) # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = 'rswag-specs' + s.name = 'open_api-rswag-specs' s.version = ENV['TRAVIS_TAG'] || '0.0.0' s.authors = ['Richie Morris', 'Jay Danielian'] s.email = ['domaindrivendev@gmail.com'] diff --git a/rswag-ui/bin/rails b/rswag-ui/bin/rails index 1ef582f..28e3103 100755 --- a/rswag-ui/bin/rails +++ b/rswag-ui/bin/rails @@ -2,7 +2,7 @@ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application. ENGINE_ROOT = File.expand_path('../..', __FILE__) -ENGINE_PATH = File.expand_path('../../lib/rswag/api/engine', __FILE__) +ENGINE_PATH = File.expand_path('../../lib/open_api/rswag/api/engine', __FILE__) # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) diff --git a/rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb b/rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb index 735fc8e..c4ea1c4 100644 --- a/rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb +++ b/rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb @@ -3,7 +3,7 @@ require 'rails/generators' module Rswag module Ui class CustomGenerator < Rails::Generators::Base - source_root File.expand_path('../../../../../../lib/rswag/ui', __FILE__) + source_root File.expand_path('../../../../../../lib/open_api/rswag/ui', __FILE__) def add_custom_index copy_file('index.erb', 'app/views/rswag/ui/home/index.html.erb') diff --git a/rswag-ui/lib/generators/rswag/ui/install/templates/rswag-ui.rb b/rswag-ui/lib/generators/rswag/ui/install/templates/rswag-ui.rb index 084a512..2fa7986 100644 --- a/rswag-ui/lib/generators/rswag/ui/install/templates/rswag-ui.rb +++ b/rswag-ui/lib/generators/rswag/ui/install/templates/rswag-ui.rb @@ -1,4 +1,4 @@ -Rswag::Ui.configure do |c| +OpenApi::Rswag::Ui.configure do |c| # List the Swagger endpoints that you want to be documented through the swagger-ui # The first parameter is the path (absolute or relative to the UI host) to the corresponding diff --git a/rswag-ui/lib/open_api/rswag/ui.rb b/rswag-ui/lib/open_api/rswag/ui.rb new file mode 100644 index 0000000..d24b5f3 --- /dev/null +++ b/rswag-ui/lib/open_api/rswag/ui.rb @@ -0,0 +1,16 @@ +require 'open_api/rswag/ui/configuration' +require 'open_api/rswag/ui/engine' + +module OpenApi + module Rswag + module Ui + def self.configure + yield(config) + end + + def self.config + @config ||= Configuration.new + end + end + end +end diff --git a/rswag-ui/lib/open_api/rswag/ui/configuration.rb b/rswag-ui/lib/open_api/rswag/ui/configuration.rb new file mode 100644 index 0000000..a49964c --- /dev/null +++ b/rswag-ui/lib/open_api/rswag/ui/configuration.rb @@ -0,0 +1,37 @@ +require 'ostruct' + +module OpenApi + module Rswag + module Ui + class Configuration + attr_reader :template_locations + attr_accessor :config_object + attr_accessor :oauth_config_object + attr_reader :assets_root + + def initialize + @template_locations = [ + # preffered override location + "#{Rack::Directory.new('').root}/swagger/index.erb", + # backwards compatible override location + "#{Rack::Directory.new('').root}/app/views/rswag/ui/home/index.html.erb", + # default location + File.expand_path('../index.erb', __FILE__) + ] + @assets_root = File.expand_path('../../../../../node_modules/swagger-ui-dist', __FILE__) + @config_object = {} + @oauth_config_object = {} + end + + def swagger_endpoint(url, name) + @config_object[:urls] ||= [] + @config_object[:urls] << { url: url, name: name } + end + + def get_binding + binding + end + end + end + end +end diff --git a/rswag-ui/lib/open_api/rswag/ui/engine.rb b/rswag-ui/lib/open_api/rswag/ui/engine.rb new file mode 100644 index 0000000..16da05e --- /dev/null +++ b/rswag-ui/lib/open_api/rswag/ui/engine.rb @@ -0,0 +1,19 @@ +require 'open_api/rswag/ui/middleware' + +module OpenApi + module Rswag + module Ui + class Engine < ::Rails::Engine + isolate_namespace OpenApi::Rswag::Ui + + initializer 'rswag-ui.initialize' do |app| + middleware.use OpenApi::Rswag::Ui::Middleware, OpenApi::Rswag::Ui.config + end + + rake_tasks do + load File.expand_path('../../../tasks/rswag-ui_tasks.rake', __FILE__) + end + end + end + end +end diff --git a/rswag-ui/lib/rswag/ui/index.erb b/rswag-ui/lib/open_api/rswag/ui/index.erb similarity index 100% rename from rswag-ui/lib/rswag/ui/index.erb rename to rswag-ui/lib/open_api/rswag/ui/index.erb diff --git a/rswag-ui/lib/open_api/rswag/ui/middleware.rb b/rswag-ui/lib/open_api/rswag/ui/middleware.rb new file mode 100644 index 0000000..6229f83 --- /dev/null +++ b/rswag-ui/lib/open_api/rswag/ui/middleware.rb @@ -0,0 +1,46 @@ +module OpenApi + module Rswag + module Ui + class Middleware < Rack::Static + + def initialize(app, config) + @config = config + super(app, urls: [ '' ], root: config.assets_root ) + end + + def call(env) + if base_path?(env) + redirect_uri = env['SCRIPT_NAME'].chomp('/') + '/index.html' + return [ 301, { 'Location' => redirect_uri }, [ ] ] + end + + if index_path?(env) + return [ 200, { 'Content-Type' => 'text/html' }, [ render_template ] ] + end + + super + end + + private + + def base_path?(env) + env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/" + end + + def index_path?(env) + env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/index.html" + end + + def render_template + file = File.new(template_filename) + template = ERB.new(file.read) + template.result(@config.get_binding) + end + + def template_filename + @config.template_locations.find { |filename| File.exists?(filename) } + end + end + end + end +end diff --git a/rswag-ui/lib/rswag/ui.rb b/rswag-ui/lib/rswag/ui.rb deleted file mode 100644 index bf5c810..0000000 --- a/rswag-ui/lib/rswag/ui.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rswag/ui/configuration' -require 'rswag/ui/engine' - -module Rswag - module Ui - def self.configure - yield(config) - end - - def self.config - @config ||= Configuration.new - end - end -end diff --git a/rswag-ui/lib/rswag/ui/configuration.rb b/rswag-ui/lib/rswag/ui/configuration.rb deleted file mode 100644 index 5f33c2c..0000000 --- a/rswag-ui/lib/rswag/ui/configuration.rb +++ /dev/null @@ -1,35 +0,0 @@ -require 'ostruct' - -module Rswag - module Ui - class Configuration - attr_reader :template_locations - attr_accessor :config_object - attr_accessor :oauth_config_object - attr_reader :assets_root - - def initialize - @template_locations = [ - # preffered override location - "#{Rack::Directory.new('').root}/swagger/index.erb", - # backwards compatible override location - "#{Rack::Directory.new('').root}/app/views/rswag/ui/home/index.html.erb", - # default location - File.expand_path('../index.erb', __FILE__) - ] - @assets_root = File.expand_path('../../../../node_modules/swagger-ui-dist', __FILE__) - @config_object = {} - @oauth_config_object = {} - end - - def swagger_endpoint(url, name) - @config_object[:urls] ||= [] - @config_object[:urls] << { url: url, name: name } - end - - def get_binding - binding - end - end - end -end diff --git a/rswag-ui/lib/rswag/ui/engine.rb b/rswag-ui/lib/rswag/ui/engine.rb deleted file mode 100644 index 78ee075..0000000 --- a/rswag-ui/lib/rswag/ui/engine.rb +++ /dev/null @@ -1,17 +0,0 @@ -require 'rswag/ui/middleware' - -module Rswag - module Ui - class Engine < ::Rails::Engine - isolate_namespace Rswag::Ui - - initializer 'rswag-ui.initialize' do |app| - middleware.use Rswag::Ui::Middleware, Rswag::Ui.config - end - - rake_tasks do - load File.expand_path('../../../tasks/rswag-ui_tasks.rake', __FILE__) - end - end - end -end diff --git a/rswag-ui/lib/rswag/ui/middleware.rb b/rswag-ui/lib/rswag/ui/middleware.rb deleted file mode 100644 index 3bad997..0000000 --- a/rswag-ui/lib/rswag/ui/middleware.rb +++ /dev/null @@ -1,44 +0,0 @@ -module Rswag - module Ui - class Middleware < Rack::Static - - def initialize(app, config) - @config = config - super(app, urls: [ '' ], root: config.assets_root ) - end - - def call(env) - if base_path?(env) - redirect_uri = env['SCRIPT_NAME'].chomp('/') + '/index.html' - return [ 301, { 'Location' => redirect_uri }, [ ] ] - end - - if index_path?(env) - return [ 200, { 'Content-Type' => 'text/html' }, [ render_template ] ] - end - - super - end - - private - - def base_path?(env) - env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/" - end - - def index_path?(env) - env['REQUEST_METHOD'] == "GET" && env['PATH_INFO'] == "/index.html" - end - - def render_template - file = File.new(template_filename) - template = ERB.new(file.read) - template.result(@config.get_binding) - end - - def template_filename - @config.template_locations.find { |filename| File.exists?(filename) } - end - end - end -end diff --git a/rswag-ui/lib/tasks/rswag-ui_tasks.rake b/rswag-ui/lib/tasks/rswag-ui_tasks.rake index 0166011..b27b1bd 100644 --- a/rswag-ui/lib/tasks/rswag-ui_tasks.rake +++ b/rswag-ui/lib/tasks/rswag-ui_tasks.rake @@ -6,7 +6,7 @@ namespace :rswag do dest = args[:dest] FileUtils.rm_r(dest, force: true) FileUtils.mkdir_p(dest) - FileUtils.cp_r(Dir.glob("#{Rswag::Ui.config.assets_root}/{*.js,*.png,*.css}"), dest) + FileUtils.cp_r(Dir.glob("#{OpenApi::Rswag::Ui.config.assets_root}/{*.js,*.png,*.css}"), dest) end end end diff --git a/rswag-ui/package-lock.json b/rswag-ui/package-lock.json index 664d3fa..cc6826d 100644 --- a/rswag-ui/package-lock.json +++ b/rswag-ui/package-lock.json @@ -1,5 +1,5 @@ { - "name": "rswag-ui", + "name": "openapi-rswag-ui", "version": "1.0.0", "lockfileVersion": 1, "requires": true, diff --git a/rswag-ui/package.json b/rswag-ui/package.json index 1fce627..813fa4c 100644 --- a/rswag-ui/package.json +++ b/rswag-ui/package.json @@ -1,5 +1,5 @@ { - "name": "rswag-ui", + "name": "openapi-rswag-ui", "version": "1.0.0", "private": true, "dependencies": { diff --git a/rswag-ui/rswag-ui.gemspec b/rswag-ui/rswag-ui.gemspec index 5b53548..e961438 100644 --- a/rswag-ui/rswag-ui.gemspec +++ b/rswag-ui/rswag-ui.gemspec @@ -2,11 +2,11 @@ $:.push File.expand_path("../lib", __FILE__) # Describe your gem and declare its dependencies: Gem::Specification.new do |s| - s.name = "rswag-ui" + s.name = "open_api-rswag-ui" s.version = ENV['TRAVIS_TAG'] || '0.0.0' - s.authors = ["Richie Morris"] + s.authors = ["Richie Morris", "Jay Danielian"] s.email = ["domaindrivendev@gmail.com"] - s.homepage = "https://github.com/domaindrivendev/rswag" + s.homepage = "https://github.com/jaydanielian/rswag" s.summary = "A Rails Engine that includes swagger-ui and powers it from configured Swagger endpoints" s.description = "Expose beautiful API documentation, that's powered by Swagger JSON endpoints, including a UI to explore and test operations" s.license = "MIT"