mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
rename to rswag plus major refactor - almost a rewrite
This commit is contained in:
8
rswag-ui/lib/generators/rswag/ui/custom/USAGE
Normal file
8
rswag-ui/lib/generators/rswag/ui/custom/USAGE
Normal 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
|
||||
13
rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb
Normal file
13
rswag-ui/lib/generators/rswag/ui/custom/custom_generator.rb
Normal 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
|
||||
8
rswag-ui/lib/generators/rswag/ui/install/USAGE
Normal file
8
rswag-ui/lib/generators/rswag/ui/install/USAGE
Normal 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
|
||||
@@ -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
|
||||
@@ -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
15
rswag-ui/lib/rswag/ui.rb
Normal 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
|
||||
17
rswag-ui/lib/rswag/ui/configuration.rb
Normal file
17
rswag-ui/lib/rswag/ui/configuration.rb
Normal 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
|
||||
13
rswag-ui/lib/rswag/ui/engine.rb
Normal file
13
rswag-ui/lib/rswag/ui/engine.rb
Normal 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
|
||||
5
rswag-ui/lib/rswag/ui/version.rb
Normal file
5
rswag-ui/lib/rswag/ui/version.rb
Normal file
@@ -0,0 +1,5 @@
|
||||
module Rswag
|
||||
module Ui
|
||||
VERSION = '1.0.0'
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user