rswag-api 2.12.0 → 2.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bd09d4d8032f40d131905519035e07f94986f31505d4f7a79c376d265c538dd
4
- data.tar.gz: 00e354141c50226d38b93bcb518ca30220bdd15cbf7e09685008e10855ea1124
3
+ metadata.gz: 2e80990b064d9bad51bb3eb217987dba1400c5f0b1ec68d903a6f34229f049d6
4
+ data.tar.gz: eb379a7fa481b8b623d4880d1f9fa9b77531b7b21f766a825ee7c21a4a36daf8
5
5
  SHA512:
6
- metadata.gz: d02f3d0259e5d80dd9be65a615b845391ba60aefb617ccffbe66d286cb93563030b7a28a45d0b89025f21fffc78c04de43bf07291565f34fcffb968af7ad3ee0
7
- data.tar.gz: 15fe7a1954145ce237113f03ca6c25a64fd486103a15e9ef8a9c6385655395e12d0424d89b19a169212c062a6a835307524cc292d436f926d76ab9983478289d
6
+ metadata.gz: f63243aa5dbb57b92d781f453e4860ca777765f2fdb76a63dee8e4076c9619fa36350ebeb472fb2108528fcd2164c939a67bc109fe55178011b2741b350b5417
7
+ data.tar.gz: e30f6dee44a3bb6145684fa82d7166c3b023b6a5b262b094670dce637652bb2893012df420a21eaa5857a79657aaef3cbc189dcfd9d35bed41660b6bfeb8b4d9
@@ -4,7 +4,7 @@ Rswag::Api.configure do |c|
4
4
  # This is used by the Swagger middleware to serve requests for API descriptions
5
5
  # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
6
6
  # that it's configured to generate files in the same folder
7
- c.swagger_root = Rails.root.to_s + '/swagger'
7
+ c.openapi_root = Rails.root.to_s + '/swagger'
8
8
 
9
9
  # Inject a lambda function to alter the returned Swagger prior to serialization
10
10
  # The function will have access to the rack env for the current request
@@ -1,11 +1,19 @@
1
1
  module Rswag
2
2
  module Api
3
3
  class Configuration
4
- attr_accessor :swagger_root, :swagger_filter, :swagger_headers
4
+ attr_accessor :openapi_root, :swagger_filter, :swagger_headers
5
5
 
6
- def resolve_swagger_root(env)
6
+ def resolve_openapi_root(env)
7
7
  path_params = env['action_dispatch.request.path_parameters'] || {}
8
- path_params[:swagger_root] || swagger_root
8
+
9
+ if path_params.key?(:swagger_root)
10
+ Rswag::Api.deprecator.warn(
11
+ 'swagger_root is deprecated and will be removed from rswag-api 3.0 (use openapi_root instead)'
12
+ )
13
+ return path_params[:swagger_root]
14
+ end
15
+
16
+ path_params[:openapi_root] || openapi_root
9
17
  end
10
18
  end
11
19
  end
@@ -5,7 +5,6 @@ require 'rack/mime'
5
5
  module Rswag
6
6
  module Api
7
7
  class Middleware
8
-
9
8
  def initialize(app, config)
10
9
  @app = app
11
10
  @config = config
@@ -15,10 +14,9 @@ module Rswag
15
14
  path = env['PATH_INFO']
16
15
  # Sanitize the filename for directory traversal by expanding, and ensuring
17
16
  # its starts with the root directory.
18
- filename = File.expand_path(File.join(@config.resolve_swagger_root(env), path))
19
- unless filename.start_with? @config.resolve_swagger_root(env).to_s
20
- return @app.call(env)
21
- end
17
+ openapi_root = @config.resolve_openapi_root(env)
18
+ filename = File.expand_path(File.join(openapi_root, path))
19
+ return @app.call(env) unless filename.start_with? openapi_root.to_s
22
20
 
23
21
  if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
24
22
  swagger = parse_file(filename)
@@ -30,11 +28,11 @@ module Rswag
30
28
  return [
31
29
  '200',
32
30
  headers,
33
- [ body ]
31
+ [body]
34
32
  ]
35
33
  end
36
34
 
37
- return @app.call(env)
35
+ @app.call(env)
38
36
  end
39
37
 
40
38
  private
data/lib/rswag/api.rb CHANGED
@@ -1,8 +1,14 @@
1
+ require 'active_support/deprecation'
1
2
  require 'rswag/api/configuration'
2
- require 'rswag/api/engine'
3
+ require 'rswag/api/engine' if defined?(Rails::Engine)
3
4
 
4
5
  module Rswag
5
6
  module Api
7
+ RENAMED_METHODS = {
8
+ swagger_root: :openapi_root
9
+ }.freeze
10
+ private_constant :RENAMED_METHODS
11
+
6
12
  def self.configure
7
13
  yield(config)
8
14
  end
@@ -10,5 +16,22 @@ module Rswag
10
16
  def self.config
11
17
  @config ||= Configuration.new
12
18
  end
19
+
20
+ def self.deprecator
21
+ @deprecator ||= ActiveSupport::Deprecation.new('3.0', 'rswag-api')
22
+ end
23
+
24
+ Configuration.class_eval do
25
+ RENAMED_METHODS.each do |old_name, new_name|
26
+ define_method("#{old_name}=") do |*args, &block|
27
+ public_send("#{new_name}=", *args, &block)
28
+ end
29
+ end
30
+ end
31
+
32
+ Api.deprecator.deprecate_methods(
33
+ Configuration,
34
+ RENAMED_METHODS.to_h { |old_name, new_name| ["#{old_name}=".to_sym, "#{new_name}=".to_sym] }
35
+ )
13
36
  end
14
37
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rswag-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.12.0
4
+ version: 2.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richie Morris
@@ -10,8 +10,28 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-11-25 00:00:00.000000000 Z
13
+ date: 2023-11-29 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: activesupport
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.2'
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.2'
15
35
  - !ruby/object:Gem::Dependency
16
36
  name: railties
17
37
  requirement: !ruby/object:Gem::Requirement