Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support security in desc block #1831

Merged
merged 4 commits into from
Dec 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#### Fixes

* Your contribution here.
* [#1831](https://github.com/ruby-grape/grape/pull/1831): Support security in desc block - [@fotos](https://github.com/fotos).
* [#1830](https://github.com/ruby-grape/grape/pull/1830): Restores self_sanity addresses #1829 - [@myxoh](https://github.com/myxoh).

### 1.2.1 (2018/11/28)
Expand Down
4 changes: 3 additions & 1 deletion lib/grape/dsl/desc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ module Desc
include Grape::DSL::Settings

# Add a description to the next namespace or function.
# @option options :summary [String] summary for this endpoint
# @param description [String] descriptive string for this endpoint
# or namespace
# @param options [Hash] other properties you can set to describe the
# endpoint or namespace. Optional.
# @option options :detail [String] additional detail about this endpoint
# @option options :summary [String] summary for this endpoint
# @option options :params [Hash] param types and info. normally, you set
# these via the `params` dsl method.
# @option options :entity [Grape::Entity] the entity returned upon a
Expand All @@ -24,6 +24,7 @@ module Desc
# @option options :nickname [String] nickname of the endpoint
# @option options :produces [Array[String]] a list of MIME types the endpoint produce
# @option options :consumes [Array[String]] a list of MIME types the endpoint consume
# @option options :security [Array[Hash]] a list of security schemes
# @option options :tags [Array[String]] a list of tags
# @yield a block yielding an instance context with methods mapping to
# each of the above, except that :entity is also aliased as #success
Expand Down Expand Up @@ -100,6 +101,7 @@ def desc_container
:nickname,
:produces,
:consumes,
:security,
:tags
)

Expand Down
40 changes: 23 additions & 17 deletions spec/grape/dsl/desc_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,24 @@ class Dummy
entity: Object,
http_codes: [[401, 'Unauthorized', 'Entities::Error']],
named: 'My named route',
headers: [XAuthToken: {
description: 'Valdates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}],
headers: [
XAuthToken: {
description: 'Valdates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}
],
hidden: false,
deprecated: false,
is_array: true,
nickname: 'nickname',
produces: %w[array of mime_types],
consumes: %w[array of mime_types],
tags: %w[tag1 tag2]
tags: %w[tag1 tag2],
security: %w[array of security schemes]
}

subject.desc 'The description' do
Expand All @@ -52,21 +55,24 @@ class Dummy
success Object
failure [[401, 'Unauthorized', 'Entities::Error']]
named 'My named route'
headers [XAuthToken: {
description: 'Valdates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}]
headers [
XAuthToken: {
description: 'Valdates your identity',
required: true
},
XOptionalHeader: {
description: 'Not really needed',
required: false
}
]
hidden false
deprecated false
is_array true
nickname 'nickname'
produces %w[array of mime_types]
consumes %w[array of mime_types]
tags %w[tag1 tag2]
security %w[array of security schemes]
end

expect(subject.namespace_setting(:description)).to eq(expected_options)
Expand Down