Skip to content

Commit

Permalink
Merge pull request #2324 from dhruvCW/expose-default-in-desc
Browse files Browse the repository at this point in the history
expose default in the description dsl.
  • Loading branch information
dblock committed May 9, 2023
2 parents 6145cd4 + b2c001d commit c956e6b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
* [#2317](https://github.com/ruby-grape/grape/pull/2317): Remove maruku and rubocop-ast as direct development/testing dependencies - [@ericproulx](https://github.com/ericproulx).
* [#2292](https://github.com/ruby-grape/grape/pull/2292): Introduce Docker to local development - [@ericproulx](https://github.com/ericproulx).
* [#2325](https://github.com/ruby-grape/grape/pull/2325): Change edge test workflows only run on demand - [@dblock](https://github.com/dblock).
* [#2324](https://github.com/ruby-grape/grape/pull/2324): Expose default in the description dsl - [@dhruvCW](https://github.com/dhruvCW).
* Your contribution here.

#### Fixes
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ desc 'Returns your public timeline.' do
params API::Entities::Status.documentation
success API::Entities::Entity
failure [[401, 'Unauthorized', 'Entities::Error']]
default { code: 500, message: 'InvalidRequest', model: Entities::Error }
named 'My named route'
headers XAuthToken: {
description: 'Validates your identity',
Expand All @@ -663,8 +664,9 @@ end

* `detail`: A more enhanced description
* `params`: Define parameters directly from an `Entity`
* `success`: (former entity) The `Entity` to be used to present by default this route
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities
* `success`: (former entity) The `Entity` to be used to present the success response for this route.
* `failure`: (former http_codes) A definition of the used failure HTTP Codes and Entities.
* `default`: The definition and `Entity` used to present the default response for this route.
* `named`: A helper to give a route a name and find it with this name in the documentation Hash
* `headers`: A definition of the used Headers
* Other options can be found in [grape-swagger][grape-swagger]
Expand Down
3 changes: 2 additions & 1 deletion lib/grape/dsl/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def desc_container(endpoint_configuration)
:produces,
:consumes,
:security,
:tags
:tags,
:default
)
config_context.define_singleton_method(:configuration) do
endpoint_configuration
Expand Down
2 changes: 2 additions & 0 deletions spec/grape/dsl/desc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Dummy
detail: 'more details',
params: { first: :param },
entity: Object,
default: { code: 400, message: 'Invalid' },
http_codes: [[401, 'Unauthorized', 'Entities::Error']],
named: 'My named route',
body_name: 'My body name',
Expand Down Expand Up @@ -54,6 +55,7 @@ class Dummy
detail 'more details'
params(first: :param)
success Object
default code: 400, message: 'Invalid'
failure [[401, 'Unauthorized', 'Entities::Error']]
named 'My named route'
body_name 'My body name'
Expand Down

0 comments on commit c956e6b

Please sign in to comment.