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

Add support for docExpansion option #31

Merged
merged 1 commit into from
Sep 17, 2015
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 @@ -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