mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Renames gems to open_api-rswag-*
This commit is contained in:
parent
13f7007b2f
commit
475929e9aa
6
Gemfile
6
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
|
||||
|
||||
|
||||
@ -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__)
|
||||
|
||||
@ -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' ]
|
||||
|
||||
@ -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']
|
||||
|
||||
@ -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__)
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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
|
||||
|
||||
16
rswag-ui/lib/open_api/rswag/ui.rb
Normal file
16
rswag-ui/lib/open_api/rswag/ui.rb
Normal file
@ -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
|
||||
37
rswag-ui/lib/open_api/rswag/ui/configuration.rb
Normal file
37
rswag-ui/lib/open_api/rswag/ui/configuration.rb
Normal file
@ -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
|
||||
19
rswag-ui/lib/open_api/rswag/ui/engine.rb
Normal file
19
rswag-ui/lib/open_api/rswag/ui/engine.rb
Normal file
@ -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
|
||||
46
rswag-ui/lib/open_api/rswag/ui/middleware.rb
Normal file
46
rswag-ui/lib/open_api/rswag/ui/middleware.rb
Normal file
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
@ -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
|
||||
|
||||
2
rswag-ui/package-lock.json
generated
2
rswag-ui/package-lock.json
generated
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "rswag-ui",
|
||||
"name": "openapi-rswag-ui",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "rswag-ui",
|
||||
"name": "openapi-rswag-ui",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
|
||||
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user