grape-swagger 0.29.0 → 0.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +11 -0
- data/Gemfile +2 -2
- data/README.md +57 -2
- data/lib/grape-swagger/doc_methods/move_params.rb +9 -2
- data/lib/grape-swagger/endpoint.rb +4 -2
- data/lib/grape-swagger/version.rb +1 -1
- data/spec/issues/680_keep_204_error_schemas_spec.rb +55 -0
- data/spec/lib/move_params_spec.rb +188 -0
- data/spec/spec_helper.rb +10 -8
- data/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +138 -0
- metadata +6 -3
- data/.document +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 329bb3676657055c5c086902b97ce065a4b7886d9de5ea5542e7874052ab92a9
|
4
|
+
data.tar.gz: 4290d2ea021d4cca08b5ba4a83033fa9df8476b79cc500d9d0de9476e1190f6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: abe0988e09f9fd987983977df65419230c04c60ef89ebb135921cf528c61c05e196873d3077db99b7540e94453929bc987e873c39f39f98adf70f77816f4fd75
|
7
|
+
data.tar.gz: 9530e8d9f2c2540ec167c8cbfe7a2a7775f9067ddadcca51fe7d32abee03d23a537970b4a1703b202a4d7d9c61b941fb8cb183817e9743d291e15c4c6d0db69e
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -8,6 +8,17 @@
|
|
8
8
|
|
9
9
|
* Your contribution here.
|
10
10
|
|
11
|
+
### 0.30.0 (July 19, 2018)
|
12
|
+
|
13
|
+
#### Features
|
14
|
+
|
15
|
+
* [#684](https://github.com/ruby-grape/grape-swagger/pull/684): Add response headers - [@jdmurphy](https://github.com/jdmurphy).
|
16
|
+
|
17
|
+
#### Fixes
|
18
|
+
|
19
|
+
* [#681](https://github.com/ruby-grape/grape-swagger/pull/681): Provide error schemas when an endpoint can return a 204 - [@adstratm](https://github.com/adstratm).
|
20
|
+
* [#683](https://github.com/ruby-grape/grape-swagger/pull/683): Fix handling of arrays of complex entities in params so that valid OpenAPI spec is generated - [@jdmurphy](https://github.com/jdmurphy).
|
21
|
+
|
11
22
|
### 0.29.0 (May 22, 2018)
|
12
23
|
|
13
24
|
#### Features
|
data/Gemfile
CHANGED
@@ -26,11 +26,11 @@ group :development, :test do
|
|
26
26
|
gem 'rake'
|
27
27
|
gem 'rdoc'
|
28
28
|
gem 'rspec', '~> 3.0'
|
29
|
-
gem 'rubocop', '~>0.
|
29
|
+
gem 'rubocop', '~> 0.58', require: false
|
30
30
|
end
|
31
31
|
|
32
32
|
group :test do
|
33
|
-
gem 'coveralls', require: false
|
33
|
+
gem 'coveralls', '~> 0.8', require: false
|
34
34
|
gem 'grape-swagger-entity'
|
35
35
|
gem 'ruby-grape-danger', '~> 0.1.1', require: false
|
36
36
|
gem 'simplecov', require: false
|
data/README.md
CHANGED
@@ -17,7 +17,7 @@
|
|
17
17
|
* [Routes Configuration](#routes)
|
18
18
|
* [Using Grape Entities](#grape-entity)
|
19
19
|
* [Securing the Swagger UI](#oauth)
|
20
|
-
* [
|
20
|
+
* [Example](#example)
|
21
21
|
* [Rake Tasks](#rake)
|
22
22
|
|
23
23
|
|
@@ -398,6 +398,7 @@ A hash merged into the `info` key of the JSON documentation.
|
|
398
398
|
* [File response](#file-response)
|
399
399
|
* [Extensions](#extensions)
|
400
400
|
* [Response examples documentation](#response-examples)
|
401
|
+
* [Response headers documentation](#response-headers)
|
401
402
|
|
402
403
|
#### Swagger Header Parameters <a name="headers" />
|
403
404
|
|
@@ -1037,6 +1038,60 @@ The result will look like following:
|
|
1037
1038
|
|
1038
1039
|
Failure information can be passed as an array of arrays or an array of hashes.
|
1039
1040
|
|
1041
|
+
#### Response headers documentation <a name="response-headers" />
|
1042
|
+
|
1043
|
+
You can also add header information to your responses by using the `desc` DSL with block syntax.
|
1044
|
+
|
1045
|
+
By specifying headers to `success` and `failure`.
|
1046
|
+
|
1047
|
+
```ruby
|
1048
|
+
desc 'This returns headers' do
|
1049
|
+
success model: Thing, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
|
1050
|
+
failure [[404, 'NotFound', ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
|
1051
|
+
end
|
1052
|
+
get '/thing' do
|
1053
|
+
...
|
1054
|
+
end
|
1055
|
+
```
|
1056
|
+
|
1057
|
+
The result will look like following:
|
1058
|
+
|
1059
|
+
```json
|
1060
|
+
"responses": {
|
1061
|
+
"200": {
|
1062
|
+
"description": "This returns examples",
|
1063
|
+
"schema": {
|
1064
|
+
"$ref": "#/definitions/Thing"
|
1065
|
+
},
|
1066
|
+
"headers": {
|
1067
|
+
"Location": {
|
1068
|
+
"description": "Location of resource",
|
1069
|
+
"type": "string"
|
1070
|
+
}
|
1071
|
+
}
|
1072
|
+
},
|
1073
|
+
"404": {
|
1074
|
+
"description": "NotFound",
|
1075
|
+
"schema": {
|
1076
|
+
"$ref": "#/definitions/ApiError"
|
1077
|
+
},
|
1078
|
+
"examples": {
|
1079
|
+
"application/json": {
|
1080
|
+
"code": 404,
|
1081
|
+
"message": "Not found"
|
1082
|
+
}
|
1083
|
+
},
|
1084
|
+
"headers": {
|
1085
|
+
"Date": {
|
1086
|
+
"description": "Date of failure",
|
1087
|
+
"type": "string"
|
1088
|
+
}
|
1089
|
+
}
|
1090
|
+
}
|
1091
|
+
}
|
1092
|
+
```
|
1093
|
+
|
1094
|
+
Failure information can be passed as an array of arrays or an array of hashes.
|
1040
1095
|
|
1041
1096
|
## Using Grape Entities <a name="grape-entity" />
|
1042
1097
|
|
@@ -1229,7 +1284,7 @@ role - only admins can see this endpoint.
|
|
1229
1284
|
|
1230
1285
|
|
1231
1286
|
|
1232
|
-
##
|
1287
|
+
## Example <a name="example" />
|
1233
1288
|
|
1234
1289
|
Go into example directory and run it: `$ bundle exec rackup`
|
1235
1290
|
go to: `http://localhost:9292/swagger_doc` to get it
|
@@ -177,9 +177,16 @@ module GrapeSwagger
|
|
177
177
|
def prepare_nested_types(params)
|
178
178
|
params.each do |param|
|
179
179
|
next unless param[:items]
|
180
|
-
|
180
|
+
|
181
|
+
param[:type] = if param[:items][:type] == 'array'
|
182
|
+
'string'
|
183
|
+
elsif param[:items].key?('$ref')
|
184
|
+
param[:type] = 'object'
|
185
|
+
else
|
186
|
+
param[:items][:type]
|
187
|
+
end
|
181
188
|
param[:format] = param[:items][:format] if param[:items][:format]
|
182
|
-
param.delete(:items)
|
189
|
+
param.delete(:items) if param[:type] != 'object'
|
183
190
|
end
|
184
191
|
end
|
185
192
|
|
@@ -195,7 +195,7 @@ module Grape
|
|
195
195
|
|
196
196
|
def response_object(route)
|
197
197
|
codes = http_codes_from_route(route)
|
198
|
-
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2], examples: x[3] } : x }
|
198
|
+
codes.map! { |x| x.is_a?(Array) ? { code: x[0], message: x[1], model: x[2], examples: x[3], headers: x[4] } : x }
|
199
199
|
|
200
200
|
codes.each_with_object({}) do |value, memo|
|
201
201
|
value[:message] ||= ''
|
@@ -210,13 +210,14 @@ module Grape
|
|
210
210
|
value[:code] = 204
|
211
211
|
end
|
212
212
|
|
213
|
-
next if
|
213
|
+
next if value[:code] == 204
|
214
214
|
next unless !response_model.start_with?('Swagger_doc') && (@definitions[response_model] || value[:model])
|
215
215
|
|
216
216
|
@definitions[response_model][:description] = description_object(route)
|
217
217
|
|
218
218
|
memo[value[:code]][:schema] = build_reference(route, value, response_model)
|
219
219
|
memo[value[:code]][:examples] = value[:examples] if value[:examples]
|
220
|
+
memo[value[:code]][:headers] = value[:headers] if value[:headers]
|
220
221
|
end
|
221
222
|
end
|
222
223
|
|
@@ -240,6 +241,7 @@ module Grape
|
|
240
241
|
default_code[:model] = @entity[:model] if @entity[:model].present?
|
241
242
|
default_code[:message] = @entity[:message] || route.description || default_code[:message].sub('{item}', @item)
|
242
243
|
default_code[:examples] = @entity[:examples] if @entity[:examples]
|
244
|
+
default_code[:headers] = @entity[:headers] if @entity[:headers]
|
243
245
|
else
|
244
246
|
default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
|
245
247
|
default_code[:model] = @entity if @entity
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'when the main endpoint response is a 204 all error schemas are lost' do
|
6
|
+
let(:app) do
|
7
|
+
Class.new(Grape::API) do
|
8
|
+
namespace :issue_680 do
|
9
|
+
desc 'delete something',
|
10
|
+
is_array: true,
|
11
|
+
success: { status: 204 },
|
12
|
+
failure: [
|
13
|
+
[401, 'Unauthorized', Entities::ApiError],
|
14
|
+
[403, 'Forbidden', Entities::ApiError],
|
15
|
+
[404, 'Not Found', Entities::ApiError]
|
16
|
+
]
|
17
|
+
|
18
|
+
delete do
|
19
|
+
status 204
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
add_swagger_documentation format: :json
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
subject do
|
28
|
+
get '/swagger_doc'
|
29
|
+
JSON.parse(last_response.body)
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when an endpoint can return a 204' do
|
33
|
+
let(:responses) { subject['paths']['/issue_680']['delete']['responses'] }
|
34
|
+
|
35
|
+
it 'returns the description but not a schema for a 204 response' do
|
36
|
+
expect(responses['204']['description']).to eq('delete something')
|
37
|
+
expect(responses['204']['schema']).to be_nil
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'returns a description AND a schema for a 401 response' do
|
41
|
+
expect(responses['401']['description']).to eq('Unauthorized')
|
42
|
+
expect(responses['401']['schema']).to_not be_nil
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns a description AND a schema for a 403 response' do
|
46
|
+
expect(responses['403']['description']).to eq('Forbidden')
|
47
|
+
expect(responses['403']['schema']).to_not be_nil
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'returns a description AND a schema for a 404 response' do
|
51
|
+
expect(responses['404']['description']).to eq('Not Found')
|
52
|
+
expect(responses['404']['schema']).to_not be_nil
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -325,5 +325,193 @@ describe GrapeSwagger::DocMethods::MoveParams do
|
|
325
325
|
it { expect(params).to eql expected_params }
|
326
326
|
end
|
327
327
|
end
|
328
|
+
|
329
|
+
describe 'prepare_nested_types' do
|
330
|
+
before :each do
|
331
|
+
subject.send(:prepare_nested_types, params)
|
332
|
+
end
|
333
|
+
|
334
|
+
let(:params) do
|
335
|
+
[
|
336
|
+
{
|
337
|
+
in: 'body',
|
338
|
+
name: 'address[street_lines]',
|
339
|
+
description: 'street lines',
|
340
|
+
type: 'array',
|
341
|
+
items: {
|
342
|
+
type: 'string'
|
343
|
+
},
|
344
|
+
required: true
|
345
|
+
}
|
346
|
+
]
|
347
|
+
end
|
348
|
+
|
349
|
+
context 'when params contains nothing with :items key' do
|
350
|
+
let(:params) do
|
351
|
+
[
|
352
|
+
{
|
353
|
+
in: 'body',
|
354
|
+
name: 'phone_number',
|
355
|
+
description: 'phone number',
|
356
|
+
type: 'string',
|
357
|
+
required: true
|
358
|
+
}
|
359
|
+
]
|
360
|
+
end
|
361
|
+
|
362
|
+
let(:expected_params) do
|
363
|
+
[
|
364
|
+
{
|
365
|
+
in: 'body',
|
366
|
+
name: 'phone_number',
|
367
|
+
description: 'phone number',
|
368
|
+
type: 'string',
|
369
|
+
required: true
|
370
|
+
}
|
371
|
+
]
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'does nothing' do
|
375
|
+
expect(params).to eq expected_params
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
context 'when params contains :items key with array type' do
|
380
|
+
let(:params) do
|
381
|
+
[
|
382
|
+
{
|
383
|
+
in: 'body',
|
384
|
+
name: 'address_street_lines',
|
385
|
+
description: 'street lines',
|
386
|
+
type: 'array',
|
387
|
+
items: {
|
388
|
+
type: 'array'
|
389
|
+
},
|
390
|
+
required: true
|
391
|
+
}
|
392
|
+
]
|
393
|
+
end
|
394
|
+
|
395
|
+
let(:expected_params) do
|
396
|
+
[
|
397
|
+
{
|
398
|
+
in: 'body',
|
399
|
+
name: 'address_street_lines',
|
400
|
+
description: 'street lines',
|
401
|
+
type: 'string',
|
402
|
+
required: true
|
403
|
+
}
|
404
|
+
]
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'sets type to string and removes :items' do
|
408
|
+
expect(params).to eq expected_params
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
context 'when params contains :items key with $ref' do
|
413
|
+
let(:params) do
|
414
|
+
[
|
415
|
+
{
|
416
|
+
in: 'body',
|
417
|
+
name: 'address_street_lines',
|
418
|
+
description: 'street lines',
|
419
|
+
type: 'array',
|
420
|
+
items: {
|
421
|
+
'$ref' => '#/definitions/StreetLine'
|
422
|
+
},
|
423
|
+
required: true
|
424
|
+
}
|
425
|
+
]
|
426
|
+
end
|
427
|
+
|
428
|
+
let(:expected_params) do
|
429
|
+
[
|
430
|
+
{
|
431
|
+
in: 'body',
|
432
|
+
name: 'address_street_lines',
|
433
|
+
description: 'street lines',
|
434
|
+
type: 'object',
|
435
|
+
items: {
|
436
|
+
'$ref' => '#/definitions/StreetLine'
|
437
|
+
},
|
438
|
+
required: true
|
439
|
+
}
|
440
|
+
]
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'sets type to object and does not remove :items' do
|
444
|
+
expect(params).to eq expected_params
|
445
|
+
end
|
446
|
+
end
|
447
|
+
|
448
|
+
context 'when params contains :items without $ref or array type' do
|
449
|
+
let(:params) do
|
450
|
+
[
|
451
|
+
{
|
452
|
+
in: 'body',
|
453
|
+
name: 'address_street_lines',
|
454
|
+
description: 'street lines',
|
455
|
+
type: 'array',
|
456
|
+
items: {
|
457
|
+
type: 'string'
|
458
|
+
},
|
459
|
+
required: true
|
460
|
+
}
|
461
|
+
]
|
462
|
+
end
|
463
|
+
|
464
|
+
let(:expected_params) do
|
465
|
+
[
|
466
|
+
{
|
467
|
+
in: 'body',
|
468
|
+
name: 'address_street_lines',
|
469
|
+
description: 'street lines',
|
470
|
+
type: 'string',
|
471
|
+
required: true
|
472
|
+
}
|
473
|
+
]
|
474
|
+
end
|
475
|
+
|
476
|
+
it 'sets type to :items :type and removes :items' do
|
477
|
+
expect(params).to eq expected_params
|
478
|
+
end
|
479
|
+
end
|
480
|
+
|
481
|
+
context 'when params contains :items key with :format' do
|
482
|
+
let(:params) do
|
483
|
+
[
|
484
|
+
{
|
485
|
+
in: 'body',
|
486
|
+
name: 'street_number',
|
487
|
+
description: 'street number',
|
488
|
+
type: 'array',
|
489
|
+
items: {
|
490
|
+
type: 'integer',
|
491
|
+
format: 'int32'
|
492
|
+
},
|
493
|
+
required: true
|
494
|
+
}
|
495
|
+
]
|
496
|
+
end
|
497
|
+
|
498
|
+
let(:expected_params) do
|
499
|
+
[
|
500
|
+
{
|
501
|
+
in: 'body',
|
502
|
+
name: 'street_number',
|
503
|
+
description: 'street number',
|
504
|
+
type: 'integer',
|
505
|
+
format: 'int32',
|
506
|
+
required: true
|
507
|
+
}
|
508
|
+
]
|
509
|
+
end
|
510
|
+
|
511
|
+
it 'sets format and removes :items' do
|
512
|
+
expect(params).to eq expected_params
|
513
|
+
end
|
514
|
+
end
|
515
|
+
end
|
328
516
|
end
|
329
517
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require '
|
5
|
-
|
6
|
-
|
7
|
-
SimpleCov.
|
8
|
-
|
9
|
-
|
3
|
+
if RUBY_ENGINE == 'ruby'
|
4
|
+
require 'simplecov'
|
5
|
+
require 'coveralls'
|
6
|
+
|
7
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter 'spec/'
|
10
|
+
add_filter 'example/'
|
11
|
+
end
|
12
|
+
Coveralls.wear!
|
10
13
|
end
|
11
|
-
Coveralls.wear!
|
12
14
|
|
13
15
|
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
14
16
|
|
@@ -0,0 +1,138 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe 'response with headers' do
|
6
|
+
# include_context "#{MODEL_PARSER} swagger header"
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
module TheApi
|
10
|
+
class ResponseApiHeaders < Grape::API
|
11
|
+
format :json
|
12
|
+
|
13
|
+
desc 'This returns headers' do
|
14
|
+
success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
|
15
|
+
failure [[404, 'NotFound', Entities::ApiError, { 'application/json' => { code: 404, message: 'Not found' } }, { 'Date' => { description: 'Date of failure', type: 'string' } }]]
|
16
|
+
end
|
17
|
+
get '/response_headers' do
|
18
|
+
{ 'declared_params' => declared(params) }
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'This syntax also returns headers' do
|
22
|
+
success model: Entities::UseResponse, headers: { 'Location' => { description: 'Location of resource', type: 'string' } }
|
23
|
+
failure [
|
24
|
+
{
|
25
|
+
code: 404,
|
26
|
+
message: 'NotFound',
|
27
|
+
model: Entities::ApiError,
|
28
|
+
headers: { 'Date' => { description: 'Date of failure', type: 'string' } }
|
29
|
+
},
|
30
|
+
{
|
31
|
+
code: 400,
|
32
|
+
message: 'BadRequest',
|
33
|
+
model: Entities::ApiError,
|
34
|
+
headers: { 'Date' => { description: 'Date of failure', type: 'string' } }
|
35
|
+
}
|
36
|
+
]
|
37
|
+
end
|
38
|
+
get '/response_failure_headers' do
|
39
|
+
{ 'declared_params' => declared(params) }
|
40
|
+
end
|
41
|
+
|
42
|
+
desc 'This does not return headers' do
|
43
|
+
success model: Entities::UseResponse
|
44
|
+
failure [[404, 'NotFound', Entities::ApiError]]
|
45
|
+
end
|
46
|
+
get '/response_no_headers' do
|
47
|
+
{ 'declared_params' => declared(params) }
|
48
|
+
end
|
49
|
+
add_swagger_documentation
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def app
|
55
|
+
TheApi::ResponseApiHeaders
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'response headers' do
|
59
|
+
let(:header_200) do
|
60
|
+
{ 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
|
61
|
+
end
|
62
|
+
let(:header_404) do
|
63
|
+
{ 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
|
64
|
+
end
|
65
|
+
let(:examples_404) do
|
66
|
+
{ 'application/json' => { 'code' => 404, 'message' => 'Not found' } }
|
67
|
+
end
|
68
|
+
|
69
|
+
subject do
|
70
|
+
get '/swagger_doc/response_headers'
|
71
|
+
JSON.parse(last_response.body)
|
72
|
+
end
|
73
|
+
|
74
|
+
specify do
|
75
|
+
expect(subject['paths']['/response_headers']['get']).to eql(
|
76
|
+
'description' => 'This returns headers',
|
77
|
+
'produces' => ['application/json'],
|
78
|
+
'responses' => {
|
79
|
+
'200' => { 'description' => 'This returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
|
80
|
+
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404, 'headers' => header_404 }
|
81
|
+
},
|
82
|
+
'tags' => ['response_headers'],
|
83
|
+
'operationId' => 'getResponseHeaders'
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'response failure headers' do
|
89
|
+
let(:header_200) do
|
90
|
+
{ 'Location' => { 'description' => 'Location of resource', 'type' => 'string' } }
|
91
|
+
end
|
92
|
+
let(:header_404) do
|
93
|
+
{ 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
|
94
|
+
end
|
95
|
+
let(:header_400) do
|
96
|
+
{ 'Date' => { 'description' => 'Date of failure', 'type' => 'string' } }
|
97
|
+
end
|
98
|
+
|
99
|
+
subject do
|
100
|
+
get '/swagger_doc/response_failure_headers'
|
101
|
+
JSON.parse(last_response.body)
|
102
|
+
end
|
103
|
+
|
104
|
+
specify do
|
105
|
+
expect(subject['paths']['/response_failure_headers']['get']).to eql(
|
106
|
+
'description' => 'This syntax also returns headers',
|
107
|
+
'produces' => ['application/json'],
|
108
|
+
'responses' => {
|
109
|
+
'200' => { 'description' => 'This syntax also returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
|
110
|
+
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_404 },
|
111
|
+
'400' => { 'description' => 'BadRequest', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_400 }
|
112
|
+
},
|
113
|
+
'tags' => ['response_failure_headers'],
|
114
|
+
'operationId' => 'getResponseFailureHeaders'
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe 'response no headers' do
|
120
|
+
subject do
|
121
|
+
get '/swagger_doc/response_no_headers'
|
122
|
+
JSON.parse(last_response.body)
|
123
|
+
end
|
124
|
+
|
125
|
+
specify do
|
126
|
+
expect(subject['paths']['/response_no_headers']['get']).to eql(
|
127
|
+
'description' => 'This does not return headers',
|
128
|
+
'produces' => ['application/json'],
|
129
|
+
'responses' => {
|
130
|
+
'200' => { 'description' => 'This does not return headers', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
|
131
|
+
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
|
132
|
+
},
|
133
|
+
'tags' => ['response_no_headers'],
|
134
|
+
'operationId' => 'getResponseNoHeaders'
|
135
|
+
)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-swagger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.30.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Vandecasteele
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grape
|
@@ -32,7 +32,6 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- ".coveralls.yml"
|
35
|
-
- ".document"
|
36
35
|
- ".gitignore"
|
37
36
|
- ".rspec"
|
38
37
|
- ".rubocop.yml"
|
@@ -91,6 +90,7 @@ files:
|
|
91
90
|
- spec/issues/587_range_parameter_delimited_by_dash_spec.rb
|
92
91
|
- spec/issues/605_root_route_documentation_spec.rb
|
93
92
|
- spec/issues/650_params_array_spec.rb
|
93
|
+
- spec/issues/680_keep_204_error_schemas_spec.rb
|
94
94
|
- spec/lib/data_type_spec.rb
|
95
95
|
- spec/lib/endpoint_spec.rb
|
96
96
|
- spec/lib/extensions_spec.rb
|
@@ -131,6 +131,7 @@ files:
|
|
131
131
|
- spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb
|
132
132
|
- spec/swagger_v2/api_swagger_v2_response_spec.rb
|
133
133
|
- spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
|
134
|
+
- spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
|
134
135
|
- spec/swagger_v2/api_swagger_v2_spec.rb
|
135
136
|
- spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
|
136
137
|
- spec/swagger_v2/api_swagger_v2_type-format_spec.rb
|
@@ -207,6 +208,7 @@ test_files:
|
|
207
208
|
- spec/issues/587_range_parameter_delimited_by_dash_spec.rb
|
208
209
|
- spec/issues/605_root_route_documentation_spec.rb
|
209
210
|
- spec/issues/650_params_array_spec.rb
|
211
|
+
- spec/issues/680_keep_204_error_schemas_spec.rb
|
210
212
|
- spec/lib/data_type_spec.rb
|
211
213
|
- spec/lib/endpoint_spec.rb
|
212
214
|
- spec/lib/extensions_spec.rb
|
@@ -247,6 +249,7 @@ test_files:
|
|
247
249
|
- spec/swagger_v2/api_swagger_v2_request_params_fix_spec.rb
|
248
250
|
- spec/swagger_v2/api_swagger_v2_response_spec.rb
|
249
251
|
- spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
|
252
|
+
- spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
|
250
253
|
- spec/swagger_v2/api_swagger_v2_spec.rb
|
251
254
|
- spec/swagger_v2/api_swagger_v2_status_codes_spec.rb
|
252
255
|
- spec/swagger_v2/api_swagger_v2_type-format_spec.rb
|