Skip to content

Commit fdb02c4

Browse files
author
Sunny Juneja
committed
Check for authorization header.
It appears that Swagger-UI correctly sets an authorization header when added in the interface (api key field). However, if the endpoint has the option "authorizations" set with "oauth2", it will override the value. See #13.
1 parent c7a512e commit fdb02c4

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

spec/dummy/app/api/api.rb

+5
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,10 @@ class API < Grape::API
2626
request.params.as_json
2727
end
2828

29+
desc 'Get Authorization header.', authorizations: { oauth2: [] }
30+
get '/authorization' do
31+
request.headers.slice('Authorization').as_json
32+
end
33+
2934
add_swagger_documentation
3035
end
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
GrapeSwaggerRails.options.url = '/api/swagger_doc'
22
GrapeSwaggerRails.options.app_name = 'Swagger'
33
GrapeSwaggerRails.options.app_url = 'http://localhost:3000'
4+
GrapeSwaggerRails.options.api_auth = 'bearer'
5+
GrapeSwaggerRails.options.api_key_name = 'Authorization'
6+
GrapeSwaggerRails.options.api_key_type = 'header'

spec/features/swagger_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
it 'adds an Authorization header' do
5050
page.execute_script("$('#input_apiKey').val('username:password')")
5151
page.execute_script("$('#input_apiKey').trigger('change')")
52-
find('#endpointListTogger_headers', visible: true).click
53-
first('a[href="#!/headers/GET_api_headers_format"]', visible: true).click
52+
find('#endpointListTogger_authorization', visible: true).click
53+
first('a[href="#!/authorization/GET_api_authorization_format"]', visible: true).click
5454
click_button 'Try it out!'
5555
expect(page).to have_css 'span.attribute', text: 'Authorization'
5656
expect(page).to have_css 'span.string', text: "Basic #{Base64.encode64('username:password').strip}"
@@ -66,8 +66,8 @@
6666
it 'adds an Authorization header' do
6767
page.execute_script("$('#input_apiKey').val('token')")
6868
page.execute_script("$('#input_apiKey').trigger('change')")
69-
find('#endpointListTogger_headers', visible: true).click
70-
first('a[href="#!/headers/GET_api_headers_format"]', visible: true).click
69+
find('#endpointListTogger_authorization', visible: true).click
70+
first('a[href="#!/authorization/GET_api_authorization_format"]', visible: true).click
7171
click_button 'Try it out!'
7272
expect(page).to have_css 'span.attribute', text: 'Authorization'
7373
expect(page).to have_css 'span.string', text: 'Bearer token'

0 commit comments

Comments
 (0)