Skip to content

Commit 0b70202

Browse files
committed
Merge pull request #31 from maruware/support_doc_expansion_option
Add support for docExpansion option
2 parents ab9d47c + e985c3f commit 0b70202

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Upgraded swagger-ui to v2.1.1 - [@dblock](https://github.com/dblock).
55
* Grape-swagger 0.7.2 is no longer supported - [@dblock](https://github.com/dblock).
66
* Implemented RuboCop, Ruby-style linter - [@dblock](https://github.com/dblock).
7+
* [#31](https://github.com/ruby-grape/grape-swagger-rails/pull/31): Support Swagger-UI docExpansion option - [@maruware](https://github.com/maruware).
78
* Your contribution here.
89

910
### 0.1.0 (February 5, 2015)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ You can specify additional headers to add to each request:
5959
GrapeSwaggerRails.options.headers['Special-Header'] = 'Some Secret Value'
6060
```
6161

62+
You can set docExpansion with "none" or "list" or "full", default is "none".
63+
See the official Swagger-UI documentation about [SwaggerUi Parameters](https://github.com/swagger-api/swagger-ui#parameters).
64+
65+
```ruby
66+
GrapeSwaggerRails.options.doc_expansion = 'list'
67+
```
68+
6269
Using the `headers` option above, you could hard-code Basic Authentication credentials.
6370
Alternatively, you can configure Basic Authentication through the UI, as described below.
6471

app/views/grape_swagger_rails/application/index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
console.log(data);
2929
}
3030
},
31-
docExpansion: "none",
31+
docExpansion: options.doc_expansion,
3232
apisSorter: "alpha"
3333
});
3434

lib/grape-swagger-rails.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ def before_filter(&block)
2525
api_key_name: 'api_key', # 'Authorization'
2626
api_key_type: 'query', # 'header'
2727

28+
doc_expansion: 'none',
29+
2830
before_filter_proc: nil # Proc used as a controller before filter
2931
)
3032
end

spec/features/swagger_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,34 @@
122122
end
123123
end
124124
end
125+
context '#doc_expansion' do
126+
context 'set list' do
127+
before do
128+
GrapeSwaggerRails.options.doc_expansion = 'list'
129+
visit '/swagger'
130+
end
131+
it 'sets SwaggerUI docExpansion with list' do
132+
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "list"')).to be true
133+
end
134+
end
135+
context 'set full' do
136+
before do
137+
GrapeSwaggerRails.options.doc_expansion = 'full'
138+
visit '/swagger'
139+
end
140+
it 'sets SwaggerUI docExpansion with full' do
141+
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "full"')).to be true
142+
end
143+
end
144+
context 'not set' do
145+
before do
146+
visit '/swagger'
147+
end
148+
it 'defaults SwaggerUI docExpansion' do
149+
expect(page.evaluate_script('window.swaggerUi.options.docExpansion == "none"')).to be true
150+
end
151+
end
152+
end
125153
after do
126154
GrapeSwaggerRails.options = @options
127155
end

0 commit comments

Comments
 (0)