Skip to content
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

properly handle DELETE endpoints #795

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/move_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def deletable?(param)
end

def move_methods
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
[:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
end

def includes_body_param?(params)
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods/parse_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def param_type(value_type)
'path'
elsif param_type
param_type
elsif %w[POST PUT PATCH].include?(value_type[:method])
elsif %w[DELETE POST PUT PATCH].include?(value_type[:method])
DataType.request_primitive?(value_type[:data_type]) ? 'formData' : 'body'
else
'query'
Expand Down
2 changes: 1 addition & 1 deletion lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def produces_object(route, format)
route_mime_types.present? ? route_mime_types : mime_types
end

SUPPORTS_CONSUMES = %i[post put patch].freeze
SUPPORTS_CONSUMES = %i[delete post put patch].freeze

def consumes_object(route, format)
return unless SUPPORTS_CONSUMES.include?(route.request_method.downcase.to_sym)
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/move_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
end

let(:allowed_verbs) do
[:post, :put, :patch, 'POST', 'PUT', 'PATCH']
[:delete, :post, :put, :patch, 'DELETE', 'POST', 'PUT', 'PATCH']
end

let(:not_allowed_verbs) do
[:get, :delete, 'GET', 'DELETE']
[:get, 'GET']
end

describe 'movable params' do
Expand Down
2 changes: 2 additions & 0 deletions spec/support/model_parsers/entity_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ class DocumentedHashAndArrayModel < Grape::Entity
'delete' => {
'description' => 'This deletes Thing.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '200' => { 'description' => 'This deletes Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } },
'tags' => ['thing'],
Expand All @@ -288,6 +289,7 @@ class DocumentedHashAndArrayModel < Grape::Entity
'delete' => {
'description' => 'dummy route.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '204' => { 'description' => 'dummy route.' }, '401' => { 'description' => 'Unauthorized' } },
'tags' => ['dummy'],
Expand Down
2 changes: 2 additions & 0 deletions spec/support/model_parsers/mock_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ class ApiResponse < OpenStruct; end
'delete' => {
'description' => 'This deletes Thing.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '200' => { 'description' => 'This deletes Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } },
'tags' => ['thing'],
Expand All @@ -280,6 +281,7 @@ class ApiResponse < OpenStruct; end
'delete' => {
'description' => 'dummy route.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '204' => { 'description' => 'dummy route.' }, '401' => { 'description' => 'Unauthorized' } },
'tags' => ['dummy'],
Expand Down
2 changes: 2 additions & 0 deletions spec/support/model_parsers/representable_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ class DocumentedHashAndArrayModel < Representable::Decorator
'delete' => {
'description' => 'This deletes Thing.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '200' => { 'description' => 'This deletes Thing.', 'schema' => { '$ref' => '#/definitions/Something' } } },
'tags' => ['thing'],
Expand All @@ -360,6 +361,7 @@ class DocumentedHashAndArrayModel < Representable::Decorator
'delete' => {
'description' => 'dummy route.',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'parameters' => [{ 'in' => 'path', 'name' => 'id', 'type' => 'integer', 'format' => 'int32', 'required' => true }],
'responses' => { '204' => { 'description' => 'dummy route.' }, '401' => { 'description' => 'Unauthorized' } },
'tags' => ['dummy'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def app
expect(subject['paths']['/no_content_response_headers']['delete']).to eql(
'description' => 'A 204 can have headers too',
'produces' => ['application/json'],
'consumes' => ['application/json'],
'responses' => {
'204' => { 'description' => 'No content', 'headers' => header_204 },
'400' => { 'description' => 'Bad Request', 'headers' => header_400, 'schema' => { '$ref' => '#/definitions/ApiError' }, 'examples' => examples_400 }
Expand Down