diff --git a/CHANGELOG.md b/CHANGELOG.md index 59f28ac9..5f35ba38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/lib/grape-swagger/endpoint.rb b/lib/grape-swagger/endpoint.rb index 2d41821d..79dd3b1a 100644 --- a/lib/grape-swagger/endpoint.rb +++ b/lib/grape-swagger/endpoint.rb @@ -191,7 +191,7 @@ def params_object(route, options, path) parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions) end - parameters + parameters.presence end def response_object(route) @@ -257,11 +257,12 @@ def success_codes_from_route(route) 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 diff --git a/spec/support/model_parsers/entity_parser.rb b/spec/support/model_parsers/entity_parser.rb index b86843fa..70a14104 100644 --- a/spec/support/model_parsers/entity_parser.rb +++ b/spec/support/model_parsers/entity_parser.rb @@ -279,7 +279,6 @@ class DocumentedHashAndArrayModel < Grape::Entity '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' diff --git a/spec/support/model_parsers/mock_parser.rb b/spec/support/model_parsers/mock_parser.rb index ad6489f4..c58a6d01 100644 --- a/spec/support/model_parsers/mock_parser.rb +++ b/spec/support/model_parsers/mock_parser.rb @@ -271,7 +271,6 @@ class ApiResponse < OpenStruct; end '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' diff --git a/spec/support/model_parsers/representable_parser.rb b/spec/support/model_parsers/representable_parser.rb index 21c19628..4c2655a4 100644 --- a/spec/support/model_parsers/representable_parser.rb +++ b/spec/support/model_parsers/representable_parser.rb @@ -351,7 +351,6 @@ class DocumentedHashAndArrayModel < Representable::Decorator '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' diff --git a/spec/swagger_v2/api_swagger_v2_response_spec.rb b/spec/swagger_v2/api_swagger_v2_response_spec.rb index 01b8379e..16751b01 100644 --- a/spec/swagger_v2/api_swagger_v2_response_spec.rb +++ b/spec/swagger_v2/api_swagger_v2_response_spec.rb @@ -49,7 +49,6 @@ def app 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 @@ def app 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' } } diff --git a/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb b/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb index 20b8fab6..b091f346 100644 --- a/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb +++ b/spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb @@ -72,7 +72,6 @@ def app 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 @@ def app 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 @@ def app 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' } } diff --git a/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb b/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb index c60b7a91..02ba8aab 100644 --- a/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb +++ b/spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb @@ -91,7 +91,6 @@ def app 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 @@ def app 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 @@ def app 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 @@ def app 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 @@ def app 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' } } diff --git a/spec/swagger_v2/default_api_spec.rb b/spec/swagger_v2/default_api_spec.rb index 6985c12e..b547a39c 100644 --- a/spec/swagger_v2/default_api_spec.rb +++ b/spec/swagger_v2/default_api_spec.rb @@ -33,7 +33,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['something'], 'operationId' => 'getSomething', 'responses' => { '200' => { 'description' => 'This gets something.' } } @@ -80,7 +79,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['something'], 'operationId' => 'getSomething', 'responses' => { '200' => { 'description' => 'This gets something.' } } diff --git a/spec/swagger_v2/guarded_endpoint_spec.rb b/spec/swagger_v2/guarded_endpoint_spec.rb index ec10cb3a..917b2935 100644 --- a/spec/swagger_v2/guarded_endpoint_spec.rb +++ b/spec/swagger_v2/guarded_endpoint_spec.rb @@ -86,7 +86,6 @@ def app 'get' => { 'description' => 'Show endpoint if authenticated', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['auth'], 'operationId' => 'getAuth', 'responses' => { '200' => { 'description' => 'Show endpoint if authenticated' } } diff --git a/spec/swagger_v2/hide_api_spec.rb b/spec/swagger_v2/hide_api_spec.rb index d5f74e49..d793bf05 100644 --- a/spec/swagger_v2/hide_api_spec.rb +++ b/spec/swagger_v2/hide_api_spec.rb @@ -54,7 +54,6 @@ def app 'get' => { 'description' => 'Show this endpoint', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['simple'], 'operationId' => 'getSimple', 'responses' => { '200' => { 'description' => 'Show this endpoint' } } @@ -64,7 +63,6 @@ def app 'get' => { 'description' => 'Lazily show endpoint', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['lazy'], 'operationId' => 'getLazy', 'responses' => { '200' => { 'description' => 'Lazily show endpoint' } } @@ -117,7 +115,6 @@ def app 'get' => { 'description' => 'Show this endpoint', 'produces' => ['application/json'], - 'parameters' => [], 'operationId' => 'getSimpleShow', 'tags' => ['simple'], 'responses' => { '200' => { 'description' => 'Show this endpoint' } } } @@ -139,7 +136,6 @@ def app 'get' => { 'description' => 'Show this endpoint', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['simple'], 'operationId' => 'getSimpleShow', 'responses' => { '200' => { 'description' => 'Show this endpoint' } } diff --git a/spec/swagger_v2/mounted_target_class_spec.rb b/spec/swagger_v2/mounted_target_class_spec.rb index c606bed0..81b829fc 100644 --- a/spec/swagger_v2/mounted_target_class_spec.rb +++ b/spec/swagger_v2/mounted_target_class_spec.rb @@ -41,7 +41,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'responses' => { '200' => { 'description' => 'This gets something.' } }, 'tags' => ['simple'], 'operationId' => 'getSimple' @@ -64,7 +63,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'responses' => { '200' => { 'description' => 'This gets something.' } }, diff --git a/spec/swagger_v2/simple_mounted_api_spec.rb b/spec/swagger_v2/simple_mounted_api_spec.rb index 9eab603f..d99bd951 100644 --- a/spec/swagger_v2/simple_mounted_api_spec.rb +++ b/spec/swagger_v2/simple_mounted_api_spec.rb @@ -104,8 +104,6 @@ def app 'get' => { 'description' => 'Document root', 'produces' => ['application/json'], - 'parameters' => [], - 'tags' => [], 'responses' => { '200' => { 'description' => 'Document root' } }, 'operationId' => 'get' } @@ -114,7 +112,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['simple'], 'operationId' => 'getSimple', 'responses' => { '200' => { 'description' => 'This gets something.' } } @@ -124,7 +121,6 @@ def app '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 @@ def app '/simple-head-test' => { 'head' => { 'produces' => ['application/json'], - 'parameters' => [], 'responses' => { '200' => { 'description' => 'head SimpleHeadTest' } }, 'tags' => ['simple-head-test'], 'operationId' => 'headSimpleHeadTest' @@ -142,7 +137,6 @@ def app '/simple-options-test' => { 'options' => { 'produces' => ['application/json'], - 'parameters' => [], 'responses' => { '200' => { 'description' => 'option SimpleOptionsTest' } }, 'tags' => ['simple-options-test'], 'operationId' => 'optionsSimpleOptionsTest' @@ -211,7 +205,6 @@ def app 'get' => { 'description' => 'This gets something.', 'produces' => ['application/json'], - 'parameters' => [], 'tags' => ['simple'], 'operationId' => 'getSimple', 'responses' => { '200' => { 'description' => 'This gets something.' } } @@ -243,7 +236,6 @@ def app '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.' } }