Skip to content

Commit

Permalink
Merge pull request #31 from maruware/support_doc_expansion_option
Browse files Browse the repository at this point in the history
Add support for docExpansion option
  • Loading branch information
dblock committed Sep 17, 2015
2 parents ab9d47c + e985c3f commit 0b70202
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Upgraded swagger-ui to v2.1.1 - [@dblock](https://github.com/dblock).
* Grape-swagger 0.7.2 is no longer supported - [@dblock](https://github.com/dblock).
* Implemented RuboCop, Ruby-style linter - [@dblock](https://github.com/dblock).
* [#31](https://github.com/ruby-grape/grape-swagger-rails/pull/31): Support Swagger-UI docExpansion option - [@maruware](https://github.com/maruware).
* Your contribution here.

### 0.1.0 (February 5, 2015)
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ You can specify additional headers to add to each request:
GrapeSwaggerRails.options.headers['Special-Header'] = 'Some Secret Value'
```

You can set docExpansion with "none" or "list" or "full", default is "none".
See the official Swagger-UI documentation about [SwaggerUi Parameters](https://github.com/swagger-api/swagger-ui#parameters).

```ruby
GrapeSwaggerRails.options.doc_expansion = 'list'
```

Using the `headers` option above, you could hard-code Basic Authentication credentials.
Alternatively, you can configure Basic Authentication through the UI, as described below.

Expand Down
2 changes: 1 addition & 1 deletion app/views/grape_swagger_rails/application/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
console.log(data);
}
},
docExpansion: "none",
docExpansion: options.doc_expansion,
apisSorter: "alpha"
});

Expand Down
2 changes: 2 additions & 0 deletions lib/grape-swagger-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def before_filter(&block)
api_key_name: 'api_key', # 'Authorization'
api_key_type: 'query', # 'header'

doc_expansion: 'none',

before_filter_proc: nil # Proc used as a controller before filter
)
end
28 changes: 28 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,34 @@
end
end
end
context '#doc_expansion' do
context 'set list' do
before do
GrapeSwaggerRails.options.doc_expansion = 'list'
visit '/swagger'
end
it 'sets SwaggerUI docExpansion with list' do
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "list"')).to be true
end
end
context 'set full' do
before do
GrapeSwaggerRails.options.doc_expansion = 'full'
visit '/swagger'
end
it 'sets SwaggerUI docExpansion with full' do
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "full"')).to be true
end
end
context 'not set' do
before do
visit '/swagger'
end
it 'defaults SwaggerUI docExpansion' do
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "none"')).to be true
end
end
end
after do
GrapeSwaggerRails.options = @options
end
Expand Down

0 comments on commit 0b70202

Please sign in to comment.