grape-swagger 0.30.0 → 0.30.1

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: 329bb3676657055c5c086902b97ce065a4b7886d9de5ea5542e7874052ab92a9
4
- data.tar.gz: 4290d2ea021d4cca08b5ba4a83033fa9df8476b79cc500d9d0de9476e1190f6a
3
+ metadata.gz: 2cc4d92b47209a6323502fd863a738a8829e0d78b599a47e83a1aa9e52746cf7
4
+ data.tar.gz: cbc408aaf0f686032312bdfb3332671d73341e90eeff694162f2d0bdcfc14a81
5
5
  SHA512:
6
- metadata.gz: abe0988e09f9fd987983977df65419230c04c60ef89ebb135921cf528c61c05e196873d3077db99b7540e94453929bc987e873c39f39f98adf70f77816f4fd75
7
- data.tar.gz: 9530e8d9f2c2540ec167c8cbfe7a2a7775f9067ddadcca51fe7d32abee03d23a537970b4a1703b202a4d7d9c61b941fb8cb183817e9743d291e15c4c6d0db69e
6
+ metadata.gz: 980563a6d50454d8f7f4439b96a820423a77758ee0c20a8ea353439ddcf46a596cf2763cdd714b07530d63c71b539c50e18775aeba2639168ae0755920887dd8
7
+ data.tar.gz: af45e27dccdbe492ba950a6dbf29f9e3f0e4348aea8e689813cc5ed32fdd595250c2dbb689a7aa41890dcdaa33280321fb704b0e2e72975e6356631d030ae370
@@ -2,6 +2,7 @@
2
2
 
3
3
  #### Features
4
4
 
5
+ * [#686](https://github.com/ruby-grape/grape-swagger/pull/686): Allow response headers for responses with no content and for files - [@jdmurphy](https://github.com/jdmurphy).
5
6
  * Your contribution here.
6
7
 
7
8
  #### Fixes
@@ -200,6 +200,9 @@ module Grape
200
200
  codes.each_with_object({}) do |value, memo|
201
201
  value[:message] ||= ''
202
202
  memo[value[:code]] = { description: value[:message] }
203
+
204
+ memo[value[:code]][:headers] = value[:headers] if value[:headers]
205
+
203
206
  next build_file_response(memo[value[:code]]) if file_response?(value[:model])
204
207
 
205
208
  response_model = @item
@@ -217,7 +220,6 @@ module Grape
217
220
 
218
221
  memo[value[:code]][:schema] = build_reference(route, value, response_model)
219
222
  memo[value[:code]][:examples] = value[:examples] if value[:examples]
220
- memo[value[:code]][:headers] = value[:headers] if value[:headers]
221
223
  end
222
224
  end
223
225
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GrapeSwagger
4
- VERSION = '0.30.0'
4
+ VERSION = '0.30.1'
5
5
  end
@@ -18,6 +18,22 @@ describe 'response with headers' do
18
18
  { 'declared_params' => declared(params) }
19
19
  end
20
20
 
21
+ desc 'A 204 can have headers too' do
22
+ success Hash[status: 204, message: 'No content', headers: { 'Location' => { description: 'Location of resource', type: 'string' } }]
23
+ failure [[400, 'Bad Request', Entities::ApiError, { 'application/json' => { code: 400, message: 'Bad request' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
24
+ end
25
+ delete '/no_content_response_headers' do
26
+ { 'declared_params' => declared(params) }
27
+ end
28
+
29
+ desc 'A file can have headers too' do
30
+ success Hash[status: 200, model: 'File', headers: { 'Cache-Control' => { description: 'Directive for caching', type: 'string' } }]
31
+ failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
32
+ end
33
+ get '/file_response_headers' do
34
+ { 'declared_params' => declared(params) }
35
+ end
36
+
21
37
  desc 'This syntax also returns headers' do
22
38
  success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
23
39
  failure [
@@ -85,6 +101,66 @@ describe 'response with headers' do
85
101
  end
86
102
  end
87
103
 
104
+ describe 'no content response headers' do
105
+ let(:header_204) do
106
+ { 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
107
+ end
108
+ let(:header_400) do
109
+ { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
110
+ end
111
+ let(:examples_400) do
112
+ { 'application/json' => { 'code' => 400, 'message' => 'Bad request' } }
113
+ end
114
+
115
+ subject do
116
+ get '/swagger_doc/no_content_response_headers', {}
117
+ JSON.parse(last_response.body)
118
+ end
119
+
120
+ specify do
121
+ expect(subject['paths']['/no_content_response_headers']['delete']).to eql(
122
+ 'description' => 'A 204 can have headers too',
123
+ 'produces' => ['application/json'],
124
+ 'responses' => {
125
+ '204' => { 'description' => 'No content', 'headers' => header_204 },
126
+ '400' => { 'description' => 'Bad Request', 'headers' => header_400, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_400 }
127
+ },
128
+ 'tags' => ['no_content_response_headers'],
129
+ 'operationId' => 'deleteNoContentResponseHeaders'
130
+ )
131
+ end
132
+ end
133
+
134
+ describe 'file response headers' do
135
+ let(:header_200) do
136
+ { 'Cache-Control' => { 'description' => 'Directive for caching', 'type' => 'string' } }
137
+ end
138
+ let(:header_404) do
139
+ { 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
140
+ end
141
+ let(:examples_404) do
142
+ { 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
143
+ end
144
+
145
+ subject do
146
+ get '/swagger_doc/file_response_headers'
147
+ JSON.parse(last_response.body)
148
+ end
149
+
150
+ specify do
151
+ expect(subject['paths']['/file_response_headers']['get']).to eql(
152
+ 'description' => 'A file can have headers too',
153
+ 'produces' => ['application/json'],
154
+ 'responses' => {
155
+ '200' => { 'description' => 'A file can have headers too', 'headers' => header_200, 'schema' => { 'type' => 'file' } },
156
+ '404' => { 'description' => 'NotFound', 'headers' => header_404, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404 }
157
+ },
158
+ 'tags' => ['file_response_headers'],
159
+ 'operationId' => 'getFileResponseHeaders'
160
+ )
161
+ end
162
+ end
163
+
88
164
  describe 'response failure headers' do
89
165
  let(:header_200) do
90
166
  { 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-swagger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.30.0
4
+ version: 0.30.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Vandecasteele