rename to rswag plus major refactor - almost a rewrite

This commit is contained in:
richie
2016-10-11 18:31:12 -07:00
parent f8d993356f
commit c558098c39
453 changed files with 52410 additions and 35793 deletions

View File

@@ -0,0 +1,8 @@
Description:
Adds a local version of index.html.erb for customizing the swagger-ui
Example:
rails generate rswag:ui:custom
This will create:
app/views/rswag/ui/home/index.html.erb

View File

@@ -0,0 +1,13 @@
require 'rails/generators'
module Rswag
module Ui
class CustomGenerator < Rails::Generators::Base
source_root File.expand_path('../../../../../../app/views/rswag/ui/home', __FILE__)
def add_custom_index
copy_file('index.html.erb', 'app/views/rswag/ui/home/index.html.erb')
end
end
end
end

View File

@@ -0,0 +1,8 @@
Description:
Adds rswag-api initializer for configuration
Example:
rails generate rswag:api:install
This will create:
config/initializers/rswag-api.rb

View File

@@ -0,0 +1,18 @@
require 'rails/generators'
module Rswag
module Ui
class InstallGenerator < Rails::Generators::Base
source_root File.expand_path('../templates', __FILE__)
def add_initializer
template('rswag-ui.rb', 'config/initializers/rswag-ui.rb')
end
def add_routes
route("mount Rswag::Ui::Engine => '/api-docs'")
end
end
end
end

View File

@@ -0,0 +1,9 @@
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
# JSON endpoint and the second is a title that will be displayed in the document selector
# NOTE: If you're using rspec-api to expose Swagger files (under swagger_root) as JSON endpoints,
# then the list below should correspond to the relative paths for those endpoints
c.swagger_endpoint '/api-docs/v1/swagger.json', 'API V1 Docs'
end

15
rswag-ui/lib/rswag/ui.rb Normal file
View File

@@ -0,0 +1,15 @@
require 'rswag/ui/version'
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

View File

@@ -0,0 +1,17 @@
require 'ostruct'
module Rswag
module Ui
class Configuration
attr_reader :swagger_endpoints
def initialize
@swagger_endpoints = []
end
def swagger_endpoint(path, title)
@swagger_endpoints << OpenStruct.new(path: path, title: title)
end
end
end
end

View File

@@ -0,0 +1,13 @@
module Rswag
module Ui
class Engine < ::Rails::Engine
isolate_namespace Rswag::Ui
initializer 'rswag-ui.initialize' do |app|
if app.config.respond_to?(:assets)
app.config.assets.precompile += [ 'swagger-ui/*' ]
end
end
end
end
end

View File

@@ -0,0 +1,5 @@
module Rswag
module Ui
VERSION = '1.0.0'
end
end