Skip to content

Skip empty parameters and tags arrays #731

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
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/support/model_parsers/entity_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion spec/support/model_parsers/mock_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 0 additions & 1 deletion spec/support/model_parsers/representable_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 0 additions & 2 deletions spec/swagger_v2/api_swagger_v2_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand All @@ -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' } }
Expand Down
3 changes: 0 additions & 3 deletions spec/swagger_v2/api_swagger_v2_response_with_examples_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 },
Expand All @@ -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' } }
Expand Down
5 changes: 0 additions & 5 deletions spec/swagger_v2/api_swagger_v2_response_with_headers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand Down Expand Up @@ -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 },
Expand All @@ -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' } }
Expand Down
2 changes: 0 additions & 2 deletions spec/swagger_v2/default_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.' } }
Expand Down Expand Up @@ -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.' } }
Expand Down
1 change: 0 additions & 1 deletion spec/swagger_v2/guarded_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand Down
4 changes: 0 additions & 4 deletions spec/swagger_v2/hide_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' } }
Expand All @@ -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' } }
Expand Down Expand Up @@ -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' } }
}
Expand All @@ -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' } }
Expand Down
2 changes: 0 additions & 2 deletions spec/swagger_v2/mounted_target_class_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -64,7 +63,6 @@ def app
'get' => {
'description' => 'This gets something.',
'produces' => ['application/json'],
'parameters' => [],
'responses' => {
'200' => { 'description' => 'This gets something.' }
},
Expand Down
8 changes: 0 additions & 8 deletions spec/swagger_v2/simple_mounted_api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ def app
'get' => {
'description' => 'Document root',
'produces' => ['application/json'],
'parameters' => [],
'tags' => [],
'responses' => { '200' => { 'description' => 'Document root' } },
'operationId' => 'get'
}
Expand All @@ -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.' } }
Expand All @@ -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.' } }
Expand All @@ -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'
Expand All @@ -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'
Expand Down Expand Up @@ -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.' } }
Expand Down Expand Up @@ -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.' } }
Expand Down