rswag-api 2.16.0 → 3.0.0.pre

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bc04cec019aea5f72349e2a5e7649d0bd463273bed1fb7e401253ddd250c575c
4
- data.tar.gz: a2292a7ffe820a8d47e18aa9dc1fff5ff9e8a319717f1096d6454be959ebf753
3
+ metadata.gz: 873e326e03b226aa5320861a43304f91adbd4cc8f9fb6fd03202b88199a8e981
4
+ data.tar.gz: cf45620fc8bf24785a6c9e0c7d0ba86238b5f0f6a5cdd999a013303b99202cce
5
5
  SHA512:
6
- metadata.gz: e9bcacb5d5f71054e7e0ad28765500c4a030dddca24854cccfd705e8f6bdcab6e35e5d386e9f5d73ba66da888def57e7654663bd3a74af014b9a0b9f82f7aa90
7
- data.tar.gz: 994751ed8609db4f71deede9e60770b226505e0414d44abaf702af3bbcd80e6cc916df5f5587cf0c51b26c4c0b07db24d67e009cce2b803d96f775ec4d1600e9
6
+ metadata.gz: 62b95022d5dbf14b01671db89c0cf0fc6ee2881bbf6fdd767bde4b60331ec24cf1cec0291bad0cd7f043aeb3854554e55de7488942856be17944c9ea5acb174d
7
+ data.tar.gz: de08556aaca450a7139c91e7ee3bed9687ea3b771179a5f129aae179f39add97f4be179bb79dc38badc72965f9879bcce243d4985941fe586e08bce673e5926d
data/Rakefile CHANGED
@@ -1,4 +1,6 @@
1
1
  #!/usr/bin/env rake
2
+ # frozen_string_literal: true
3
+
2
4
  begin
3
5
  require 'bundler/setup'
4
6
  rescue LoadError
@@ -20,8 +22,4 @@ RDoc::Task.new(:rdoc) do |rdoc|
20
22
  rdoc.rdoc_files.include('lib/**/*.rb')
21
23
  end
22
24
 
23
-
24
-
25
-
26
25
  Bundler::GemHelper.install_tasks
27
-
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails/generators'
2
4
 
3
5
  module Rswag
4
6
  module Api
5
-
6
7
  class InstallGenerator < Rails::Generators::Base
7
- source_root File.expand_path('../templates', __FILE__)
8
+ source_root File.expand_path('templates', __dir__)
8
9
 
9
10
  def add_initializer
10
11
  template('rswag_api.rb', 'config/initializers/rswag_api.rb')
@@ -1,14 +1,15 @@
1
- Rswag::Api.configure do |c|
1
+ # frozen_string_literal: true
2
2
 
3
+ Rswag::Api.configure do |c|
3
4
  # Specify a root folder where Swagger JSON files are located
4
5
  # This is used by the Swagger middleware to serve requests for API descriptions
5
6
  # NOTE: If you're using rswag-specs to generate Swagger, you'll need to ensure
6
7
  # that it's configured to generate files in the same folder
7
- c.openapi_root = Rails.root.to_s + '/swagger'
8
+ c.openapi_root = Rails.root.join('openapi').to_s
8
9
 
9
- # Inject a lambda function to alter the returned Swagger prior to serialization
10
+ # Inject a lambda function to alter the returned OpenAPI prior to serialization
10
11
  # The function will have access to the rack env for the current request
11
12
  # For example, you could leverage this to dynamically assign the "host" property
12
13
  #
13
- #c.swagger_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
14
+ # c.openapi_filter = lambda { |swagger, env| swagger['host'] = env['HTTP_HOST'] }
14
15
  end
@@ -1,18 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Rswag
2
4
  module Api
3
5
  class Configuration
4
- attr_accessor :openapi_root, :swagger_filter, :swagger_headers
6
+ attr_accessor :openapi_root, :openapi_filter, :openapi_headers
5
7
 
6
8
  def resolve_openapi_root(env)
7
9
  path_params = env['action_dispatch.request.path_parameters'] || {}
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
10
  path_params[:openapi_root] || openapi_root
17
11
  end
18
12
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rswag/api/middleware'
2
4
 
3
5
  module Rswag
@@ -5,7 +7,7 @@ module Rswag
5
7
  class Engine < ::Rails::Engine
6
8
  isolate_namespace Rswag::Api
7
9
 
