rspec-openapi 0.4.8 → 0.6.0

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: 4d6f2c98f9e3462e319dc05435274d53b933deb41553c2f4d7b70b3d4d135c7e
4
- data.tar.gz: 48e8862133eebc1cf0a700eb720603159f6274012342b4f9d259157d527af525
3
+ metadata.gz: b4d19b6239f38863e5cc4a7924d4dc9fc6f684a03f057f49371b4bd110fc312e
4
+ data.tar.gz: 972520dcffe3b393e32194a0fa4f9154c93c097f63d81750d7ac5d5b15d229d6
5
5
  SHA512:
6
- metadata.gz: 8420b3ad4d97a8a5e1d1dd89280f2dd95335e362997740fbbd342d7a352a2a90f3b1d912366ac3d32693c44e3b65ef0058522323fbdd5f1d6900cc122d1d1ae1
7
- data.tar.gz: 891a7b33e112310e66ec6bcff616aac5c93a8036028ba95cf25b5ac40a3d89e2599a906782a15a107c37779a7c657bfda4b92d5fb4e364725300d071c2a870e3
6
+ metadata.gz: 377aa3ea1a708b7ba2a8fd9cbaf96f0e6cf3588bdfbedcb14ee3ccb30c478c54e2d34fcd8e08bafc25c4c3cfab0062a4deb9781cf63e1c001b6e16750348222e
7
+ data.tar.gz: eebc893ceb3eaa4207fcbac83e453ea19adcfdc5b64d82725f441dfa8fa33142bab178dd21b76318dbf6f01afa80da40a9f50b5c87c726a2e63fd3bfd56e4386
@@ -15,11 +15,19 @@ jobs:
15
15
  strategy:
16
16
  fail-fast: false
17
17
  matrix:
18
- ruby:
19
- - ruby:2.5
20
- - ruby:2.6
21
- - ruby:2.7
22
- - ruby:3.0
18
+ include:
19
+ - ruby: ruby:2.5
20
+ - ruby: ruby:2.6
21
+ - ruby: ruby:2.7
22
+ - ruby: ruby:3.0
23
+ - ruby: ruby:3.1
24
+ rails: 6.0.5
25
+ - ruby: ruby:3.1
26
+ rails: 6.1.6
27
+ - ruby: ruby:3.1
28
+ rails: 7.0.3
29
+ env:
30
+ RAILS_VERSION: ${{ matrix.rails == '' && '6.1.6' || matrix.rails }}
23
31
  steps:
24
32
  - uses: actions/checkout@v2
