grape-swagger 0.30.0 → 0.30.1
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cc4d92b47209a6323502fd863a738a8829e0d78b599a47e83a1aa9e52746cf7
|
4
|
+
data.tar.gz: cbc408aaf0f686032312bdfb3332671d73341e90eeff694162f2d0bdcfc14a81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 980563a6d50454d8f7f4439b96a820423a77758ee0c20a8ea353439ddcf46a596cf2763cdd714b07530d63c71b539c50e18775aeba2639168ae0755920887dd8
|
7
|
+
data.tar.gz: af45e27dccdbe492ba950a6dbf29f9e3f0e4348aea8e689813cc5ed32fdd595250c2dbb689a7aa41890dcdaa33280321fb704b0e2e72975e6356631d030ae370
|
data/CHANGELOG.md
CHANGED
@@ -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
|
|
@@ -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' } }
|