8
- initializer 'rswag-api.initialize' do |app|
10
+ initializer 'rswag-api.initialize' do |_app|
9
11
  middleware.use Rswag::Api::Middleware, Rswag::Api.config
10
12
  end
11
13
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'json'
2
4
  require 'yaml'
3
5
  require 'rack/mime'
@@ -19,11 +21,11 @@ module Rswag
19
21
  return @app.call(env) unless filename.start_with? openapi_root.to_s
20
22
 
21
23
  if env['REQUEST_METHOD'] == 'GET' && File.file?(filename)
22
- swagger = parse_file(filename)
23
- @config.swagger_filter.call(swagger, env) unless @config.swagger_filter.nil?
24
+ openapi = parse_file(filename)
25
+ @config.openapi_filter.call(openapi, env) unless @config.openapi_filter.nil?
24
26
  mime = Rack::Mime.mime_type(::File.extname(path), 'text/plain')
25
- headers = { 'Content-Type' => mime }.merge(@config.swagger_headers || {})
26
- body = unload_swagger(filename, swagger)
27
+ headers = { 'Content-Type' => mime }.merge(@config.openapi_headers || {})
28
+ body = unload_openapi(filename, openapi)
27
29
 
28
30
  return [
29
31
  '200',
@@ -38,7 +40,7 @@ module Rswag
38
40
  private
39
41
 
40
42
  def parse_file(filename)
41
- if /\.ya?ml$/ === filename
43
+ if /\.ya?ml$/.match?(filename)
42
44
  load_yaml(filename)
43
45
  else
44
46
  load_json(filename)
@@ -53,11 +55,11 @@ module Rswag
53
55
  JSON.parse(File.read(filename))
54
56
  end
55
57
 
56
- def unload_swagger(filename, swagger)
57
- if /\.ya?ml$/ === filename
58
- YAML.dump(swagger)
58
+ def unload_openapi(filename, openapi)
59
+ if /\.ya?ml$/.match?(filename)
60
+ YAML.dump(openapi)
59
61
  else
60
- JSON.dump(swagger)
62
+ JSON.dump(openapi)
61
63
  end
62
64
  end
63
65
  end
data/lib/rswag/api.rb CHANGED
@@ -1,14 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/deprecation'
2
4
  require 'rswag/api/configuration'
3
5
  require 'rswag/api/engine' if defined?(Rails::Engine)
4
6
 
5
7
  module Rswag
6
8
  module Api
7
- RENAMED_METHODS = {
8
- swagger_root: :openapi_root
9
- }.freeze
10
- private_constant :RENAMED_METHODS
11
-
12
9
  def self.configure
13
10
  yield(config)
14
11
  end
@@ -16,22 +13,5 @@ module Rswag
16
13
  def self.config
17
14
  @config ||= Configuration.new
18
15
  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
- )
36
16
  end
37
17
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rswag-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.16.0
4
+ version: 3.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richie Morris
8
8
  - Greg Myers
9
9
  - Jay Danielian
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-11-13 00:00:00.000000000 Z
13
+ date: 2025-08-01 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -66,9 +66,10 @@ dependencies:
66
66
  - - '='
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.21.2
69
- description: 'Open up your API to the phenomenal OpenAPI ecosystem by exposing OpenAPI
70
- files, that describe your service, as JSON endpoints. More about the OpenAPI initiative
71
- here: http://spec.openapis.org/'
69
+ description: |
70
+ Open up your API to the phenomenal OpenAPI ecosystem by exposing OpenAPI files,
71
+ that describe your service, as JSON endpoints.
72
+ More about the OpenAPI initiative here: http://spec.openapis.org/
72
73
  email:
73
74
  - domaindrivendev@gmail.com
74
75
  executables: []
@@ -88,7 +89,7 @@ homepage: https://github.com/rswag/rswag
88
89
  licenses:
89
90
  - MIT
90
91
  metadata: {}
91
- post_install_message:
92
+ post_install_message:
92
93
  rdoc_options: []
93
94
  require_paths:
94
95
  - lib
@@ -104,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
105
  version: '0'
105
106
  requirements: []
106
107
  rubygems_version: 3.5.11
107
- signing_key:
108
+ signing_key:
108
109
  specification_version: 4
109
110
  summary: A Rails Engine that exposes OpenAPI (formerly called Swagger) files as JSON
110
111
  endpoints