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

Feature/options supported submit methods #57

Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.2.2 (Next)

* Your contribution here
* [#57](https://github.com/ruby-grape/grape-swagger-rails/pull/57): Support Swagger-UI supportedSubmitMethods option - [@ShadowWrathOogles](https://github.com/ShadowWrathOogles).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this back please! With a dot at the end ;)

* Your contribution here.

Copy link

@aschuster3 aschuster3 Jun 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super nitpicky (and I apologize), but could you re-add * Your contributions here. after your addition? After that, this is good to merge. No need to worry about squashing, GitHub now lets me do that automatically.

Thank you again for your contribution!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @aschuster3 for being on top of this ;)

### 0.2.1 (May 21, 2016)

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,16 @@ See the official Swagger-UI documentation about [SwaggerUi Parameters](https://g
GrapeSwaggerRails.options.doc_expansion = 'list'
```

You can set supportedSubmitMethods with an array of the supported HTTP methods, default is:
```ruby
["get" "post" "put" "delete" "patch"]
```
See the official Swagger-UI documentation about [SwaggerUi Parameters](https://github.com/swagger-api/swagger-ui#parameters).

```ruby
GrapeSwaggerRails.options.supported_submit_methods = ["get"]
```

You can set validatorUrl to your own locally deployed Swagger validator, or disable validation by setting this option to nil.
This is useful to avoid error messages when running Swagger-UI on a server which is not accessible from outside your network.

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 @@ -19,7 +19,7 @@
url: options.app_url + options.url,
dom_id: "swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
supportedSubmitMethods: options.supported_submit_methods || [],
authorizations: headers,
onComplete: function(swaggerApi, swaggerUi){
if('console' in window) {
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger-rails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def before_filter(&block)
api_key_default_value: '', # Auto populates api_key

doc_expansion: 'none',
supported_submit_methods: %w(get post put delete patch),

before_filter_proc: nil, # Proc used as a controller before filter

Expand Down
49 changes: 49 additions & 0 deletions spec/features/swagger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,55 @@
end
end
end
context '#supported_submit_methods' do
context 'set all operations' do
before do
GrapeSwaggerRails.options.supported_submit_methods = %w(get post put delete patch)
visit '/swagger'
end
it 'sets SwaggerUI supportedSubmitMethods with all operations' do
expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 5
find('#endpointListTogger_params', visible: true).click
first('span[class="http_method"] a', visible: true).click
expect(page).to have_button('Try it out!', disabled: false)
end
end
context 'set some operations' do
before do
GrapeSwaggerRails.options.supported_submit_methods = ['post']
visit '/swagger'
end
it 'sets SwaggerUI supportedSubmitMethods with some operations' do
expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 1
find('#endpointListTogger_params', visible: true).click
first('span[class="http_method"] a', visible: true).click
expect(page).not_to have_button('Try it out!')
end
end
context 'set nil' do
before do
GrapeSwaggerRails.options.supported_submit_methods = nil
visit '/swagger'
end
it 'clears SwaggerUI supportedSubmitMethods' do
expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 0
find('#endpointListTogger_params', visible: true).click
first('span[class="http_method"] a', visible: true).click
expect(page).not_to have_button('Try it out!')
end
end
context 'not set' do
before do
visit '/swagger'
end
it 'defaults SwaggerUI supportedSubmitMethods' do
expect(page.evaluate_script('window.swaggerUi.options.supportedSubmitMethods.length')).to eq 5
find('#endpointListTogger_params', visible: true).click
first('span[class="http_method"] a', visible: true).click
expect(page).to have_button('Try it out!', disabled: false)
end
end
end
context '#validator_url' do
context 'set null' do
before do
Expand Down