diff --git a/lib/grape-swagger/doc_methods/move_params.rb b/lib/grape-swagger/doc_methods/move_params.rb index 1d34650e..f73bdbf4 100644 --- a/lib/grape-swagger/doc_methods/move_params.rb +++ b/lib/grape-swagger/doc_methods/move_params.rb @@ -197,7 +197,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) diff --git a/spec/issues/params_schema_definition_for_delete_action_spec.rb b/spec/issues/params_schema_definition_for_delete_action_spec.rb new file mode 100644 index 00000000..c5ecb7d9 --- /dev/null +++ b/spec/issues/params_schema_definition_for_delete_action_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe '#xxx Body params for DELETE action' do + let(:app) do + Class.new(Grape::API) do + params do + requires :post_id, type: Integer + requires :query, type: String, documentation: { type: 'string', param_type: 'body' } + end + delete '/posts/:post_id/comments' do + { 'declared_params' => declared(params) } + end + add_swagger_documentation format: :json + end + end + + describe 'retrieves the documentation for delete parameters as a schema defintion' do + subject do + get '/swagger_doc' + JSON.parse(last_response.body) + end + + specify do + expect(subject['paths']['/posts/{post_id}/comments']['delete']['parameters']).to match( + [ + { + 'format' => 'int32', + 'in' => 'path', + 'name' => 'post_id', + 'type' => 'integer', + 'required' => true + }, + { + 'name' => 'deletePostsPostIdComments', + 'in' => 'body', + 'required' => true, + 'schema' => { '$ref' => '#/definitions/deletePostsPostIdComments' } + } + ] + ) + + expect(subject['definitions']['deletePostsPostIdComments']).to match( + 'type' => 'object', + 'properties' => { + 'query' => { + 'type' => 'string' + } + }, + 'required' => ['query'] + ) + end + end +end diff --git a/spec/lib/move_params_spec.rb b/spec/lib/move_params_spec.rb index c513e90e..bd294e45 100644 --- a/spec/lib/move_params_spec.rb +++ b/spec/lib/move_params_spec.rb @@ -30,11 +30,11 @@ end let(:allowed_verbs) do - [:post, :put, :patch, 'POST', 'PUT', 'PATCH'] + [:post, :put, :patch, :delete, 'POST', 'PUT', 'PATCH', 'DELETE'] end let(:not_allowed_verbs) do - [:get, :delete, 'GET', 'DELETE'] + [:get, 'GET'] end describe 'movable params' do diff --git a/spec/support/mock_parser.rb b/spec/support/mock_parser.rb index d9a78961..6877df0a 100644 --- a/spec/support/mock_parser.rb +++ b/spec/support/mock_parser.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'ostruct' + module GrapeSwagger class MockParser attr_reader :model, :endpoint