rspec-openapi 0.3.11 → 0.3.16
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/.github/FUNDING.yml +1 -0
- data/CHANGELOG.md +27 -0
- data/lib/rspec/openapi/hooks.rb +16 -1
- data/lib/rspec/openapi/record.rb +1 -0
- data/lib/rspec/openapi/record_builder.rb +5 -2
- data/lib/rspec/openapi/schema_builder.rb +19 -6
- data/lib/rspec/openapi/version.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 799f75b4bb5607dff7ab4a556b5d27d72b587af88636e7b510533724a1ede97a
|
4
|
+
data.tar.gz: 71aedf1e1610f23106dd778a2b9d9f4677c73c280127ff61300afa024068bef8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e65865ca2d26e66f6fa560fe3fc157a491786ba7243d267dcdd4f22e3e5c28c29895384a32b8b19c095317a0447453ad292bfe91ff4059395f8ee08f0763f738
|
7
|
+
data.tar.gz: fda7f3678e952359a356069353d0756890edd7da50e4cd422489db091f9223439e1385d7939f27bd55d4c4afc7e6760bd55805275f932345273e6d5528a2b036
|
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: k0kubun
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,30 @@
|
|
1
|
+
## v0.3.16
|
2
|
+
|
3
|
+
* Use `media_type` instead of `content_type` for Rails 6.1
|
4
|
+
[#26](https://github.com/k0kubun/rspec-openapi/pull/26)
|
5
|
+
* Avoid crashing the after suite hook when it fails to build schema
|
6
|
+
[#27](https://github.com/k0kubun/rspec-openapi/pull/27)
|
7
|
+
|
8
|
+
## v0.3.15
|
9
|
+
|
10
|
+
* Fix an error when Content-Disposition header is inline
|
11
|
+
[#24](https://github.com/k0kubun/rspec-openapi/pull/24)
|
12
|
+
|
13
|
+
## v0.3.14
|
14
|
+
|
15
|
+
* Avoid an error when an application calls `request.body.read`
|
16
|
+
[#20](https://github.com/k0kubun/rspec-openapi/pull/20)
|
17
|
+
|
18
|
+
## v0.3.13
|
19
|
+
|
20
|
+
* Avoid crashing when there's no request made in a spec
|
21
|
+
[#19](https://github.com/k0kubun/rspec-openapi/pull/19)
|
22
|
+
|
23
|
+
## v0.3.12
|
24
|
+
|
25
|
+
* Generate `nullable: true` for null fields in schema
|
26
|
+
[#18](https://github.com/k0kubun/rspec-openapi/pull/18)
|
27
|
+
|
1
28
|
## v0.3.11
|
2
29
|
|
3
30
|
* Show a filename as an `example` for `ActionDispatch::Http::UploadedFile`
|
data/lib/rspec/openapi/hooks.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rspec/openapi/schema_file'
|
|
6
6
|
require 'rspec/openapi/schema_merger'
|
7
7
|
|
8
8
|
records = []
|
9
|
+
records_errors = []
|
9
10
|
|
10
11
|
RSpec.configuration.after(:each) do |example|
|
11
12
|
if example.metadata[:type] == :request && example.metadata[:openapi] != false
|
@@ -19,7 +20,21 @@ RSpec.configuration.after(:suite) do
|
|
19
20
|
RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec|
|
20
21
|
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
|
21
22
|
records.each do |record|
|
22
|
-
|
23
|
+
begin
|
24
|
+
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
|
25
|
+
rescue => e # e.g. SchemaBuilder raises a NotImplementedError
|
26
|
+
# NOTE: Don't fail the build
|
27
|
+
records_errors << [e, record]
|
28
|
+
end
|
23
29
|
end
|
24
30
|
end
|
31
|
+
if records_errors.any?
|
32
|
+
error_message = <<~EOS
|
33
|
+
RSpec::OpenAPI got errors building #{records_errors.size} requests
|
34
|
+
|
35
|
+
#{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
|
36
|
+
EOS
|
37
|
+
colorizer = ::RSpec::Core::Formatters::ConsoleCodes
|
38
|
+
RSpec.configuration.reporter.message colorizer.wrap(error_message, :failure)
|
39
|
+
end
|
25
40
|
end
|
data/lib/rspec/openapi/record.rb
CHANGED
@@ -11,5 +11,6 @@ RSpec::OpenAPI::Record = Struct.new(
|
|
11
11
|
:status, # @param [Integer] - 200
|
12
12
|
:response_body, # @param [Object] - {"status" => "ok"}
|
13
13
|
:response_content_type, # @param [String] - "application/json"
|
14
|
+
:response_content_disposition, # @param [String] - "inline"
|
14
15
|
keyword_init: true,
|
15
16
|
)
|
@@ -8,11 +8,13 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
8
8
|
def build(context, example:)
|
9
9
|
if rack_test?(context)
|
10
10
|
request = ActionDispatch::Request.new(context.last_request.env)
|
11
|
+
request.body.rewind if request.body.respond_to?(:rewind)
|
11
12
|
response = ActionDispatch::TestResponse.new(*context.last_response.to_a)
|
12
13
|
else
|
13
14
|
request = context.request
|
14
15
|
response = context.response
|
15
16
|
end
|
17
|
+
return if request.nil?
|
16
18
|
|
17
19
|
# Generate `path` and `summary` in a framework-friendly manner when possible
|
18
20
|
if rails?
|
@@ -38,13 +40,14 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
|
|
38
40
|
path_params: raw_path_params(request),
|
39
41
|
query_params: request.query_parameters,
|
40
42
|
request_params: raw_request_params(request),
|
41
|
-
request_content_type: request.
|
43
|
+
request_content_type: request.media_type,
|
42
44
|
summary: summary,
|
43
45
|
tags: tags,
|
44
46
|
description: RSpec::OpenAPI.description_builder.call(example),
|
45
47
|
status: response.status,
|
46
48
|
response_body: response_body,
|
47
|
-
response_content_type: response.
|
49
|
+
response_content_type: response.media_type,
|
50
|
+
response_content_disposition: response.header["Content-Disposition"],
|
48
51
|
).freeze
|
49
52
|
end
|
50
53
|
|
@@ -7,10 +7,11 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
7
7
|
}
|
8
8
|
|
9
9
|
if record.response_body
|
10
|
+
disposition = normalize_content_disposition(record.response_content_disposition)
|
10
11
|
response[:content] = {
|
11
12
|
normalize_content_type(record.response_content_type) => {
|
12
|
-
schema: build_property(record.response_body),
|
13
|
-
example: (record
|
13
|
+
schema: build_property(record.response_body, disposition: disposition),
|
14
|
+
example: response_example(record, disposition: disposition),
|
14
15
|
}.compact,
|
15
16
|
}
|
16
17
|
end
|
@@ -34,6 +35,12 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
34
35
|
|
35
36
|
private
|
36
37
|
|
38
|
+
def response_example(record, disposition:)
|
39
|
+
return nil if !example_enabled? || disposition
|
40
|
+
|
41
|
+
record.response_body
|
42
|
+
end
|
43
|
+
|
37
44
|
def example_enabled?
|
38
45
|
RSpec::OpenAPI.enable_example
|
39
46
|
end
|
@@ -78,8 +85,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
78
85
|
}
|
79
86
|
end
|
80
87
|
|
81
|
-
def build_property(value)
|
82
|
-
property = build_type(value)
|
88
|
+
def build_property(value, disposition: nil)
|
89
|
+
property = build_type(value, disposition)
|
83
90
|
|
84
91
|
case value
|
85
92
|
when Array
|
@@ -94,7 +101,9 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
94
101
|
property
|
95
102
|
end
|
96
103
|
|
97
|
-
def build_type(value)
|
104
|
+
def build_type(value, disposition)
|
105
|
+
return { type: 'string', format: 'binary' } if disposition
|
106
|
+
|
98
107
|
case value
|
99
108
|
when String
|
100
109
|
{ type: 'string' }
|
@@ -111,7 +120,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
111
120
|
when ActionDispatch::Http::UploadedFile
|
112
121
|
{ type: 'string', format: 'binary' }
|
113
122
|
when NilClass
|
114
|
-
{
|
123
|
+
{ nullable: true }
|
115
124
|
else
|
116
125
|
raise NotImplementedError, "type detection is not implemented for: #{value.inspect}"
|
117
126
|
end
|
@@ -143,4 +152,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
|
|
143
152
|
def normalize_content_type(content_type)
|
144
153
|
content_type&.sub(/;.+\z/, '')
|
145
154
|
end
|
155
|
+
|
156
|
+
def normalize_content_disposition(content_disposition)
|
157
|
+
content_disposition&.sub(/;.+\z/, '')
|
158
|
+
end
|
146
159
|
end
|
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.3.
|
4
|
+
version: 0.3.16
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -45,6 +45,7 @@ executables: []
|
|
45
45
|
extensions: []
|
46
46
|
extra_rdoc_files: []
|
47
47
|
files:
|
48
|
+
- ".github/FUNDING.yml"
|
48
49
|
- ".github/workflows/test.yml"
|
49
50
|
- ".gitignore"
|
50
51
|
- ".rspec"
|
@@ -74,7 +75,7 @@ metadata:
|
|
74
75
|
homepage_uri: https://github.com/k0kubun/rspec-openapi
|
75
76
|
source_code_uri: https://github.com/k0kubun/rspec-openapi
|
76
77
|
changelog_uri: https://github.com/k0kubun/rspec-openapi/blob/master/CHANGELOG.md
|
77
|
-
post_install_message:
|
78
|
+
post_install_message:
|
78
79
|
rdoc_options: []
|
79
80
|
require_paths:
|
80
81
|
- lib
|
@@ -89,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
90
|
- !ruby/object:Gem::Version
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
|
-
rubygems_version: 3.
|
93
|
-
signing_key:
|
93
|
+
rubygems_version: 3.1.6
|
94
|
+
signing_key:
|
94
95
|
specification_version: 4
|
95
96
|
summary: Generate OpenAPI schema from RSpec request specs
|
96
97
|
test_files: []
|