rspec-openapi 0.18.1 → 0.18.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rspec/openapi/extractors/hanami.rb +2 -6
- data/lib/rspec/openapi/extractors/rails.rb +6 -15
- data/lib/rspec/openapi/extractors.rb +0 -7
- data/lib/rspec/openapi/version.rb +1 -1
- data/lib/rspec/openapi.rb +31 -21
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 39da96c0f0b1650e0504d45a624be7905c9f47a2b128e992eecb5b05b828dd87
|
4
|
+
data.tar.gz: 5c6cb0fdaf3900ae93d0618c82b6762c8cf50002e7ac155c23a46b543f91d126
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df87ce7e2b08623ec314330020d011ede771872a435f11b266be1f1c1a2e24c8329559b1f3e42b50a58a86c442c0afed2e98444694138823b9b17ebb94e54878
|
7
|
+
data.tar.gz: c89fb952a0d8fbc4c5ed814bd11513d2323f2c5237ad0a7b0e341e2522c329a331230b51ecab3bcf42a60dd4e5da090a337202dac37db3d4f68ab82ad7a9f91b
|
@@ -52,7 +52,7 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new
|
|
52
52
|
# @param [RSpec::Core::Example] example
|
53
53
|
# @return Array
|
54
54
|
def request_attributes(request, example)
|
55
|
-
route = Hanami.app.router.recognize(request.path, method: request.method)
|
55
|
+
route = Hanami.app.router.recognize(Rack::MockRequest.env_for(request.path, method: request.method))
|
56
56
|
|
57
57
|
return RSpec::OpenAPI::Extractors::Rack.request_attributes(request, example) unless route.routable?
|
58
58
|
|
@@ -66,7 +66,7 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new
|
|
66
66
|
deprecated = metadata[:deprecated]
|
67
67
|
path = request.path
|
68
68
|
|
69
|
-
raw_path_params = route.params
|
69
|
+
raw_path_params = route.params
|
70
70
|
|
71
71
|
result = InspectorAnalyzer.call(request.method, add_id(path, route))
|
72
72
|
|
@@ -92,8 +92,6 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new
|
|
92
92
|
return path if route.params.empty?
|
93
93
|
|
94
94
|
route.params.each_pair do |key, value|
|
95
|
-
next unless RSpec::OpenAPI::Extractors.number_or_nil(value)
|
96
|
-
|
97
95
|
path = path.sub("/#{value}", "/:#{key}")
|
98
96
|
end
|
99
97
|
|
@@ -104,8 +102,6 @@ class << RSpec::OpenAPI::Extractors::Hanami = Object.new
|
|
104
102
|
return path if route.params.empty?
|
105
103
|
|
106
104
|
route.params.each_pair do |key, value|
|
107
|
-
next unless RSpec::OpenAPI::Extractors.number_or_nil(value)
|
108
|
-
|
109
105
|
path = path.sub("/#{value}", "/{#{key}}")
|
110
106
|
end
|
111
107
|
|
@@ -44,32 +44,23 @@ class << RSpec::OpenAPI::Extractors::Rails = Object.new
|
|
44
44
|
|
45
45
|
# @param [ActionDispatch::Request] request
|
46
46
|
def find_rails_route(request, app: Rails.application, path_prefix: '')
|
47
|
-
app.routes.router.recognize(request) do |route,
|
47
|
+
app.routes.router.recognize(request) do |route, _parameters|
|
48
48
|
path = route.path.spec.to_s.delete_suffix('(.:format)')
|
49
49
|
|
50
50
|
if route.app.matches?(request)
|
51
51
|
if route.app.engine?
|
52
52
|
route, path = find_rails_route(request, app: route.app.app, path_prefix: path)
|
53
53
|
next if route.nil?
|
54
|
-
elsif path_prefix + path == add_id(request.path, parameters)
|
55
|
-
return [route, path_prefix + path]
|
56
|
-
else
|
57
|
-
return [route, nil]
|
58
54
|
end
|
55
|
+
|
56
|
+
# Params are empty when it is Engine or Rack app.
|
57
|
+
# In that case, we can't handle parameters in path.
|
58
|
+
return [route, nil] if request.params.empty?
|
59
|
+
|
59
60
|
return [route, path_prefix + path]
|
60
61
|
end
|
61
62
|
end
|
62
63
|
|
63
64
|
nil
|
64
65
|
end
|
65
|
-
|
66
|
-
def add_id(path, parameters)
|
67
|
-
parameters.each_pair do |key, value|
|
68
|
-
next unless RSpec::OpenAPI::Extractors.number_or_nil(value)
|
69
|
-
|
70
|
-
path = path.sub("/#{value}", "/:#{key}")
|
71
|
-
end
|
72
|
-
|
73
|
-
path
|
74
|
-
end
|
75
66
|
end
|
data/lib/rspec/openapi.rb
CHANGED
@@ -15,30 +15,17 @@ require 'rspec/openapi/shared_hooks'
|
|
15
15
|
require 'rspec/openapi/extractors'
|
16
16
|
require 'rspec/openapi/extractors/rack'
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
require 'hanami'
|
23
|
-
rescue LoadError
|
24
|
-
warn 'Hanami not detected' if DEBUG_ENABLED
|
25
|
-
else
|
26
|
-
require 'rspec/openapi/extractors/hanami'
|
27
|
-
end
|
18
|
+
module RSpec::OpenAPI
|
19
|
+
class Config
|
20
|
+
class << self
|
21
|
+
attr_accessor :debug_enabled
|
28
22
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
else
|
34
|
-
require 'rspec/openapi/extractors/rails'
|
23
|
+
def load_environment_settings
|
24
|
+
@debug_enabled = ['', '1', 'true'].include?(ENV['DEBUG']&.downcase)
|
25
|
+
end
|
26
|
+
end
|
35
27
|
end
|
36
|
-
end
|
37
28
|
|
38
|
-
require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
|
39
|
-
require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
|
40
|
-
|
41
|
-
module RSpec::OpenAPI
|
42
29
|
@path = 'doc/openapi.yaml'
|
43
30
|
@title = File.basename(Dir.pwd)
|
44
31
|
@comment = nil
|
@@ -84,3 +71,26 @@ module RSpec::OpenAPI
|
|
84
71
|
attr_reader :config_filename
|
85
72
|
end
|
86
73
|
end
|
74
|
+
|
75
|
+
if ENV['OPENAPI']
|
76
|
+
RSpec::OpenAPI::Config.load_environment_settings
|
77
|
+
|
78
|
+
begin
|
79
|
+
require 'hanami'
|
80
|
+
rescue LoadError
|
81
|
+
warn 'Hanami not detected' if RSpec::OpenAPI::Config.debug_enabled
|
82
|
+
else
|
83
|
+
require 'rspec/openapi/extractors/hanami'
|
84
|
+
end
|
85
|
+
|
86
|
+
begin
|
87
|
+
require 'rails'
|
88
|
+
rescue LoadError
|
89
|
+
warn 'Rails not detected' if RSpec::OpenAPI::Config.debug_enabled
|
90
|
+
else
|
91
|
+
require 'rspec/openapi/extractors/rails'
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
require 'rspec/openapi/minitest_hooks' if Object.const_defined?('Minitest')
|
96
|
+
require 'rspec/openapi/rspec_hooks' if ENV['OPENAPI'] && Object.const_defined?('RSpec')
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -109,7 +109,7 @@ licenses:
|
|
109
109
|
metadata:
|
110
110
|
homepage_uri: https://github.com/exoego/rspec-openapi
|
111
111
|
source_code_uri: https://github.com/exoego/rspec-openapi
|
112
|
-
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.18.
|
112
|
+
changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.18.3
|
113
113
|
rubygems_mfa_required: 'true'
|
114
114
|
post_install_message:
|
115
115
|
rdoc_options: []
|