rspec-openapi 0.4.1 → 0.4.2
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 +5 -0
- data/README.md +10 -18
- data/lib/rspec/openapi/hooks.rb +16 -14
- 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: a02d800d2c00b3cfec6a1a860f17eafaed45e51329aaa7407ed1e96892a10ac9
|
4
|
+
data.tar.gz: db0ec61540014497148d218846c01287d2b4f0e1ec4782148d932c5308ccbc75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b357caa7a5b3f497a743ddf7be434ceb141e5de9b93d5995ac66e7d42abce47fddaa65f5f62f0ceffca4e4d42a40405c7b6d8190b4d2557148d633af1c9e289d
|
7
|
+
data.tar.gz: c8166a897c99f4b60747bc4c51f223c20627303fd6276c2e8e9a4908fee6287d43f1fb43135354ff7615f7c0cece8665c1b5a96da234e3598dbe311c1468d712
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -24,7 +24,7 @@ gem 'rspec-openapi', group: :test
|
|
24
24
|
Run rspec with OPENAPI=1 to generate `doc/openapi.yaml` for your request specs.
|
25
25
|
|
26
26
|
```bash
|
27
|
-
$ OPENAPI=1 rspec
|
27
|
+
$ OPENAPI=1 bundle exec rspec
|
28
28
|
```
|
29
29
|
|
30
30
|
### Example
|
@@ -111,6 +111,15 @@ RSpec::OpenAPI.path = 'doc/schema.yaml'
|
|
111
111
|
# Change the output type to JSON
|
112
112
|
RSpec::OpenAPI.path = 'doc/schema.json'
|
113
113
|
|
114
|
+
# Or generate multiple partial schema files, given an RSpec example
|
115
|
+
RSpec::OpenAPI.path = -> (example) {
|
116
|
+
case example.file_path
|
117
|
+
when %r[spec/requests/api/v1/] then 'doc/openapi/v1.yaml'
|
118
|
+
when %r[spec/requests/api/v2/] then 'doc/openapi/v2.yaml'
|
119
|
+
else 'doc/openapi.yaml'
|
120
|
+
end
|
121
|
+
}
|
122
|
+
|
114
123
|
# Disable generating `example`
|
115
124
|
RSpec::OpenAPI.enable_example = false
|
116
125
|
|
@@ -163,23 +172,6 @@ RSpec.describe '/resources', type: :request do
|
|
163
172
|
end
|
164
173
|
```
|
165
174
|
|
166
|
-
## Project status
|
167
|
-
|
168
|
-
Beta
|
169
|
-
|
170
|
-
Basic features are there, and some people are already using this.
|
171
|
-
|
172
|
-
### Other missing features with notes
|
173
|
-
|
174
|
-
* Delete obsoleted endpoints
|
175
|
-
* Give up, or at least make the feature optional?
|
176
|
-
* Running all to detect obsoleted endpoints is sometimes not realistic anyway.
|
177
|
-
* Intelligent merges
|
178
|
-
* To maintain both automated changes and manual edits, the schema merge needs to be intelligent.
|
179
|
-
* We'll just deep-reverse-merge schema for now, but if there's a $ref for example, modifications
|
180
|
-
there should be rerouted to the referenced object.
|
181
|
-
* A type could be an array of all possible types when merged.
|
182
|
-
|
183
175
|
## Links
|
184
176
|
|
185
177
|
Existing RSpec plugins which have OpenAPI integration:
|
data/lib/rspec/openapi/hooks.rb
CHANGED
@@ -5,34 +5,36 @@ require 'rspec/openapi/schema_builder'
|
|
5
5
|
require 'rspec/openapi/schema_file'
|
6
6
|
require 'rspec/openapi/schema_merger'
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
path_records = Hash.new { |h, k| h[k] = [] }
|
9
|
+
error_records = {}
|
10
10
|
|
11
11
|
RSpec.configuration.after(:each) do |example|
|
12
12
|
if RSpec::OpenAPI.example_types.include?(example.metadata[:type]) && example.metadata[:openapi] != false
|
13
|
+
path = RSpec::OpenAPI.path.yield_self { |path| path.is_a?(Proc) ? path.call(example) : path }
|
13
14
|
record = RSpec::OpenAPI::RecordBuilder.build(self, example: example)
|
14
|
-
|
15
|
+
path_records[path] << record if record
|
15
16
|
end
|
16
17
|
end
|
17
18
|
|
18
19
|
RSpec.configuration.after(:suite) do
|
19
20
|
title = File.basename(Dir.pwd)
|
20
|
-
|
21
|
-
RSpec::OpenAPI::
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
#
|
27
|
-
|
21
|
+
path_records.each do |path, records|
|
22
|
+
RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
|
23
|
+
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
|
24
|
+
records.each do |record|
|
25
|
+
begin
|
26
|
+
RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
|
27
|
+
rescue StandardError, NotImplementedError => e # e.g. SchemaBuilder raises a NotImplementedError
|
28
|
+
error_records[e] = record # Avoid failing the build
|
29
|
+
end
|
28
30
|
end
|
29
31
|
end
|
30
32
|
end
|
31
|
-
if
|
33
|
+
if error_records.any?
|
32
34
|
error_message = <<~EOS
|
33
|
-
RSpec::OpenAPI got errors building #{
|
35
|
+
RSpec::OpenAPI got errors building #{error_records.size} requests
|
34
36
|
|
35
|
-
#{
|
37
|
+
#{error_records.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
|
36
38
|
EOS
|
37
39
|
colorizer = ::RSpec::Core::Formatters::ConsoleCodes
|
38
40
|
RSpec.configuration.reporter.message colorizer.wrap(error_message, :failure)
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi Kokubun
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-10 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.2.22
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Generate OpenAPI schema from RSpec request specs
|