rspec-openapi 0.4.2 → 0.4.5
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 +4 -4
- data/CHANGELOG.md +15 -0
- data/README.md +16 -0
- data/lib/rspec/openapi/record_builder.rb +7 -5
- data/lib/rspec/openapi/schema_merger.rb +8 -4
- data/lib/rspec/openapi/version.rb +1 -1
- 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: f962e8e048c5a935842a4d45896ead010b7e8bf0568161f8b9dddadd17b6c751
|
4
|
+
data.tar.gz: c4d0098e4f6a8c4d3a747b9045897627621085cf5c995d4129b099293dc99bdb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37626fc7ba17753cc589d76e68c1cafb2cb84039873985ca702b6439448303f62bb7527257aea1128db3b4bbd53cdd12f909c8a5aa40c9feccc2ab00ba27e16e
|
7
|
+
data.tar.gz: 2dacbbf2be2111fe1a80a8482e885b07b56a8e09f78b002d5b5e1ba15d7d109e02ee81f29ecc50ebbb7c6bd1a24c080e62d05e98d34f67cbb7120e1e3578c55f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
## v0.4.5
|
2
|
+
|
3
|
+
- Fix linter issues for `tags` and `summary`
|
4
|
+
[#40](https://github.com/k0kubun/rspec-openapi/pull/40)
|
5
|
+
|
6
|
+
## v0.4.4
|
7
|
+
|
8
|
+
- De-duplicate parameters by a combination of `name` and `in`
|
9
|
+
[#39](https://github.com/k0kubun/rspec-openapi/pull/39)
|
10
|
+
|
11
|
+
## v0.4.3
|
12
|
+
|
13
|
+
* Allow customizing `schema`, `description`, and `tags` through `:openapi` metadata
|
14
|
+
[#36](https://github.com/k0kubun/rspec-openapi/pull/36)
|
15
|
+
|
1
16
|
## v0.4.2
|
2
17
|
|
3
18
|
* Allow using Proc as `RSpec::OpenAPI.path`
|
data/README.md
CHANGED
@@ -172,6 +172,22 @@ RSpec.describe '/resources', type: :request do
|
|
172
172
|
end
|
173
173
|
```
|
174
174
|
|
175
|
+
## Customizations
|
176
|
+
|
177
|
+
Some examples' attributes can be overwritten via RSpec metadata options. Example:
|
178
|
+
|
179
|
+
```rb
|
180
|
+
describe 'GET /api/v1/posts', openapi: {
|
181
|
+
summary: 'list all posts',
|
182
|
+
description: 'list all posts ordered by pub_date',
|
183
|
+
tags: %w[v1 posts],
|
184
|
+
} do
|
185
|
+
# ...
|
186
|
+
end
|
187
|
+
```
|
188
|
+
|
189
|
+
**NOTE**: `description` key will override also the one provided by `RSpec::OpenAPI.description_builder` method.
|
190
|
+
|
175
191
|
## Links
|
176
192
|
|
177
193
|
Existing RSpec plugins which have OpenAPI integration:
|
@@ -20,8 +20,8 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
20
20
|
if rails?
|
21
21
|
route = find_rails_route(request)
|
22
22
|
path = route.path.spec.to_s.delete_suffix('(.:format)')
|
23
|
-
summary =
|
24
|
-
tags = [route.requirements[:controller]
|
23
|
+
summary = route.requirements[:action] || "#{request.method} #{path}"
|
24
|
+
tags = [route.requirements[:controller]&.classify].compact
|
25
25
|
else
|
26
26
|
path = request.path
|
27
27
|
summary = "#{request.method} #{request.path}"
|
@@ -40,6 +40,8 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
40
40
|
headers_arr << [header, header_value] if header_value
|
41
41
|
end
|
42
42
|
|
43
|
+
metadata_options = example.metadata[:openapi] || {}
|
44
|
+
|
43
45
|
RSpec::OpenAPI::Record.new(
|
44
46
|
method: request.request_method,
|
45
47
|
path: path,
|
@@ -48,9 +50,9 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
48
50
|
request_params: raw_request_params(request),
|
49
51
|
request_content_type: request.media_type,
|
50
52
|
request_headers: request_headers,
|
51
|
-
summary: summary,
|
52
|
-
tags: tags,
|
53
|
-
description: RSpec::OpenAPI.description_builder.call(example),
|
53
|
+
summary: metadata_options[:summary] || summary,
|
54
|
+
tags: metadata_options[:tags] || tags,
|
55
|
+
description: metadata_options[:description] || RSpec::OpenAPI.description_builder.call(example),
|
54
56
|
status: response.status,
|
55
57
|
response_body: response_body,
|
56
58
|
response_content_type: response.media_type,
|
@@ -21,9 +21,12 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
# Not doing `base.replace(deep_merge(base, spec))` to preserve key orders
|
24
|
+
# Not doing `base.replace(deep_merge(base, spec))` to preserve key orders.
|
25
|
+
# Also this needs to be aware of OpenAPI details unlike an ordinary deep_reverse_merge
|
26
|
+
# because a Hash-like structure may be an array whose Hash elements have a key name.
|
27
|
+
#
|
25
28
|
# TODO: Perform more intelligent merges like rerouting edits / merging types
|
26
|
-
# Should we probably force-merge `summary` regardless of manual modifications?
|
29
|
+
# TODO: Should we probably force-merge `summary` regardless of manual modifications?
|
27
30
|
def deep_reverse_merge!(base, spec)
|
28
31
|
spec.each do |key, value|
|
29
32
|
if base[key].is_a?(Hash) && value.is_a?(Hash)
|
@@ -31,9 +34,10 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
|
|
31
34
|
elsif !base.key?(key)
|
32
35
|
base[key] = value
|
33
36
|
elsif base[key].is_a?(Array) && value.is_a?(Array)
|
34
|
-
if
|
35
|
-
|
37
|
+
# parameters need to be merged as if `name` and `in` were the Hash keys.
|
38
|
+
if key == 'parameters'
|
36
39
|
base[key] |= value
|
40
|
+
base[key].uniq! { |param| param.slice('name', 'in') }
|
37
41
|
end
|
38
42
|
else
|
39
43
|
# no-op
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-openapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-03-
|
11
|
+
date: 2022-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
- !ruby/object:Gem::Version
|
91
91
|
version: '0'
|
92
92
|
requirements: []
|
93
|
-
rubygems_version: 3.
|
93
|
+
rubygems_version: 3.3.7
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Generate OpenAPI schema from RSpec request specs
|