rspec-openapi 0.3.12 → 0.3.17

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: 727ee90aa68d99aa8748b948fc70449163127e0ea0d0b1bfd5eadc5a1cbc8c2c
4
- data.tar.gz: 2d9746ec612b49af4c9482ffe608489e4ac55416aeed8e774ae642cf62af77ce
3
+ metadata.gz: 880f187fffd674c1abc266390cb70acedd726d09e947042286ce01b93b42f1f1
4
+ data.tar.gz: f602dbac30374bd4efa06806f505b8a867172b6ea493bf6d3e3ce8b156ce8455
5
5
  SHA512:
6
- metadata.gz: 3af2e86ba1321f7ab8cade64796a6e13a7f39f3d3363212dc6e93a550a2615d5fbed13e239dc2a78d54d757d4d0ed875a636af9c45a65d4b891731772ddeab91
7
- data.tar.gz: daa2a965e6b8b0c2e53fded5ae6de2980c277712b3230077d71ba39e6da977e2fb8fbd5995e13a018595473c034c0154e017b69a7e22e16bad555b3d14a67d6f
6
+ metadata.gz: 1a8b1611dea768d2bf7fa3c884d666d2635fec945dccda28ce8314e6557fe33b1c6315c8994953639f92ed181c61323a4c0a169670c2e47808aa9348f88a88a3
7
+ data.tar.gz: 82602c1729a8299fb128bd3f31b9449369e4eef7744bf60da1a54f1de148b9eb36b1e7b2e85b423695e36e3b6a3c1de7fa2710b5bae2e194ba23371b719f29ac
@@ -0,0 +1 @@
1
+ github: k0kubun
data/CHANGELOG.md CHANGED
@@ -1,3 +1,30 @@
1
+ ## v0.3.17
2
+
3
+ * Rescue NotImplementedError in the after suite hook as well
4
+ [#28](https://github.com/k0kubun/rspec-openapi/pull/28)
5
+
6
+ ## v0.3.16
7
+
8
+ * Use `media_type` instead of `content_type` for Rails 6.1
9
+ [#26](https://github.com/k0kubun/rspec-openapi/pull/26)
10
+ * Avoid crashing the after suite hook when it fails to build schema
11
+ [#27](https://github.com/k0kubun/rspec-openapi/pull/27)
12
+
13
+ ## v0.3.15
14
+
15
+ * Fix an error when Content-Disposition header is inline
16
+ [#24](https://github.com/k0kubun/rspec-openapi/pull/24)
17
+
18
+ ## v0.3.14
19
+
20
+ * Avoid an error when an application calls `request.body.read`
21
+ [#20](https://github.com/k0kubun/rspec-openapi/pull/20)
22
+
23
+ ## v0.3.13
24
+
25
+ * Avoid crashing when there's no request made in a spec
26
+ [#19](https://github.com/k0kubun/rspec-openapi/pull/19)
27
+
1
28
  ## v0.3.12
2
29
 
3
30
  * Generate `nullable: true` for null fields in schema
@@ -6,6 +6,7 @@ require 'rspec/openapi/schema_file'
6
6
  require 'rspec/openapi/schema_merger'
7
7
 
8
8
  records = []
9
+ records_errors = []
9
10
 
10
11
  RSpec.configuration.after(:each) do |example|
11
12
  if example.metadata[:type] == :request && example.metadata[:openapi] != false
@@ -19,7 +20,21 @@ RSpec.configuration.after(:suite) do
19
20
  RSpec::OpenAPI::SchemaFile.new(RSpec::OpenAPI.path).edit do |spec|
20
21
  RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::DefaultSchema.build(title))
21
22
  records.each do |record|
22
- RSpec::OpenAPI::SchemaMerger.reverse_merge!(spec, RSpec::OpenAPI::SchemaBuilder.build(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]
28
+ end
23
29
  end
24
30
  end
31
+ if records_errors.any?
32
+ error_message = <<~EOS
33
+ RSpec::OpenAPI got errors building #{records_errors.size} requests
34
+
35
+ #{records_errors.map {|e, record| "#{e.inspect}: #{record.inspect}" }.join("\n")}
36
+ EOS
37
+ colorizer = ::RSpec::Core::Formatters::ConsoleCodes
38
+ RSpec.configuration.reporter.message colorizer.wrap(error_message, :failure)
39
+ end
25
40
  end
@@ -11,5 +11,6 @@ RSpec::OpenAPI::Record = Struct.new(
11
11
  :status, # @param [Integer] - 200
12
12
  :response_body, # @param [Object] - {"status" => "ok"}
13
13
  :response_content_type, # @param [String] - "application/json"
14
+ :response_content_disposition, # @param [String] - "inline"
14
15
  keyword_init: true,
15
16
  )
@@ -8,11 +8,13 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
8
8
  def build(context, example:)
9
9
  if rack_test?(context)
10
10
  request = ActionDispatch::Request.new(context.last_request.env)
11
+ request.body.rewind if request.body.respond_to?(:rewind)
11
12
  response = ActionDispatch::TestResponse.new(*context.last_response.to_a)
12
13
  else
13
14
  request = context.request
14
15
  response = context.response
15
16
  end
17
+ return if request.nil?
16
18
 
17
19
  # Generate `path` and `summary` in a framework-friendly manner when possible
18
20
  if rails?
@@ -38,13 +40,14 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
38
40
  path_params: raw_path_params(request),
39
41
  query_params: request.query_parameters,
40
42
  request_params: raw_request_params(request),
41
- request_content_type: request.content_type,
43
+ request_content_type: request.media_type,
42
44
  summary: summary,
43
45
  tags: tags,
44
46
  description: RSpec::OpenAPI.description_builder.call(example),
45
47
  status: response.status,
46
48
  response_body: response_body,
47
- response_content_type: response.content_type,
49
+ response_content_type: response.media_type,
50
+ response_content_disposition: response.header["Content-Disposition"],
48
51
  ).freeze
49
52
  end
50
53
 
@@ -7,10 +7,11 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
7
7
  }
8
8
 
9
9
  if record.response_body
10
+ disposition = normalize_content_disposition(record.response_content_disposition)
10
11
  response[:content] = {
11
12
  normalize_content_type(record.response_content_type) => {
12
- schema: build_property(record.response_body),
13
- example: (record.response_body if example_enabled?),
13
+ schema: build_property(record.response_body, disposition: disposition),
14
+ example: response_example(record, disposition: disposition),
14
15
  }.compact,
15
16
  }
16
17
  end
@@ -34,6 +35,12 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
34
35
 
35
36
  private
36
37
 
38
+ def response_example(record, disposition:)
39
+ return nil if !example_enabled? || disposition
40
+
41
+ record.response_body
42
+ end
43
+
37
44
  def example_enabled?
38
45
  RSpec::OpenAPI.enable_example
39
46
  end
@@ -78,8 +85,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
78
85
  }
79
86
  end
80
87
 
81
- def build_property(value)
82
- property = build_type(value)
88
+ def build_property(value, disposition: nil)
89
+ property = build_type(value, disposition)
83
90
 
84
91
  case value
85
92
  when Array
@@ -94,7 +101,9 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
94
101
  property
95
102
  end
96
103
 
97
- def build_type(value)
104
+ def build_type(value, disposition)
105
+ return { type: 'string', format: 'binary' } if disposition
106
+
98
107
  case value
99
108
  when String
100
109
  { type: 'string' }
@@ -143,4 +152,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
143
152
  def normalize_content_type(content_type)
144
153
  content_type&.sub(/;.+\z/, '')
145
154
  end
155
+
156
+ def normalize_content_disposition(content_disposition)
157
+ content_disposition&.sub(/;.+\z/, '')
158
+ end
146
159
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.12'
3
+ VERSION = '0.3.17'
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.3.12
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Kokubun
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-27 00:00:00.000000000 Z
11
+ date: 2021-06-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -45,6 +45,7 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - ".github/FUNDING.yml"
48
49
  - ".github/workflows/test.yml"
49
50
  - ".gitignore"
50
51
  - ".rspec"
@@ -74,7 +75,7 @@ metadata:
74
75
  homepage_uri: https://github.com/k0kubun/rspec-openapi
75
76
  source_code_uri: https://github.com/k0kubun/rspec-openapi
76
77
  changelog_uri: https://github.com/k0kubun/rspec-openapi/blob/master/CHANGELOG.md
77
- post_install_message:
78
+ post_install_message:
78
79
  rdoc_options: []
79
80
  require_paths:
80
81
  - lib
@@ -89,8 +90,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  requirements: []
92
- rubygems_version: 3.2.6
93
- signing_key:
93
+ rubygems_version: 3.1.6
94
+ signing_key:
94
95
  specification_version: 4
95
96
  summary: Generate OpenAPI schema from RSpec request specs
96
97
  test_files: []