Skip to content

Commit 4777b87

Browse files
fotosdblock
authored andcommitted
Allow empty security array for endpoints (#729)
1 parent 83a6e8d commit 4777b87

14 files changed

+54
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#### Fixes
88

99
* Your contribution here.
10+
* [#729](https://github.com/ruby-grape/grape-swagger/pull/729): Allow empty security array for endpoints - [@fotos](https://github.com/fotos).
1011

1112
### 0.32.0 (November 26, 2018)
1213

lib/grape-swagger/endpoint.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def method_object(route, options, path)
125125
method[:tags] = route.options.fetch(:tags, tag_object(route, path))
126126
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path)
127127
method[:deprecated] = deprecated_object(route)
128-
method.delete_if { |_, value| value.blank? }
128+
method.delete_if { |_, value| value.nil? }
129129

130130
[route.request_method.downcase.to_sym, method]
131131
end
@@ -149,7 +149,6 @@ def summary_object(route)
149149
def description_object(route)
150150
description = route.description if route.description.present?
151151
description = route.options[:detail] if route.options.key?(:detail)
152-
description ||= ''
153152

154153
description
155154
end

spec/support/model_parsers/entity_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class DocumentedHashAndArrayModel < Grape::Entity
279279
'get' => {
280280
'description' => 'This gets Things.',
281281
'produces' => ['application/json'],
282+
'parameters' => [],
282283
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
283284
'tags' => ['thing2'],
284285
'operationId' => 'getThing2'

spec/support/model_parsers/mock_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ class ApiResponse < OpenStruct; end
271271
'get' => {
272272
'description' => 'This gets Things.',
273273
'produces' => ['application/json'],
274+
'parameters' => [],
274275
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
275276
'tags' => ['thing2'],
276277
'operationId' => 'getThing2'

spec/support/model_parsers/representable_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class DocumentedHashAndArrayModel < Representable::Decorator
351351
'get' => {
352352
'description' => 'This gets Things.',
353353
'produces' => ['application/json'],
354+
'parameters' => [],
354355
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
355356
'tags' => ['thing2'],
356357
'operationId' => 'getThing2'

spec/swagger_v2/api_swagger_v2_response_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def app
4949
expect(subject['paths']['/nested_type']['get']).to eql(
5050
'description' => 'This returns something',
5151
'produces' => ['application/json'],
52+
'parameters' => [],
5253
'responses' => {
5354
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseItemResponseAsType' } },
5455
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
@@ -70,6 +71,7 @@ def app
7071
expect(subject['paths']['/entity_response']['get']).to eql(
7172
'description' => 'This returns something',
7273
'produces' => ['application/json'],
74+
'parameters' => [],
7375
'responses' => {
7476
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
7577
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def app
7272
expect(subject['paths']['/response_examples']['get']).to eql(
7373
'description' => 'This returns examples',
7474
'produces' => ['application/json'],
75+
'parameters' => [],
7576
'responses' => {
7677
'200' => { 'description' => 'This returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
7778
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 }
@@ -102,6 +103,7 @@ def app
102103
expect(subject['paths']['/response_failure_examples']['get']).to eql(
103104
'description' => 'This syntax also returns examples',
104105
'produces' => ['application/json'],
106+
'parameters' => [],
105107
'responses' => {
106108
'200' => { 'description' => 'This syntax also returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
107109
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 },
@@ -123,6 +125,7 @@ def app
123125
expect(subject['paths']['/response_no_examples']['get']).to eql(
124126
'description' => 'This does not return examples',
125127
'produces' => ['application/json'],
128+
'parameters' => [],
126129
'responses' => {
127130
'200' => { 'description' => 'This does not return examples', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
128131
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def app
9191
expect(subject['paths']['/response_headers']['get']).to eql(
9292
'description' => 'This returns headers',
9393
'produces' => ['application/json'],
94+
'parameters' => [],
9495
'responses' => {
9596
'200' => { 'description' => 'This returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
9697
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404, 'headers' => header_404 }
@@ -121,6 +122,7 @@ def app
121122
expect(subject['paths']['/no_content_response_headers']['delete']).to eql(
122123
'description' => 'A 204 can have headers too',
123124
'produces' => ['application/json'],
125+
'parameters' => [],
124126
'responses' => {
125127
'204' => { 'description' => 'No content', 'headers' => header_204 },
126128
'400' => { 'description' => 'Bad Request', 'headers' => header_400, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_400 }
@@ -151,6 +153,7 @@ def app
151153
expect(subject['paths']['/file_response_headers']['get']).to eql(
152154
'description' => 'A file can have headers too',
153155
'produces' => ['application/json'],
156+
'parameters' => [],
154157
'responses' => {
155158
'200' => { 'description' => 'A file can have headers too', 'headers' => header_200, 'schema' => { 'type' => 'file' } },
156159
'404' => { 'description' => 'NotFound', 'headers' => header_404, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404 }
@@ -181,6 +184,7 @@ def app
181184
expect(subject['paths']['/response_failure_headers']['get']).to eql(
182185
'description' => 'This syntax also returns headers',
183186
'produces' => ['application/json'],
187+
'parameters' => [],
184188
'responses' => {
185189
'200' => { 'description' => 'This syntax also returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
186190
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_404 },
@@ -202,6 +206,7 @@ def app
202206
expect(subject['paths']['/response_no_headers']['get']).to eql(
203207
'description' => 'This does not return headers',
204208
'produces' => ['application/json'],
209+
'parameters' => [],
205210
'responses' => {
206211
'200' => { 'description' => 'This does not return headers', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
207212
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

spec/swagger_v2/default_api_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def app
3333
'get' => {
3434
'description' => 'This gets something.',
3535
'produces' => ['application/json'],
36+
'parameters' => [],
3637
'tags' => ['something'],
3738
'operationId' => 'getSomething',
3839
'responses' => { '200' => { 'description' => 'This gets something.' } }
@@ -79,6 +80,7 @@ def app
7980
'get' => {
8081
'description' => 'This gets something.',
8182
'produces' => ['application/json'],
83+
'parameters' => [],
8284
'tags' => ['something'],
8385
'operationId' => 'getSomething',
8486
'responses' => { '200' => { 'description' => 'This gets something.' } }

spec/swagger_v2/guarded_endpoint_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ def app
8686
'get' => {
8787
'description' => 'Show endpoint if authenticated',
8888
'produces' => ['application/json'],
89+
'parameters' => [],
8990
'tags' => ['auth'],
9091
'operationId' => 'getAuth',
9192
'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }

0 commit comments

Comments
 (0)