rswag-api-2.1 2.9.1.ruby21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aaa5f6059e1dbb4d5e49f85e05068f7d4e215cfce6e74eaa44e86a856cdae705
4
+ data.tar.gz: c572a7e21aa7d04425243f25c8ee0c79e544cd8b5862fc96d813c94ecda83b7f
5
+ SHA512:
6
+ metadata.gz: 969d0c04143d8f3f0f4b39fd0c097b863f7b35512e6c82b5f042958d0ca320c3ce7aca8d497c6162a21d24649df8f6ad5d469c661d9b94b183daa2e437851ab4
7
+ data.tar.gz: 56f5451997de89df2370037efc8a156b86b0d86190bba1df42b74742a2cc84a554a7d0f7768b1c317c9a89a6ed0bbacb31f52c88035d57da2e60656ea9c782dd
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 lambda 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, :swagger_headers
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,62 @@
1
+ require 'json'
2
+ require 'yaml'
3
+ require 'rack/mime'
4
+
5
+ module Rswag
6
+ module Api
7
+ class Middleware
8
+
9
+ def initialize(app, config)
10
+ @app = app
11
+ @config = config
12
+ end
13
+
14
+ def call(env)
15
+ path = env['PATH_INFO']
16
+ filename = "#{@config.resolve_swagger_root(env)}/#{path}"
17
+
18
+ if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
19
+ swagger = parse_file(filename)
20
+ @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
21
+ mime = Rack::Mime.mime_type(::File.extname(path), 'text/plain')
22
+ headers = { 'Content-Type' => mime }.merge(@config.swagger_headers || {})
23
+ body = unload_swagger(filename, swagger)
24
+
25
+ return [
26
+ '200',
27
+ headers,
28
+ [ body ]
29
+ ]
30
+ end
31
+
32
+ return @app.call(env)
33
+ end
34
+
35
+ private
36
+
37
+ def parse_file(filename)
38
+ if /\.ya?ml$/ === filename
39
+ load_yaml(filename)
40
+ else
41
+ load_json(filename)
42
+ end
43
+ end
44
+
45
+ def load_yaml(filename)
46
+ YAML.safe_load(File.read(filename))
47
+ end
48
+
49
+ def load_json(filename)
50
+ JSON.parse(File.read(filename))
51
+ end
52
+
53
+ def unload_swagger(filename, swagger)
54
+ if /\.ya?ml$/ === filename
55
+ YAML.dump(swagger)
56
+ else
57
+ JSON.dump(swagger)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ 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,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rswag-api-2.1
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.9.1.ruby21
5
+ platform: ruby
6
+ authors:
7
+ - Richie Morris
8
+ - Greg Myers
9
+ - Jay Danielian
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2026-06-07 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: railties
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '3.1'
22
+ - - "<"
23
+ - !ruby/object:Gem::Version
24
+ version: '7.1'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - ">="
30
+ - !ruby/object:Gem::Version
31
+ version: '3.1'
32
+ - - "<"
33
+ - !ruby/object:Gem::Version
34
+ version: '7.1'
35
+ - !ruby/object:Gem::Dependency
36
+ name: simplecov
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 0.21.2
42
+ type: :development
43
+ prerelease: false
44
+ version_requirements: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '='
47
+ - !ruby/object:Gem::Version
48
+ version: 0.21.2
49
+ description: 'Open up your API to the phenomenal OpenAPI ecosystem by exposing OpenAPI
50
+ files, that describe your service, as JSON endpoints. More about the OpenAPI initiative
51
+ here: http://spec.openapis.org/'
52
+ email:
53
+ - domaindrivendev@gmail.com
54
+ executables: []
55
+ extensions: []
56
+ extra_rdoc_files: []
57
+ files:
58
+ - MIT-LICENSE
59
+ - Rakefile
60
+ - lib/generators/rswag/api/install/USAGE
61
+ - lib/generators/rswag/api/install/install_generator.rb
62
+ - lib/generators/rswag/api/install/templates/rswag_api.rb
63
+ - lib/rswag/api.rb
64
+ - lib/rswag/api/configuration.rb
65
+ - lib/rswag/api/engine.rb
66
+ - lib/rswag/api/middleware.rb
67
+ homepage: https://github.com/rswag/rswag
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">"
83
+ - !ruby/object:Gem::Version
84
+ version: 1.3.1
85
+ requirements: []
86
+ rubygems_version: 3.3.27
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: A Rails Engine that exposes OpenAPI (formerly called Swagger) files as JSON
90
+ endpoints
91
+ test_files: []