rspec-openapi 0.13.0 → 0.15.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: a5139294ebac456aadd2c09832f55cb214b7bf4ba9893919445823455cbee18a
4
- data.tar.gz: b77813ff2d18290e714482bfa45350f69b182a638162d083923acb9b21124cfe
3
+ metadata.gz: cf9d4a386bc3e6a08230a32ae5593c8787f255cc901df5493daa8fb196796cc0
4
+ data.tar.gz: ba75408ae751a4c010a6e42872376c6bc539e0a4820fe1c2387649d5f9826f7a
5
5
  SHA512:
6
- metadata.gz: 58de63dbf9608beb5f313eb57e6e1e4386eefa23fd1b572d17b06319f571ca3c6b1ac172a7886b3dcd42e14feb1f5f60ebd5a532951441193f8400d66e5229ce
7
- data.tar.gz: 95765054acd231993f058a9f3a31a596c56ff143af9f1dc576bfb2f201773e611025329069b8c49751f50d3bf14b16a4f83ef863587d2f7815209f0afcdccb4a
6
+ metadata.gz: 22fc87ba0e0b3140f62d9b2396b2d24dbd9fc34fdbdf2664826db02fb3549c4ac3ddc4097ce85a348ff01b4b79279cfe5f450bc65bebb99c95982bf8c06beff0
7
+ data.tar.gz: fdd836b66e540d2e2488810ac1570ea0565c963d5817da740da3691d337e5b090e21b287fed92a3c12c9c434916e2481982eee117ee0add52e2bd4ef66a80961
@@ -19,7 +19,7 @@ jobs:
19
19
  - name: Set up Ruby
20
20
  uses: ruby/setup-ruby@v1
21
21
  with:
22
- ruby-version: 2.6
22
+ ruby-version: 3.3
23
23
  bundler-cache: true
24
24
 
25
25
  - name: Rubocop run
@@ -16,8 +16,6 @@ jobs:
16
16
  fail-fast: false
17
17
  matrix:
18
18
  include:
19
- - ruby: ruby:2.5
20
- - ruby: ruby:2.6
21
19
  - ruby: ruby:2.7
22
20
  - ruby: ruby:3.0
23
21
  - ruby: ruby:3.1
@@ -36,11 +34,6 @@ jobs:
36
34
  - uses: actions/checkout@v4
37
35
  - name: bundle install
38
36
  run: bundle install -j$(nproc) --retry 3
39
- - name: install simplecov-fork only for minitest with coverage
40
- run: |
41
- gem install specific_install
42
- gem specific_install https://github.com/exoego/simplecov.git branch-fix
43
- if: matrix.coverage == 'coverage'
44
37
  - run: bundle exec rspec
45
38
  timeout-minutes: 1
46
39
  - run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
data/.rubocop.yml CHANGED
@@ -2,7 +2,8 @@ inherit_from: .rubocop_todo.yml
2
2
 
3
3
  AllCops:
4
4
  NewCops: enable
5
- TargetRubyVersion: 2.5
5
+ SuggestExtensions: false
6
+ TargetRubyVersion: 2.7
6
7
  Exclude:
7
8
  - 'spec/rails/**/*'
8
9
  - 'vendor/**/*'
data/.rubocop_todo.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2024-01-13 11:12:43 UTC using RuboCop version 1.50.2.
3
+ # on 2024-03-25 05:35:37 UTC using RuboCop version 1.62.1.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
- # Offense count: 9
9
+ # Offense count: 11
10
10
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
11
11
  Metrics/AbcSize:
12
12
  Max: 48
@@ -14,19 +14,19 @@ Metrics/AbcSize:
14
14
  # Offense count: 2
15
15
  # Configuration parameters: CountComments, CountAsOne.
16
16
  Metrics/ClassLength:
17
- Max: 192
17
+ Max: 207
18
18
 
19
- # Offense count: 5
19
+ # Offense count: 8
20
20
  # Configuration parameters: AllowedMethods, AllowedPatterns.
21
21
  Metrics/CyclomaticComplexity:
22
22
  Max: 13
23
23
 
