rspec-openapi 0.14.0 → 0.15.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 032e7acfd3a1818b7bffc9130fb58116cc8f8e2045d40e426cabb9c47d37d323
4
- data.tar.gz: 4dad6278000051a228fbe41f0210931411ddb119730055bd9262bd8dfd18ea23
3
+ metadata.gz: cf9d4a386bc3e6a08230a32ae5593c8787f255cc901df5493daa8fb196796cc0
4
+ data.tar.gz: ba75408ae751a4c010a6e42872376c6bc539e0a4820fe1c2387649d5f9826f7a
5
5
  SHA512:
6
- metadata.gz: 75d7e8fb034bffdb1ed6d5dafbd1acdffd45d28db52bcb39c5606dad7bac41656415b2b0473a9aaed24bc2a9577ab9dd0bc8c413f547fabaaa5e4df7fe62f806
7
- data.tar.gz: 2489d638c378f1f061ba992804761af38795a414535df628a5a3b419fcc73f11b116a23bb9d1a3f5a90f687fb30a70e220417463f75c33519194068440e155a2
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
@@ -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
@@ -33,7 +33,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
33
33
  description: description,
34
34
  security: security,
35
35
  status: response.status,
36
- response_body: safe_parse_body(response),
36
+ response_body: safe_parse_body(response, response.media_type),
37
37
  response_headers: response_headers,
38
38
  response_content_type: response.media_type,
39
39
  response_content_disposition: response.header['Content-Disposition'],
@@ -42,7 +42,10 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
42
42
 
43
43
  private
44
44
 
45
- 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
+
46
49
  response.parsed_body
47
50
  rescue JSON::ParserError
48
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.14.0'
5
+ VERSION = '0.15.0'
6
6
  end
7
7
  end
@@ -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.14.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-08 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.14.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
  - - ">="