rspec-openapi 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3032d3fed3b9bdc2b2a8512db3d1645679163539106650c1ad05069a15ab59cd
4
- data.tar.gz: d1d3e85b467226a857b30bfe95b5643a1a37df2c0a925e509bdd893ae3017177
3
+ metadata.gz: a02d800d2c00b3cfec6a1a860f17eafaed45e51329aaa7407ed1e96892a10ac9
4
+ data.tar.gz: db0ec61540014497148d218846c01287d2b4f0e1ec4782148d932c5308ccbc75
5
5
  SHA512:
6
- metadata.gz: 0c65c74db1ada24cf360545bda34830ca82d9cbd11b6e862a0563f9fc2bf244d65a96ec74e8223c182d1a2bff72b237e30c5884c2818576f9c142585d177351b
7
- data.tar.gz: 397cfcddeaf3c1f683b9a1cd75960bf7d61e24adfcc9988bea2533c7a781acd42f43178b2ffb45deb5b3e821090f979d18af041a078f9ca3c2c7cd124cb4aff2
6
+ metadata.gz: b357caa7a5b3f497a743ddf7be434ceb141e5de9b93d5995ac66e7d42abce47fddaa65f5f62f0ceffca4e4d42a40405c7b6d8190b4d2557148d633af1c9e289d
7
+ data.tar.gz: c8166a897c99f4b60747bc4c51f223c20627303fd6276c2e8e9a4908fee6287d43f1fb43135354ff7615f7c0cece8665c1b5a96da234e3598dbe311c1468d712
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ ## v0.4.2
2
+
3
+ * Allow using Proc as `RSpec::OpenAPI.path`
4
+ [#35](https://github.com/k0kubun/rspec-openapi/pull/35)
5
+
1
6
  ## v0.4.1
2
7
 
3
8
  * Add `RSpec::OpenAPI.example_types` to hook types other than `type: :request`.
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:
@@ -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
- records = []
9
- records_errors = []
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
- records << record if record
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
- RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec|
21
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
22
- records.each do |record|
23
- begin
24
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
25
- rescue StandardError, NotImplementedError => e # e.g. SchemaBuilder raises a NotImplementedError
26
- # NOTE: Don't fail the build
27
- records_errors << [e, record]
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 records_errors.any?
33
+ if error_records.any?
32
34
  error_message = <<~EOS
33
- RSpec::OpenAPI got errors building #{records_errors.size} requests
35
+ RSpec::OpenAPI got errors building #{error_records.size} requests
34
36
 
35
- #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
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)
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.4.1'
3
+ VERSION = '0.4.2'
4
4
  end
5
5
  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.4.1
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: 2021-11-22 00:00:00.000000000 Z
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.1.2
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