24
- # Offense count: 16
24
+ # Offense count: 19
25
25
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
26
26
  Metrics/MethodLength:
27
- Max: 31
27
+ Max: 34
28
28
 
29
- # Offense count: 1
29
+ # Offense count: 3
30
30
  # Configuration parameters: AllowedMethods, AllowedPatterns.
31
31
  Metrics/PerceivedComplexity:
32
32
  Max: 13
data/README.md CHANGED
@@ -29,7 +29,7 @@ $ OPENAPI=1 bundle exec rspec
29
29
 
30
30
  ### Example
31
31
 
32
- Let's say you have [a request spec](./spec/requests/rails/tables_spec.rb) like this:
32
+ Let's say you have [a request spec](https://github.com/exoego/rspec-openapi/blob/24e5c567c2e90945c7a41f19f71634ac028cc314/spec/requests/rails_spec.rb#L38) like this:
33
33
 
34
34
  ```rb
35
35
  RSpec.describe 'Tables', type: :request do
@@ -184,6 +184,12 @@ RSpec::OpenAPI.example_types = %i[request]
184
184
  # :controller and :action always exist. :format is added when routes is configured as such.
185
185
  RSpec::OpenAPI.ignored_path_params = %i[controller action format]
186
186
 
187
+ # Configure which paths to ignore.
188
+ # You can exclude some specs via `openapi: false`.
189
+ # But, in a complex API usage scenario, you may need to include spec itself, but exclude some private paths.
190
+ # In that case, you can specify the paths to ignore.
191
+ # String or Regexp is acceptable.
192
+ RSpec::OpenAPI.ignored_paths = ["/admin/full/path/", Regexp.new("^/_internal/")]
187
193
  ```
188
194
 
189
195
  ### Can I use rspec-openapi with `$ref` to minimize duplication of schema?
@@ -12,7 +12,7 @@ module RSpec::OpenAPI::Minitest
12
12
  file_path = method(name).source_location.first
13
13
  human_name = name.sub(/^test_/, '').gsub('_', ' ')
14
14
  example = Example.new(self, human_name, {}, file_path)
15
- path = RSpec::OpenAPI.path.yield_self { |p| p.is_a?(Proc) ? p.call(example) : p }
15
+ path = RSpec::OpenAPI.path.then { |p| p.is_a?(Proc) ? p.call(example) : p }
16
16
  record = RSpec::OpenAPI::RecordBuilder.build(self, example: example)
17
17
  RSpec::OpenAPI.path_records[path] << record if record
18
18
  end
@@ -45,6 +45,6 @@ if ENV['OPENAPI']
45
45
  Minitest.after_run do
46
46
  result_recorder = RSpec::OpenAPI::ResultRecorder.new(RSpec::OpenAPI.path_records)
47
47
  result_recorder.record_results!
48
- puts result_record.error_message if result_recorder.errors?
48
+ puts result_recorder.error_message if result_recorder.errors?
49
49
  end
50
50
  end
@@ -14,6 +14,8 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
14
14
  path, summary, tags, operation_id, required_request_params, raw_path_params, description, security =
15
15
  extract_request_attributes(request, example)
16
16
 
17
+ return if RSpec::OpenAPI.ignored_paths.any? { |ignored_path| path.match?(ignored_path) }
18
+
17
19
  request_headers, response_headers = extract_headers(request, response)
18
20
 