25
33
  - name: bundle install
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## v0.6.0
2
+
3
+ * Replace `RSpec::OpenAPI.server_urls` with `RSpec::OpenAPI.servers`
4
+ [#60](https://github.com/k0kubun/rspec-openapi/pull/60)
5
+
6
+ ## v0.5.1
7
+
8
+ * Clarify the version requirement for actionpack
9
+ [#62](https://github.com/k0kubun/rspec-openapi/pull/62)
10
+
11
+ ## v0.5.0
12
+
13
+ * Overwrite fields in an existing schema file instead of leaving all existing fields as is
14
+ [#55](https://github.com/k0kubun/rspec-openapi/pull/55)
15
+
1
16
  ## v0.4.8
2
17
 
3
18
  * Fix a bug in nested parameters handling
data/Gemfile CHANGED
@@ -3,7 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in rspec-openapi.gemspec
4
4
  gemspec
5
5
 
6
- gem 'rails', '6.0.3.2'
6
+ gem 'rails', ENV['RAILS_VERSION'] || '6.0.3.2'
7
7
  gem 'roda'
8
8
  gem 'rspec-rails'
9
9
 
data/README.md CHANGED
@@ -105,6 +105,8 @@ and the schema file can be used as an input of [Swagger UI](https://github.com/s
105
105
  The following configurations are optional.
106
106
 
107
107
  ```rb
108
+ require 'rspec/openapi'
109
+
108
110
  # Change the path to generate schema from `doc/openapi.yaml`
109
111
  RSpec::OpenAPI.path = 'doc/schema.yaml'
110
112
 
@@ -138,10 +140,8 @@ RSpec::OpenAPI.info = {
138
140
  # Set `headers` - generate parameters with headers for a request
139
141
  RSpec::OpenAPI.request_headers = %w[X-Authorization-Token]
140
142
 
141
- # Set `server_urls` - generate servers of a schema file
142
- RSpec::OpenAPI.server_urls = %w[
143
- http://localhost:3000
144
- ]
143
+ # Set `servers` - generate servers of a schema file
144
+ RSpec::OpenAPI.servers = [{ url: 'http://localhost:3000' }]
145
145
 
146
146
  # Generate a comment on top of a schema file
147
147
  RSpec::OpenAPI.comment = <<~EOS
@@ -6,7 +6,7 @@ class << RSpec::OpenAPI::DefaultSchema = Object.new
6
6
  title: title,
7
7
  version: RSpec::OpenAPI.application_version,
8
8
  },
9
- servers: RSpec::OpenAPI.server_urls.map { |url| { url: url } } || [],
9
+ servers: RSpec::OpenAPI.servers,
10
10
  paths: {},
11
11
  }.freeze
12
12
  end
@@ -22,10 +22,10 @@ RSpec.configuration.after(:suite) do
22
22
  RSpec::OpenAPI::SchemaFile.new(path).edit do |spec|
23
23
  schema = RSpec::OpenAPI::DefaultSchema.build(title)
24
24
  schema[:info].merge!(RSpec::OpenAPI.info)
25
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, schema)
25
+ RSpec::OpenAPI::SchemaMerger.merge!(spec, schema)
26
26
  records.each do |record|
27
27
  begin
28
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
28
+ RSpec::OpenAPI::SchemaMerger.merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(record))
29
29
  rescue StandardError, NotImplementedError => e # e.g. SchemaBuilder raises a NotImplementedError
30
30
  error_records[e] = record # Avoid failing the build
31
31
  end
@@ -1,9 +1,9 @@
1
1
  class << RSpec::OpenAPI::SchemaMerger = Object.new
2
2
  # @param [Hash] base
3
3
  # @param [Hash] spec
4
- def reverse_merge!(base, spec)
4
+ def merge!(base, spec)
5
5
  spec = normalize_keys(spec)
6
- deep_reverse_merge!(base, spec)
6
+ merge_schema!(base, spec)
7
7
  end
8
8
 
9
9
  private
@@ -22,25 +22,26 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
22
22
  end
23
23
 
24
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.
25
+ # Also this needs to be aware of OpenAPI details because a Hash-like structure
26
+ # may be an array whose Hash elements have a key name.
27
27
  #
28
- # TODO: Perform more intelligent merges like rerouting edits / merging types
29
28
  # TODO: Should we probably force-merge `summary` regardless of manual modifications?
30
- def deep_reverse_merge!(base, spec)
29
+ def merge_schema!(base, spec)
31
30
  spec.each do |key, value|
32
31
  if base[key].is_a?(Hash) && value.is_a?(Hash)
33
- deep_reverse_merge!(base[key], value)
34
- elsif !base.key?(key)
35
- base[key] = value
32
+ if !base[key].key?("$ref")
33
+ merge_schema!(base[key], value)
34
+ end
36
35
  elsif base[key].is_a?(Array) && value.is_a?(Array)
37
36
  # parameters need to be merged as if `name` and `in` were the Hash keys.
38
37
  if key == 'parameters'
39
38
  base[key] |= value
40
39
  base[key].uniq! { |param| param.slice('name', 'in') }
40
+ else
41
+ base[key] = value
41
42
  end
42
43
  else
43
- # no-op
44
+ base[key] = value
44
45
  end
45
46
  end
46
47
  base
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.4.8'
3
+ VERSION = '0.6.0'
4
4
  end
5
5
  end
data/lib/rspec/openapi.rb CHANGED
@@ -9,10 +9,10 @@ module RSpec::OpenAPI
9
9
  @info = {}
10
10
  @application_version = '1.0.0'
11
11
  @request_headers = []
12
- @server_urls = []
12
+ @servers = []
13
13
  @example_types = %i[request]
14
14
 
15
15
  class << self
16
- attr_accessor :path, :comment, :enable_example, :description_builder, :info, :application_version, :request_headers, :server_urls, :example_types
16
+ attr_accessor :path, :comment, :enable_example, :description_builder, :info, :application_version, :request_headers, :servers, :example_types
17
17
  end
18
18
  end
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
24
  spec.require_paths = ['lib']
25
25
 
26
- spec.add_dependency 'actionpack'
26
+ spec.add_dependency 'actionpack', '>= 5.2.0'
27
27
  spec.add_dependency 'rspec'
28
28
  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.8
4
+ version: 0.6.0
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-30 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 5.2.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 5.2.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -49,7 +49,6 @@ files:
49
49
  - ".github/workflows/test.yml"
50
50
  - ".gitignore"
51
51
  - ".rspec"
52
- - ".travis.yml"
53
52
  - CHANGELOG.md
54
53
  - Gemfile
55
54
  - LICENSE.txt
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.1
6
- before_install: gem install bundler -v 2.1.4