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' } }

spec/swagger_v2/hide_api_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def app
5454
'get' => {
5555
'description' => 'Show this endpoint',
5656
'produces' => ['application/json'],
57+
'parameters' => [],
5758
'tags' => ['simple'],
5859
'operationId' => 'getSimple',
5960
'responses' => { '200' => { 'description' => 'Show this endpoint' } }
@@ -63,6 +64,7 @@ def app
6364
'get' => {
6465
'description' => 'Lazily show endpoint',
6566
'produces' => ['application/json'],
67+
'parameters' => [],
6668
'tags' => ['lazy'],
6769
'operationId' => 'getLazy',
6870
'responses' => { '200' => { 'description' => 'Lazily show endpoint' } }
@@ -115,6 +117,7 @@ def app
115117
'get' => {
116118
'description' => 'Show this endpoint',
117119
'produces' => ['application/json'],
120+
'parameters' => [],
118121
'operationId' => 'getSimpleShow',
119122
'tags' => ['simple'], 'responses' => { '200' => { 'description' => 'Show this endpoint' } }
120123
}
@@ -136,6 +139,7 @@ def app
136139
'get' => {
137140
'description' => 'Show this endpoint',
138141
'produces' => ['application/json'],
142+
'parameters' => [],
139143
'tags' => ['simple'],
140144
'operationId' => 'getSimpleShow',
141145
'responses' => { '200' => { 'description' => 'Show this endpoint' } }

spec/swagger_v2/mounted_target_class_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ def app
4141
'get' => {
4242
'description' => 'This gets something.',
4343
'produces' => ['application/json'],
44+
'parameters' => [],
4445
'responses' => { '200' => { 'description' => 'This gets something.' } },
4546
'tags' => ['simple'],
4647
'operationId' => 'getSimple'
@@ -63,6 +64,7 @@ def app
6364
'get' => {
6465
'description' => 'This gets something.',
6566
'produces' => ['application/json'],
67+
'parameters' => [],
6668
'responses' => {
6769
'200' => { 'description' => 'This gets something.' }
6870
},

spec/swagger_v2/security_requirement_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,24 @@ def app
1010
{ foo: 'bar' }
1111
end
1212

13-
add_swagger_documentation
13+
desc 'Endpoint without security requirement', security: []
14+
get '/without_security' do
15+
{ foo: 'bar' }
16+
end
17+
18+
add_swagger_documentation(
19+
security_definitions: {
20+
petstore_auth: {
21+
type: 'oauth2',
22+
flow: 'implicit',
23+
authorizationUrl: 'https://petstore.swagger.io/oauth/dialog',
24+
scopes: {
25+
'read:pets': 'read your pets',
26+
'write:pets': 'modify pets in your account'
27+
}
28+
}
29+
}
30+
)
1431
end
1532
end
1633

@@ -22,4 +39,8 @@ def app
2239
it 'defines the security requirement on the endpoint method' do
2340
expect(subject['paths']['/with_security']['get']['security']).to eql ['oauth_pets' => ['read:pets', 'write:pets']]
2441
end
42+
43+
it 'defines an empty security requirement on the endpoint method' do
44+
expect(subject['paths']['/without_security']['get']['security']).to eql []
45+
end
2546
end

spec/swagger_v2/simple_mounted_api_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ def app
104104
'get' => {
105105
'description' => 'Document root',
106106
'produces' => ['application/json'],
107+
'parameters' => [],
108+
'tags' => [],
107109
'responses' => { '200' => { 'description' => 'Document root' } },
108110
'operationId' => 'get'
109111
}
@@ -112,6 +114,7 @@ def app
112114
'get' => {
113115
'description' => 'This gets something.',
114116
'produces' => ['application/json'],
117+
'parameters' => [],
115118
'tags' => ['simple'],
116119
'operationId' => 'getSimple',
117120
'responses' => { '200' => { 'description' => 'This gets something.' } }
@@ -121,6 +124,7 @@ def app
121124
'get' => {
122125
'description' => 'This gets something for URL using - separator.',
123126
'produces' => ['application/json'],
127+
'parameters' => [],
124128
'tags' => ['simple-test'],
125129
'operationId' => 'getSimpleTest',
126130
'responses' => { '200' => { 'description' => 'This gets something for URL using - separator.' } }
@@ -129,6 +133,7 @@ def app
129133
'/simple-head-test' => {
130134
'head' => {
131135
'produces' => ['application/json'],
136+
'parameters' => [],
132137
'responses' => { '200' => { 'description' => 'head SimpleHeadTest' } },
133138
'tags' => ['simple-head-test'],
134139
'operationId' => 'headSimpleHeadTest'
@@ -137,6 +142,7 @@ def app
137142
'/simple-options-test' => {
138143
'options' => {
139144
'produces' => ['application/json'],
145+
'parameters' => [],
140146
'responses' => { '200' => { 'description' => 'option SimpleOptionsTest' } },
141147
'tags' => ['simple-options-test'],
142148
'operationId' => 'optionsSimpleOptionsTest'
@@ -205,6 +211,7 @@ def app
205211
'get' => {
206212
'description' => 'This gets something.',
207213
'produces' => ['application/json'],
214+
'parameters' => [],
208215
'tags' => ['simple'],
209216
'operationId' => 'getSimple',
210217
'responses' => { '200' => { 'description' => 'This gets something.' } }
@@ -236,6 +243,7 @@ def app
236243
'get' => {
237244
'description' => 'This gets something for URL using - separator.',
238245
'produces' => ['application/json'],
246+
'parameters' => [],
239247
'tags' => ['simple-test'],
240248
'operationId' => 'getSimpleTest',
241249
'responses' => { '200' => { 'description' => 'This gets something for URL using - separator.' } }

0 commit comments

Comments
 (0)