19
21
  RSpec::OpenAPI::Record.new(
@@ -31,7 +33,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
31
33
  description: description,
32
34
  security: security,
33
35
  status: response.status,
34
- response_body: safe_parse_body(response),
36
+ response_body: safe_parse_body(response, response.media_type),
35
37
  response_headers: response_headers,
36
38
  response_content_type: response.media_type,
37
39
  response_content_disposition: response.header['Content-Disposition'],
@@ -40,7 +42,10 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
40
42
 
41
43
  private
42
44
 
43
- def safe_parse_body(response)
45
+ def safe_parse_body(response, media_type)
46
+ # Use raw body, because Nokogiri-parsed HTML are modified (new lines injection, meta injection, and so on) :(
47
+ return response.body if media_type == 'text/html'
48
+
44
49
  response.parsed_body
45
50
  rescue JSON::ParserError
46
51
  nil
@@ -4,7 +4,7 @@ require 'rspec/core'
4
4
 
5
5
  RSpec.configuration.after(:each) do |example|
6
6
  if RSpec::OpenAPI.example_types.include?(example.metadata[:type]) && example.metadata[:openapi] != false
7
- path = RSpec::OpenAPI.path.yield_self { |p| p.is_a?(Proc) ? p.call(example) : p }
7
+ path = RSpec::OpenAPI.path.then { |p| p.is_a?(Proc) ? p.call(example) : p }
8
8
  record = RSpec::OpenAPI::RecordBuilder.build(self, example: example)
9
9
  RSpec::OpenAPI.path_records[path] << record if record
10
10
  end
@@ -13,12 +13,16 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
13
13
 
14
14
  if record.response_body
15
15
  disposition = normalize_content_disposition(record.response_content_disposition)
16
- response[:content] = {
17
- normalize_content_type(record.response_content_type) => {
18
- schema: build_property(record.response_body, disposition: disposition),
19
- example: response_example(record, disposition: disposition),
20
- }.compact,
21
- }
16
+
17
+ has_content = !normalize_content_type(record.response_content_type).nil?
18
+ if has_content
19
+ response[:content] = {
20
+ normalize_content_type(record.response_content_type) => {
21
+ schema: build_property(record.response_body, disposition: disposition),
22
+ example: response_example(record, disposition: disposition),
23
+ }.compact,
24
+ }
25
+ end
22
26
  end
23
27
 
24
28
  {
@@ -13,9 +13,9 @@ class << RSpec::OpenAPI::SchemaMerger = Object.new
13
13
  def normalize_keys(spec)
14
14
  case spec
15
15
  when Hash
16
- spec.map do |key, value|
16
+ spec.to_h do |key, value|
17
17
  [key.to_s, normalize_keys(value)]
18
- end.to_h
18
+ end
19
19
  when Array
20
20
  spec.map { |s| normalize_keys(s) }
21
21
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RSpec
4
4
  module OpenAPI
5
- VERSION = '0.13.0'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  end
data/lib/rspec/openapi.rb CHANGED
@@ -31,6 +31,7 @@ module RSpec::OpenAPI
31
31
  @response_headers = []
32
32
  @path_records = Hash.new { |h, k| h[k] = [] }
33
33
  @ignored_path_params = %i[controller action format]
34
+ @ignored_paths = []
34
35
 
35
36
  # This is the configuraion override file name we look for within each path.
36
37
  @config_filename = 'rspec_openapi.rb'
@@ -51,6 +52,7 @@ module RSpec::OpenAPI
51
52
  :example_types,
52
53
  :response_headers,
53
54
  :path_records,
55
+ :ignored_paths,
54
56
  :ignored_path_params
55
57
 
56
58
  attr_reader :config_filename
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = 'Generate OpenAPI from RSpec request specs'
13
13
  spec.homepage = 'https://github.com/exoego/rspec-openapi'
14
14
  spec.license = 'MIT'
15
- spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
15
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
16
16
 
17
17
  spec.metadata = {
18
18
  'homepage_uri' => 'https://github.com/exoego/rspec-openapi',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-openapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.13.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-03-02 00:00:00.000000000 Z
12
+ date: 2024-03-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -88,7 +88,7 @@ licenses:
88
88
  metadata:
89
89
  homepage_uri: https://github.com/exoego/rspec-openapi
90
90
  source_code_uri: https://github.com/exoego/rspec-openapi
91
- changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.13.0
91
+ changelog_uri: https://github.com/exoego/rspec-openapi/releases/tag/v0.15.0
92
92
  rubygems_mfa_required: 'true'
93
93
  post_install_message:
94
94
  rdoc_options: []
@@ -98,7 +98,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
98
98
  requirements:
99
99
  - - ">="
100
100
  - !ruby/object:Gem::Version
101
- version: 2.5.0
101
+ version: 2.7.0
102
102
  required_rubygems_version: !ruby/object:Gem::Requirement
103
103
  requirements:
104
104
  - - ">="