Skip to content

Commit c956e6b

Browse files
authored
Merge pull request #2324 from dhruvCW/expose-default-in-desc
expose default in the description dsl.
2 parents 6145cd4 + b2c001d commit c956e6b

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [#2317](https://github.com/ruby-grape/grape/pull/2317): Remove maruku and rubocop-ast as direct development/testing dependencies - [@ericproulx](https://github.com/ericproulx).
1414
* [#2292](https://github.com/ruby-grape/grape/pull/2292): Introduce Docker to local development - [@ericproulx](https://github.com/ericproulx).
1515
* [#2325](https://github.com/ruby-grape/grape/pull/2325): Change edge test workflows only run on demand - [@dblock](https://github.com/dblock).
16+
* [#2324](https://github.com/ruby-grape/grape/pull/2324): Expose default in the description dsl - [@dhruvCW](https://github.com/dhruvCW).
1617
* Your contribution here.
1718

1819
#### Fixes

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ desc 'Returns your public timeline.' do
639639
params API::Entities::Status.documentation
640640
success API::Entities::Entity
641641
failure [[401, 'Unauthorized', 'Entities::Error']]
642+
default { code: 500, message: 'InvalidRequest', model: Entities::Error }
642643
named 'My named route'
643644
headers XAuthToken: {
644645
description: 'Validates your identity',
@@ -663,8 +664,9 @@ end
663664

664665
* `detail`: A more enhanced description
665666
* `params`: Define parameters directly from an `Entity`
666-
* `success`: (former entity) The `Entity` to be used to present by default this route
667-
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities
667+
* `success`: (former entity) The `Entity` to be used to present the success response for this route.
668+
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities.
669+
* `default`: The definition and `Entity` used to present the default response for this route.
668670
* `named`: A helper to give a route a name and find it with this name in the documentation Hash
669671
* `headers`: A definition of the used Headers
670672
* Other options can be found in [grape-swagger][grape-swagger]

lib/grape/dsl/desc.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ def desc_container(endpoint_configuration)
9898
:produces,
9999
:consumes,
100100
:security,
101-
:tags
101+
:tags,
102+
:default
102103
)
103104
config_context.define_singleton_method(:configuration) do
104105
endpoint_configuration

spec/grape/dsl/desc_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Dummy
2626
detail: 'more details',
2727
params: { first: :param },
2828
entity: Object,
29+
default: { code: 400, message: 'Invalid' },
2930
http_codes: [[401, 'Unauthorized', 'Entities::Error']],
3031
named: 'My named route',
3132
body_name: 'My body name',
@@ -54,6 +55,7 @@ class Dummy
5455
detail 'more details'
5556
params(first: :param)
5657
success Object
58+
default code: 400, message: 'Invalid'
5759
failure [[401, 'Unauthorized', 'Entities::Error']]
5860
named 'My named route'
5961
body_name 'My body name'

0 commit comments

Comments
 (0)