mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 07:16:40 +00:00
Renames rswag-api to open_api-rswag-api
This commit is contained in:
parent
b8dcc8fe30
commit
27a7481b48
@ -1,4 +1,4 @@
|
|||||||
Rswag::Api.configure do |c|
|
OpenApi::Rswag::Api.configure do |c|
|
||||||
|
|
||||||
# Specify a root folder where Swagger JSON files are located
|
# Specify a root folder where Swagger JSON files are located
|
||||||
# This is used by the Swagger middleware to serve requests for API descriptions
|
# This is used by the Swagger middleware to serve requests for API descriptions
|
||||||
|
|||||||
19
rswag-api/lib/open_api/rswag/api.rb
Normal file
19
rswag-api/lib/open_api/rswag/api.rb
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
module OpenApi
|
||||||
|
|
||||||
|
end
|
||||||
|
require 'open_api/rswag/api/configuration'
|
||||||
|
require 'open_api/rswag/api/engine'
|
||||||
|
|
||||||
|
module OpenApi
|
||||||
|
module Rswag
|
||||||
|
module Api
|
||||||
|
def self.configure
|
||||||
|
yield(config)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.config
|
||||||
|
@config ||= Configuration.new
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,4 +1,4 @@
|
|||||||
module Rswag
|
module OpenApi::Rswag
|
||||||
module Api
|
module Api
|
||||||
class Configuration
|
class Configuration
|
||||||
attr_accessor :swagger_root, :swagger_filter
|
attr_accessor :swagger_root, :swagger_filter
|
||||||
@ -1,6 +1,6 @@
|
|||||||
require 'rswag/api/middleware'
|
require 'open_api/rswag/api/middleware'
|
||||||
|
|
||||||
module Rswag
|
module OpenApi::Rswag
|
||||||
module Api
|
module Api
|
||||||
class Engine < ::Rails::Engine
|
class Engine < ::Rails::Engine
|
||||||
isolate_namespace Rswag::Api
|
isolate_namespace Rswag::Api
|
||||||
39
rswag-api/lib/open_api/rswag/api/middleware.rb
Normal file
39
rswag-api/lib/open_api/rswag/api/middleware.rb
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
require 'json'
|
||||||
|
|
||||||
|
module OpenApi
|
||||||
|
module Rswag
|
||||||
|
module Api
|
||||||
|
class Middleware
|
||||||
|
|
||||||
|
def initialize(app, config)
|
||||||
|
@app = app
|
||||||
|
@config = config
|
||||||
|
end
|
||||||
|
|
||||||
|
def call(env)
|
||||||
|
path = env['PATH_INFO']
|
||||||
|
filename = "#{@config.resolve_swagger_root(env)}/#{path}"
|
||||||
|
|
||||||
|
if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
|
||||||
|
swagger = load_json(filename)
|
||||||
|
@config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
|
||||||
|
|
||||||
|
return [
|
||||||
|
'200',
|
||||||
|
{ 'Content-Type' => 'application/json' },
|
||||||
|
[ JSON.dump(swagger) ]
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
return @app.call(env)
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_json(filename)
|
||||||
|
JSON.parse(File.read(filename))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,14 +0,0 @@
|
|||||||
require 'rswag/api/configuration'
|
|
||||||
require 'rswag/api/engine'
|
|
||||||
|
|
||||||
module Rswag
|
|
||||||
module Api
|
|
||||||
def self.configure
|
|
||||||
yield(config)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.config
|
|
||||||
@config ||= Configuration.new
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -1,37 +0,0 @@
|
|||||||
require 'json'
|
|
||||||
|
|
||||||
module Rswag
|
|
||||||
module Api
|
|
||||||
class Middleware
|
|
||||||
|
|
||||||
def initialize(app, config)
|
|
||||||
@app = app
|
|
||||||
@config = config
|
|
||||||
end
|
|
||||||
|
|
||||||
def call(env)
|
|
||||||
path = env['PATH_INFO']
|
|
||||||
filename = "#{@config.resolve_swagger_root(env)}/#{path}"
|
|
||||||
|
|
||||||
if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
|
|
||||||
swagger = load_json(filename)
|
|
||||||
@config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
|
|
||||||
|
|
||||||
return [
|
|
||||||
'200',
|
|
||||||
{ 'Content-Type' => 'application/json' },
|
|
||||||
[ JSON.dump(swagger) ]
|
|
||||||
]
|
|
||||||
end
|
|
||||||
|
|
||||||
return @app.call(env)
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def load_json(filename)
|
|
||||||
JSON.parse(File.read(filename))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -2,9 +2,9 @@ $:.push File.expand_path("../lib", __FILE__)
|
|||||||
|
|
||||||
# Describe your gem and declare its dependencies:
|
# Describe your gem and declare its dependencies:
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.name = "rswag-api"
|
s.name = "open_api-rswag-api"
|
||||||
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
s.version = ENV['TRAVIS_TAG'] || '0.0.0'
|
||||||
s.authors = ["Richie Morris"]
|
s.authors = ["Richie Morris", "Jay Danielian"]
|
||||||
s.email = ["domaindrivendev@gmail.com"]
|
s.email = ["domaindrivendev@gmail.com"]
|
||||||
s.homepage = "https://github.com/domaindrivendev/rswag"
|
s.homepage = "https://github.com/domaindrivendev/rswag"
|
||||||
s.summary = "A Rails Engine that exposes Swagger files as JSON endpoints"
|
s.summary = "A Rails Engine that exposes Swagger files as JSON endpoints"
|
||||||
@ -1,6 +1,7 @@
|
|||||||
require 'generator_spec'
|
require 'generator_spec'
|
||||||
require 'generators/rswag/api/install/install_generator'
|
require 'generators/rswag/api/install/install_generator'
|
||||||
|
|
||||||
|
|
||||||
module Rswag
|
module Rswag
|
||||||
module Api
|
module Api
|
||||||
|
|
||||||
@ -25,3 +26,4 @@ module Rswag
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
require 'rswag/api/middleware'
|
require 'open_api/rswag/api/middleware'
|
||||||
require 'rswag/api/configuration'
|
require 'open_api/rswag/api/configuration'
|
||||||
|
|
||||||
module Rswag
|
module OpenApi::Rswag
|
||||||
module Api
|
module Api
|
||||||
|
|
||||||
describe Middleware do
|
describe Middleware do
|
||||||
Loading…
Reference in New Issue
Block a user