rspec-openapi 0.3.10 → 0.3.15

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: 62ae9fb333bba34df56a7675823e22ae9029852028d529ffae48ee9070eadeb0
4
- data.tar.gz: 249959214fbce6ae72294f07e1a7de945c1052071d67942ec7f19c68cbe90a9f
3
+ metadata.gz: 76a7b33ccfea2d2fbaf9cb45b49171c46c0b6b9df44280ac6d6bf0f864aedb60
4
+ data.tar.gz: d52a3651c1dc945711c378d39e53867f518c9b8aed2d6bf7502c00aade767856
5
5
  SHA512:
6
- metadata.gz: 8f66917401fc326b7a290892000ef82af637d959fd337ab158152176605fa5e41a8ce2e904b7c1d73cef203d1b3851912bcff0d58f5e879d27fc728f456d1569
7
- data.tar.gz: abf3aee3cd216b58d53079c53372a3839c3cc89470d5a0500274fde35a3103643d8c6a3555b977989bc598f4f71e0518300cec76372dce1a8ff4bb41615a0113
6
+ metadata.gz: f8eac8961aa0b71a48f3af48c118dad88b8e4e90767dfb37c87d0902422a9ed6bea2c43cf87c713c209be0d7284f114cd455d49069b8521d3d34ad6ffcd901eb
7
+ data.tar.gz: d2a984317e8b93f8f2f29540c2a34af9fa89b46aadbdd300cc2247212d338530aff7d53aae75b27cabbd1d21ea3a30698051e1cd836509bf36c202f5c538eec9
@@ -0,0 +1 @@
1
+ github: k0kubun
@@ -19,6 +19,7 @@ jobs:
19
19
  - ruby:2.5
20
20
  - ruby:2.6
21
21
  - ruby:2.7
22
+ - ruby:3.0
22
23
  steps:
23
24
  - uses: actions/checkout@v2
24
25
  - name: bundle install
data/CHANGELOG.md CHANGED
@@ -1,3 +1,28 @@
1
+ ## v0.3.15
2
+
3
+ * Fix an error when Content-Disposition header is inline
4
+ [#24](https://github.com/k0kubun/rspec-openapi/pull/24)
5
+
6
+ ## v0.3.14
7
+
8
+ * Avoid an error when an application calls `request.body.read`
9
+ [#20](https://github.com/k0kubun/rspec-openapi/pull/20)
10
+
11
+ ## v0.3.13
12
+
13
+ * Avoid crashing when there's no request made in a spec
14
+ [#19](https://github.com/k0kubun/rspec-openapi/pull/19)
15
+
16
+ ## v0.3.12
17
+
18
+ * Generate `nullable: true` for null fields in schema
19
+ [#18](https://github.com/k0kubun/rspec-openapi/pull/18)
20
+
21
+ ## v0.3.11
22
+
23
+ * Show a filename as an `example` for `ActionDispatch::Http::UploadedFile`
24
+ [#17](https://github.com/k0kubun/rspec-openapi/pull/17)
25
+
1
26
  ## v0.3.10
2
27
 
3
28
  * Add `info.version`
@@ -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?
@@ -45,6 +47,7 @@ class << RSpec::OpenAPI::RecordBuilder = Object.new
45
47
  status: response.status,
46
48
  response_body: response_body,
47
49
  response_content_type: response.content_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
@@ -72,14 +79,14 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
72
79
  content: {
73
80
  normalize_content_type(record.request_content_type) => {
74
81
  schema: build_property(record.request_params),
75
- example: (record.request_params if example_enabled?),
82
+ example: (build_example(record.request_params) if example_enabled?),
76
83
  }.compact
77
84
  }
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' }
@@ -111,7 +120,7 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
111
120
  when ActionDispatch::Http::UploadedFile
112
121
  { type: 'string', format: 'binary' }
113
122
  when NilClass
114
- { type: 'null' }
123
+ { nullable: true }
115
124
  else
116
125
  raise NotImplementedError, "type detection is not implemented for: #{value.inspect}"
117
126
  end
@@ -126,6 +135,16 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
126
135
  end
127
136
  end
128
137
 
138
+ def build_example(value)
139
+ return nil if value.nil?
140
+ value = value.dup
141
+ value.each do |key, v|
142
+ if v.is_a?(ActionDispatch::Http::UploadedFile)
143
+ value[key] = v.original_filename
144
+ end
145
+ end
146
+ end
147
+
129
148
  def normalize_path(path)
130
149
  path.gsub(%r|/:([^:/]+)|, '/{\1}')
131
150
  end
@@ -133,4 +152,8 @@ class << RSpec::OpenAPI::SchemaBuilder = Object.new
133
152
  def normalize_content_type(content_type)
134
153
  content_type&.sub(/;.+\z/, '')
135
154
  end
155
+
156
+ def normalize_content_disposition(content_disposition)
157
+ content_disposition&.sub(/;.+\z/, '')
158
+ end
136
159
  end
@@ -1,5 +1,5 @@
1
1
  module RSpec
2
2
  module OpenAPI
3
- VERSION = '0.3.10'
3
+ VERSION = '0.3.15'
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.10
4
+ version: 0.3.15
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-01-12 00:00:00.000000000 Z
11
+ date: 2021-04-24 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"
@@ -89,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
89
90
  - !ruby/object:Gem::Version
90
91
  version: '0'
91
92
  requirements: []
92
- rubygems_version: 3.1.2
93
+ rubygems_version: 3.2.3
93
94
  signing_key:
94
95
  specification_version: 4
95
96
  summary: Generate OpenAPI schema from RSpec request specs