Skip to content

Allow Security Object to be defined #602

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

Merged
merged 1 commit into from
Apr 14, 2017
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Your contribution here.

* [#602](https://github.com/ruby-grape/grape-swagger/pull/602): Allow security object to be defined - [@markevich](https://github.com/markevich).

#### Fixes

* Your contribution here.
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ end
* [swagger_endpoint_guard](#swagger_endpoint_guard)
* [token_owner](#token_owner)
* [security_definitions](#security_definitions)
* [security](#security)
* [models](#models)
* [tags](#tags)
* [hide_documentation_path](#hide_documentation_path)
Expand Down Expand Up @@ -311,6 +312,18 @@ add_swagger_documentation \
}
```

#### security: <a name="security" />
Specify the [Security Object](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#securityRequirementObject)

```ruby
add_swagger_documentation \
security: [
{
api_key: []
}
]
```


#### models: <a name="models" />
A list of entities to document. Combine with the [grape-entity](https://github.com/ruby-grape/grape-entity) gem.
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger/doc_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def defaults
format: :json,
authorizations: nil,
security_definitions: nil,
security: nil,
api_documentation: { desc: 'Swagger compatible API description' },
specific_api_documentation: { desc: 'Swagger compatible API description for specific API' },
endpoint_auth_wrapper: nil,
Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def swagger_object(target_class, request, options)
produces: content_types_for(target_class),
authorizations: options[:authorizations],
securityDefinitions: options[:security_definitions],
security: options[:security],
host: GrapeSwagger::DocMethods::OptionalObject.build(:host, options, request),
basePath: GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options, request),
schemes: options[:schemes].is_a?(String) ? [options[:schemes]] : options[:schemes]
Expand Down
4 changes: 3 additions & 1 deletion spec/swagger_v2/api_swagger_v2_global_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class ConfigurationApi < Grape::API
mount_path: 'documentation',
add_base_path: true,
add_version: true,
security_definitions: { api_key: { foo: 'bar' } }
security_definitions: { api_key: { foo: 'bar' } },
security: [{ api_key: [] }]
end
end
end
Expand All @@ -49,6 +50,7 @@ def app
expect(subject['schemes']).to eql ['https']
expect(subject['securityDefinitions'].keys).to include('api_key')
expect(subject['securityDefinitions']['api_key']).to include('foo' => 'bar')
expect(subject['security']).to include('api_key' => [])
end
end
end