Skip to content

Allow Security Definitions Objects to be defined #471

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 3 commits into from
Jul 11, 2016
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: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Metrics/AbcSize:
# Offense count: 3
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 219
Max: 220

# Offense count: 10
Metrics/CyclomaticComplexity:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#448](https://github.com/ruby-grape/grape-swagger/pull/448): Header parameters are now prepended to the parameter list - [@anakinj](https://github.com/anakinj).
* [#444](https://github.com/ruby-grape/grape-swagger/pull/444): With multi types parameter the first type is use as the documentation type - [@scauglog](https://github.com/scauglog).
* [#463](https://github.com/ruby-grape/grape-swagger/pull/463): Added 'hidden' option for parameter to be exclude from generated documentation - [@anakinj](https://github.com/anakinj).
* [#471](https://github.com/ruby-grape/grape-swagger/pull/471): Allow Security Definitions Objects to be defined - [@bendodd](https://github.com/bendodd).
* Your contribution here.

#### Fixes
Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ end
* [add_version](#add_version)
* [doc_version](#doc_version)
* [markdown](#markdown)
* [security_definitions](#security_definitions)
* [models](#models)
* [hide_documentation_path](#hide_documentation_path)
* [info](#info)
Expand Down Expand Up @@ -273,12 +274,24 @@ add_swagger_documentation \
markdown: GrapeSwagger::Markdown::RedcarpetAdapter.new
```

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

```ruby
add_swagger_documentation \
security_definitions: {
api_key: {
type: "apiKey",
name: "api_key",
in: "header"
}
}
```

#### *authorizations*:
This value is added to the `authorizations` key in the JSON documentation.



<a name="models" />
#### 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 @@ -102,6 +102,7 @@ def defaults
hide_documentation_path: true,
format: :json,
authorizations: nil,
security_definitions: nil,
api_documentation: { desc: 'Swagger compatible API description' },
specific_api_documentation: { desc: 'Swagger compatible API description for specific API' }
}
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 @@ -24,6 +24,7 @@ def swagger_object(target_class, request, options)
swagger: '2.0',
produces: content_types_for(target_class),
authorizations: options[:authorizations],
securityDefinitions: options[:security_definitions],
host: GrapeSwagger::DocMethods::OptionalObject.build(:host, options, request),
basePath: GrapeSwagger::DocMethods::OptionalObject.build(:base_path, options, request),
tags: GrapeSwagger::DocMethods::TagNameDescription.build(options),
Expand Down
5 changes: 4 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 @@ -23,7 +23,8 @@ class ConfigurationApi < Grape::API
base_path: -> { 'somewhere/over/the/rainbow' },
mount_path: 'documentation',
add_base_path: true,
add_version: true
add_version: true,
security_definitions: { api_key: { foo: 'bar' } }
end
end
end
Expand All @@ -44,6 +45,8 @@ def app
expect(subject['basePath']).to eql 'somewhere/over/the/rainbow'
expect(subject['paths'].keys.first).to eql '/somewhere/over/the/rainbow/v3/configuration'
expect(subject['schemes']).to eql ['https']
expect(subject['securityDefinitions'].keys).to include('api_key')
expect(subject['securityDefinitions']['api_key']).to include('foo' => 'bar')
end
end
end