Skip empty parameters and tags arrays (#731)

* Skip empty parameters arrays

* Skip empty tags arrays

* Update CHANGELOG
This commit is contained in:
Fotos Georgiadis 2018-12-07 19:29:22 +00:00 committed by peter scholz
parent 69269d7c54
commit 548d8af682
13 changed files with 4 additions and 32 deletions

View File

@ -7,6 +7,7 @@
#### Fixes
* Your contribution here.
* [#731](https://github.com/ruby-grape/grape-swagger/pull/731): Skip empty parameters and tags arrays - [@fotos](https://github.com/fotos).
* [#729](https://github.com/ruby-grape/grape-swagger/pull/729): Allow empty security array for endpoints - [@fotos](https://github.com/fotos).
### 0.32.0 (November 26, 2018)

View File

@ -191,7 +191,7 @@ module Grape
parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions)
end
parameters
parameters.presence
end
def response_object(route)
@ -257,11 +257,12 @@ module Grape
def tag_object(route, path)
version = GrapeSwagger::DocMethods::Version.get(route)
version = [version] unless version.is_a?(Array)
Array(
path.split('{')[0].split('/').reject(&:empty?).delete_if do |i|
i == route.prefix.to_s || version.map(&:to_s).include?(i)
end.first
)
).presence
end
private

View File

@ -279,7 +279,6 @@ RSpec.shared_context 'entity swagger example' do
'get' => {
'description' => 'This gets Things.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
'tags' => ['thing2'],
'operationId' => 'getThing2'

View File

@ -271,7 +271,6 @@ RSpec.shared_context 'mock swagger example' do
'get' => {
'description' => 'This gets Things.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
'tags' => ['thing2'],
'operationId' => 'getThing2'

View File

@ -351,7 +351,6 @@ RSpec.shared_context 'representable swagger example' do
'get' => {
'description' => 'This gets Things.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'get Horses', 'schema' => { '$ref' => '#/definitions/Something' } }, '401' => { 'description' => 'HorsesOutError', 'schema' => { '$ref' => '#/definitions/ApiError' } } },
'tags' => ['thing2'],
'operationId' => 'getThing2'

View File

@ -49,7 +49,6 @@ describe 'response' do
expect(subject['paths']['/nested_type']['get']).to eql(
'description' => 'This returns something',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseItemResponseAsType' } },
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }
@ -71,7 +70,6 @@ describe 'response' do
expect(subject['paths']['/entity_response']['get']).to eql(
'description' => 'This returns something',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This returns something', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
'400' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

View File

@ -72,7 +72,6 @@ describe 'response with examples' do
expect(subject['paths']['/response_examples']['get']).to eql(
'description' => 'This returns examples',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 }
@ -103,7 +102,6 @@ describe 'response with examples' do
expect(subject['paths']['/response_failure_examples']['get']).to eql(
'description' => 'This syntax also returns examples',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This syntax also returns examples', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'examples' => example_200 },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => example_404 },
@ -125,7 +123,6 @@ describe 'response with examples' do
expect(subject['paths']['/response_no_examples']['get']).to eql(
'description' => 'This does not return examples',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This does not return examples', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

View File

@ -91,7 +91,6 @@ describe 'response with headers' do
expect(subject['paths']['/response_headers']['get']).to eql(
'description' => 'This returns headers',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404, 'headers' => header_404 }
@ -122,7 +121,6 @@ describe 'response with headers' do
expect(subject['paths']['/no_content_response_headers']['delete']).to eql(
'description' => 'A 204 can have headers too',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'204' => { 'description' => 'No content', 'headers' => header_204 },
'400' => { 'description' => 'Bad Request', 'headers' => header_400, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_400 }
@ -153,7 +151,6 @@ describe 'response with headers' do
expect(subject['paths']['/file_response_headers']['get']).to eql(
'description' => 'A file can have headers too',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'A file can have headers too', 'headers' => header_200, 'schema' => { 'type' => 'file' } },
'404' => { 'description' => 'NotFound', 'headers' => header_404, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_404 }
@ -184,7 +181,6 @@ describe 'response with headers' do
expect(subject['paths']['/response_failure_headers']['get']).to eql(
'description' => 'This syntax also returns headers',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This syntax also returns headers', 'schema' => { '$ref' => '#/definitions/UseResponse' }, 'headers' => header_200 },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' }, 'headers' => header_404 },
@ -206,7 +202,6 @@ describe 'response with headers' do
expect(subject['paths']['/response_no_headers']['get']).to eql(
'description' => 'This does not return headers',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This does not return headers', 'schema' => { '$ref' => '#/definitions/UseResponse' } },
'404' => { 'description' => 'NotFound', 'schema' => { '$ref' => '#/definitions/ApiError' } }

View File

@ -33,7 +33,6 @@ describe 'Default API' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['something'],
'operationId' => 'getSomething',
'responses' => { '200' => { 'description' => 'This gets something.' } }
@ -80,7 +79,6 @@ describe 'Default API' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['something'],
'operationId' => 'getSomething',
'responses' => { '200' => { 'description' => 'This gets something.' } }

View File

@ -86,7 +86,6 @@ describe 'a guarded api endpoint' do
'get' => {
'description' => 'Show endpoint if authenticated',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['auth'],
'operationId' => 'getAuth',
'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } }

View File

@ -54,7 +54,6 @@ describe 'a hide mounted api' do
'get' => {
'description' => 'Show this endpoint',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple'],
'operationId' => 'getSimple',
'responses' => { '200' => { 'description' => 'Show this endpoint' } }
@ -64,7 +63,6 @@ describe 'a hide mounted api' do
'get' => {
'description' => 'Lazily show endpoint',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['lazy'],
'operationId' => 'getLazy',
'responses' => { '200' => { 'description' => 'Lazily show endpoint' } }
@ -117,7 +115,6 @@ describe 'a hide mounted api with same namespace' do
'get' => {
'description' => 'Show this endpoint',
'produces' => ['application/json'],
'parameters' => [],
'operationId' => 'getSimpleShow',
'tags' => ['simple'], 'responses' => { '200' => { 'description' => 'Show this endpoint' } }
}
@ -139,7 +136,6 @@ describe 'a hide mounted api with same namespace' do
'get' => {
'description' => 'Show this endpoint',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple'],
'operationId' => 'getSimpleShow',
'responses' => { '200' => { 'description' => 'Show this endpoint' } }

View File

@ -41,7 +41,6 @@ describe 'docs mounted separately from api' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'This gets something.' } },
'tags' => ['simple'],
'operationId' => 'getSimple'
@ -64,7 +63,6 @@ describe 'docs mounted separately from api' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This gets something.' }
},

View File

@ -104,8 +104,6 @@ describe 'a simple mounted api' do
'get' => {
'description' => 'Document root',
'produces' => ['application/json'],
'parameters' => [],
'tags' => [],
'responses' => { '200' => { 'description' => 'Document root' } },
'operationId' => 'get'
}
@ -114,7 +112,6 @@ describe 'a simple mounted api' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple'],
'operationId' => 'getSimple',
'responses' => { '200' => { 'description' => 'This gets something.' } }
@ -124,7 +121,6 @@ describe 'a simple mounted api' do
'get' => {
'description' => 'This gets something for URL using - separator.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple-test'],
'operationId' => 'getSimpleTest',
'responses' => { '200' => { 'description' => 'This gets something for URL using - separator.' } }
@ -133,7 +129,6 @@ describe 'a simple mounted api' do
'/simple-head-test' => {
'head' => {
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'head SimpleHeadTest' } },
'tags' => ['simple-head-test'],
'operationId' => 'headSimpleHeadTest'
@ -142,7 +137,6 @@ describe 'a simple mounted api' do
'/simple-options-test' => {
'options' => {
'produces' => ['application/json'],
'parameters' => [],
'responses' => { '200' => { 'description' => 'option SimpleOptionsTest' } },
'tags' => ['simple-options-test'],
'operationId' => 'optionsSimpleOptionsTest'
@ -211,7 +205,6 @@ describe 'a simple mounted api' do
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple'],
'operationId' => 'getSimple',
'responses' => { '200' => { 'description' => 'This gets something.' } }
@ -243,7 +236,6 @@ describe 'a simple mounted api' do
'get' => {
'description' => 'This gets something for URL using - separator.',
'produces' => ['application/json'],
'parameters' => [],
'tags' => ['simple-test'],
'operationId' => 'getSimpleTest',
'responses' => { '200' => { 'description' => 'This gets something for URL using - separator.' } }