rswagger-api 2.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eda08b3c20283275f151dc819f46ea5468d5c0b2a409a24839a06d26eff57213
4
+ data.tar.gz: 4e91770769de822f4a2406f5fa7cf37ac53c271c8c5d4e27acb5f115e9bcc58f
5
+ SHA512:
6
+ metadata.gz: 3d3c325c2365a4dd0a3787cfe4afc2031ff8ad5d171a54a5b71223706aa77de82464e1eea63dad3ef015a9fa7fc7fcd2526857740b040c0fb77fdc83832a4e6a
7
+ data.tar.gz: 46196380d55656f14fcd2ac3f27c87563925437e1b57de587be604815e480197edb97b10e7de3614b2b4575f8ce2d01bebf0871979c8308d8c236c0d77bb881f
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 domaindrivendev
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'rswag-specs'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Adds rswag-api initializer for configuration
3
+
4
+ Example:
5
+ rails generate rswag:api:install
6
+
7
+ This will create:
8
+ config/initializers/rswag-api.rb
@@ -0,0 +1,18 @@
1
+ require 'rails/generators'
2
+
3
+ module Rswag
4
+ module Api
5
+
6
+ class InstallGenerator < Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ def add_initializer
10
+ template('rswag-api.rb', 'config/initializers/rswag-api.rb')
11
+ end
12
+
13
+ def add_routes
14
+ route("mount Rswag::Api::Engine => '/api-docs'")
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ Rswag::Api.configure do |c|
2
+
3
+ # Specify a root folder where Swagger JSON files are located
4
+ # This is used by the Swagger middleware to serve requests for API descriptions
5
+ # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
6
+ # that it's configured to generate files in the same folder
7
+ c.swagger_root = Rails.root.to_s + '/swagger'
8
+
9
+ # Inject a lamda function to alter the returned Swagger prior to serialization
10
+ # The function will have access to the rack env for the current request
11
+ # For example, you could leverage this to dynamically assign the "host" property
12
+ #
13
+ #c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
14
+ end
@@ -0,0 +1,12 @@
1
+ module Rswag
2
+ module Api
3
+ class Configuration
4
+ attr_accessor :swagger_root, :swagger_filter
5
+
6
+ def resolve_swagger_root(env)
7
+ path_params = env['action_dispatch.request.path_parameters'] || {}
8
+ path_params[:swagger_root] || swagger_root
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,13 @@
1
+ require 'rswag/api/middleware'
2
+
3
+ module Rswag
4
+ module Api
5
+ class Engine < ::Rails::Engine
6
+ isolate_namespace Rswag::Api
7
+
8
+ initializer 'rswag-api.initialize' do |app|
9
+ middleware.use Rswag::Api::Middleware, Rswag::Api.config
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ require 'json'
2
+
3
+ module Rswag
4
+ module Api
5
+ class Middleware
6
+
7
+ def initialize(app, config)
8
+ @app = app
9
+ @config = config
10
+ end
11
+
12
+ def call(env)
13
+ path = env['PATH_INFO']
14
+ filename = "#{@config.resolve_swagger_root(env)}/#{path}"
15
+
16
+ if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
17
+ swagger = load_json(filename)
18
+ @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
19
+
20
+ return [
21
+ '200',
22
+ { 'Content-Type' => 'application/json' },
23
+ [ JSON.dump(swagger) ]
24
+ ]
25
+ end
26
+
27
+ return @app.call(env)
28
+ end
29
+
30
+ private
31
+
32
+ def load_json(filename)
33
+ JSON.parse(File.read(filename))
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/rswag/api.rb ADDED
@@ -0,0 +1,14 @@
1
+ require 'rswag/api/configuration'
2
+ require 'rswag/api/engine'
3
+
4
+ module Rswag
5
+ module Api
6
+ def self.configure
7
+ yield(config)
8
+ end
9
+
10
+ def self.config
11
+ @config ||= Configuration.new
12
+ end
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rswagger-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.6
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Yarikov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ description: Open up your API to the phenomenal Swagger ecosystem by exposing Swagger
28
+ files, that describe your service, as JSON endpoints
29
+ email:
30
+ - dmitry@yarikov.com
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - MIT-LICENSE
36
+ - Rakefile
37
+ - lib/generators/rswag/api/install/USAGE
38
+ - lib/generators/rswag/api/install/install_generator.rb
39
+ - lib/generators/rswag/api/install/templates/rswag-api.rb
40
+ - lib/rswag/api.rb
41
+ - lib/rswag/api/configuration.rb
42
+ - lib/rswag/api/engine.rb
43
+ - lib/rswag/api/middleware.rb
44
+ homepage: https://github.com/yarikov/rswag
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubygems_version: 3.0.4
64
+ signing_key:
65
+ specification_version: 4
66
+ summary: A Rails Engine that exposes Swagger files as JSON endpoints
67
+ test_files: []