Skip to content
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 @@
* [#31](https://github.com/ruby-grape/grape-swagger-rails/pull/31): Support Swagger-UI docExpansion option - [@maruware](https://github.com/maruware).
* [#32](https://github.com/ruby-grape/grape-swagger-rails/pull/32): Fix Ruby 1.9.3 compatibility - [@suan](https://github.com/suan).
* [#39](https://github.com/ruby-grape/grape-swagger-rails/pull/39): Support CSS media queries - [@alexagranov](https://github.com/alexagranov).
* [#42](https://github.com/ruby-grape/grape-swagger-rails/pull/42): Headers added on swaggerUi initialization (before swaggerUi.load() call) - [@sedx](https://github.com/sedx).
* Your contribution here.

### 0.1.0 (February 5, 2015)
Expand Down
9 changes: 6 additions & 3 deletions app/views/grape_swagger_rails/application/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
$(function () {
var options = $("html").data('swagger-options');

var headers = {};
<% GrapeSwaggerRails.options.headers.each_with_index do |(key, value), index| %>
<%=raw "headers.header_#{index} = new SwaggerClient.ApiKeyAuthorization('#{CGI.escapeHTML(key)}', '#{CGI.escapeHTML(value)}', 'header');" %>
<% end %>

window.swaggerUi = new SwaggerUi({
url: options.app_url + options.url,
dom_id: "swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
authorizations: headers,
onComplete: function(swaggerApi, swaggerUi){
if('console' in window) {
console.log("Loaded SwaggerUI")
Expand Down Expand Up @@ -50,9 +56,6 @@

window.swaggerUi.load();

<% GrapeSwaggerRails.options.headers.each_with_index do |(key, value), index| %>
<%=raw "window.swaggerUi.api.clientAuthorizations.add('header_#{index}', new SwaggerClient.ApiKeyAuthorization('#{CGI.escapeHTML(key)}', '#{CGI.escapeHTML(value)}', 'header'));" %>
<% end %>
});
</script>
</head>
Expand Down
3 changes: 3 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
visit '/swagger'
end
it 'adds headers' do
headers = page.evaluate_script('swaggerUi.api.clientAuthorizations')['authz']
expect(headers.select { |key| key.to_s.match(/^header/) }).not_to be_blank
expect(headers.fetch('header_0', {}).fetch('name', {})).to eq GrapeSwaggerRails.options.headers.keys.first
find('#endpointListTogger_headers', visible: true).click
first('a[href="#!/headers/GET_api_headers_format"]', visible: true).click
click_button 'Try it out!'
Expand Down