mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-23 06:16:42 +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
|
||||
# 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
|
||||
class Configuration
|
||||
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
|
||||
class Engine < ::Rails::Engine
|
||||
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:
|
||||
Gem::Specification.new do |s|
|
||||
s.name = "rswag-api"
|
||||
s.name = "open_api-rswag-api"
|
||||
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.summary = "A Rails Engine that exposes Swagger files as JSON endpoints"
|
||||
@ -1,6 +1,7 @@
|
||||
require 'generator_spec'
|
||||
require 'generators/rswag/api/install/install_generator'
|
||||
|
||||
|
||||
module Rswag
|
||||
module Api
|
||||
|
||||
@ -25,3 +26,4 @@ module Rswag
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
require 'rswag/api/middleware'
|
||||
require 'rswag/api/configuration'
|
||||
require 'open_api/rswag/api/middleware'
|
||||
require 'open_api/rswag/api/configuration'
|
||||
|
||||
module Rswag
|
||||
module OpenApi::Rswag
|
||||
module Api
|
||||
|
||||
describe Middleware do
|
||||
Loading…
Reference in New Issue
Block a user