Skip to content

Commit 89c4d2c

Browse files
committed
Support more options in desc blockFix ruby-grape#1789.Support summary, hidden, deprecated, is_array, nickname,produces, consumes, tags options in desc block.
1 parent 41b7519 commit 89c4d2c

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Features
44

55
* Your contribution here.
6+
* [#1791](https://github.com/ruby-grape/grape/pull/1791): Support more options in desc block - [@darren987469](https://github.com/darren987469).
67

78
#### Fixes
89

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,10 +446,13 @@ version 'v1', using: :param, parameter: 'v'
446446

447447
## Describing Methods
448448

449-
You can add a description to API methods and namespaces.
449+
You can add a description to API methods and namespaces. The description would be used by [grape-swagger][grape-swagger] to generate swagger compliant documentation.
450+
451+
Note: Description block is only for documentation and won't affects API behavior.
450452

451453
```ruby
452454
desc 'Returns your public timeline.' do
455+
summary 'summary'
453456
detail 'more details'
454457
params API::Entities::Status.documentation
455458
success API::Entities::Entity
@@ -463,7 +466,13 @@ desc 'Returns your public timeline.' do
463466
description: 'Not really needed',
464467
required: false
465468
}
466-
469+
hidden false
470+
deprecated false
471+
is_array true
472+
nickname 'nickname'
473+
produces ['array', 'of', 'mime_types']
474+
consumes ['array', 'of', 'mime_types']
475+
tags ['tag1', 'tag2']
467476
end
468477
get :public_timeline do
469478
Status.limit(20)
@@ -476,6 +485,9 @@ end
476485
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities
477486
* `named`: A helper to give a route a name and find it with this name in the documentation Hash
478487
* `headers`: A definition of the used Headers
488+
* Other options can be found in [grape-swagger][grape-swagger]
489+
490+
[grape-swagger]: https://github.com/ruby-grape/grape-swagger
479491

480492
## Parameters
481493

lib/grape/dsl/desc.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,21 @@ def unset_description_field(field)
7878
def desc_container
7979
Module.new do
8080
include Grape::Util::StrictHashConfiguration.module(
81+
:summary,
8182
:description,
8283
:detail,
8384
:params,
8485
:entity,
8586
:http_codes,
8687
:named,
87-
:headers
88+
:headers,
89+
:hidden,
90+
:deprecated,
91+
:is_array,
92+
:nickname,
93+
:produces,
94+
:consumes,
95+
:tags
8896
)
8997

9098
def config_context.success(*args)

spec/grape/dsl/desc_spec.rb

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Dummy
2121

2222
it 'can be set with a block' do
2323
expected_options = {
24+
summary: 'summary',
2425
description: 'The description',
2526
detail: 'more details',
2627
params: { first: :param },
@@ -34,10 +35,18 @@ class Dummy
3435
XOptionalHeader: {
3536
description: 'Not really needed',
3637
required: false
37-
}]
38+
}],
39+
hidden: false,
40+
deprecated: false,
41+
is_array: true,
42+
nickname: 'nickname',
43+
produces: ['array', 'of', 'mime_types'],
44+
consumes: ['array', 'of', 'mime_types'],
45+
tags: ['tag1', 'tag2']
3846
}
3947

4048
subject.desc 'The description' do
49+
summary 'summary'
4150
detail 'more details'
4251
params(first: :param)
4352
success Object
@@ -51,6 +60,13 @@ class Dummy
5160
description: 'Not really needed',
5261
required: false
5362
}]
63+
hidden false
64+
deprecated false
65+
is_array true
66+
nickname 'nickname'
67+
produces ['array', 'of', 'mime_types']
68+
consumes ['array', 'of', 'mime_types']
69+
tags ['tag1', 'tag2']
5470
end
5571

5672
expect(subject.namespace_setting(:description)).to eq(expected_options)

0 commit comments

Comments
 (0)